diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /tests/ui/derives | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/ui/derives/deriving-bounds.stderr | 2 | ||||
-rw-r--r-- | tests/ui/derives/deriving-meta-unknown-trait.stderr | 2 | ||||
-rw-r--r-- | tests/ui/derives/deriving-primitive.stderr | 2 | ||||
-rw-r--r-- | tests/ui/derives/deriving-with-repr-packed-move-errors.rs | 96 | ||||
-rw-r--r-- | tests/ui/derives/deriving-with-repr-packed-move-errors.stderr | 174 | ||||
-rw-r--r-- | tests/ui/derives/deriving-with-repr-packed.stderr | 1 | ||||
-rw-r--r-- | tests/ui/derives/issue-36617.stderr | 40 |
7 files changed, 307 insertions, 10 deletions
diff --git a/tests/ui/derives/deriving-bounds.stderr b/tests/ui/derives/deriving-bounds.stderr index 74ca37287..4461652eb 100644 --- a/tests/ui/derives/deriving-bounds.stderr +++ b/tests/ui/derives/deriving-bounds.stderr @@ -21,6 +21,7 @@ note: unsafe traits like `Sync` should be implemented explicitly | LL | #[derive(Sync)] | ^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: cannot find derive macro `Send` in this scope --> $DIR/deriving-bounds.rs:1:10 @@ -45,6 +46,7 @@ note: unsafe traits like `Send` should be implemented explicitly | LL | #[derive(Send)] | ^^^^ + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 4 previous errors diff --git a/tests/ui/derives/deriving-meta-unknown-trait.stderr b/tests/ui/derives/deriving-meta-unknown-trait.stderr index 053d34f68..28753b8f9 100644 --- a/tests/ui/derives/deriving-meta-unknown-trait.stderr +++ b/tests/ui/derives/deriving-meta-unknown-trait.stderr @@ -15,6 +15,8 @@ LL | #[derive(Eqr)] --> $SRC_DIR/core/src/cmp.rs:LL:COL | = note: similarly named derive macro `Eq` defined here + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/derives/deriving-primitive.stderr b/tests/ui/derives/deriving-primitive.stderr index ca64c9ee7..b39637825 100644 --- a/tests/ui/derives/deriving-primitive.stderr +++ b/tests/ui/derives/deriving-primitive.stderr @@ -9,6 +9,8 @@ error: cannot find derive macro `FromPrimitive` in this scope | LL | #[derive(FromPrimitive)] | ^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/derives/deriving-with-repr-packed-move-errors.rs b/tests/ui/derives/deriving-with-repr-packed-move-errors.rs new file mode 100644 index 000000000..ffeb02d78 --- /dev/null +++ b/tests/ui/derives/deriving-with-repr-packed-move-errors.rs @@ -0,0 +1,96 @@ +// Check that deriving builtin traits for a packed struct with +// non-Copy fields emits move errors along with an additional +// diagnostic note explaining the reason +// See issue #117406 + +use std::fmt::{Debug, Formatter, Result}; +use std::cmp::Ordering; + +// Packed + derives: additional diagnostic should be emitted +// for each of Debug, PartialEq and PartialOrd +#[repr(packed)] +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] +struct StructA(String); +//~^ ERROR: cannot move out of `self` which is behind a shared reference +//~| ERROR: cannot move out of `self` which is behind a shared reference +//~| ERROR: cannot move out of `other` which is behind a shared reference +//~| ERROR: cannot move out of `self` which is behind a shared reference +//~| ERROR: cannot move out of `other` which is behind a shared reference +//~| ERROR: cannot move out of `self` which is behind a shared reference +//~| ERROR: cannot move out of `other` which is behind a shared reference +//~| ERROR: cannot move out of `self` which is behind a shared reference +//~| ERROR: cannot move out of `self` which is behind a shared reference + + +// Unrelated impl: additinal diagnostic should NOT be emitted +impl StructA { + fn fmt(&self) -> String { + self.0 //~ ERROR: cannot move out of `self` which is behind a shared reference + } +} + +// Packed + manual impls: additional diagnostic should NOT be emitted +#[repr(packed)] +struct StructB(String); + +impl Debug for StructB { + fn fmt(&self, f: &mut Formatter) -> Result { + let x = &{ self.0 }; //~ ERROR: cannot move out of `self` which is behind a shared reference + write!(f, "{}", x) + } +} + +impl PartialEq for StructB { + fn eq(&self, other: &StructB) -> bool { + ({ self.0 }) == ({ other.0 }) + //~^ ERROR: cannot move out of `self` which is behind a shared reference + //~| ERROR: cannot move out of `other` which is behind a shared reference + } +} + +impl PartialOrd for StructB { + fn partial_cmp(&self, other: &StructB) -> Option<Ordering> { + PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 }) + //~^ ERROR: cannot move out of `self` which is behind a shared reference + //~| ERROR: cannot move out of `other` which is behind a shared reference + } +} + +// NOT packed + derives: additinal diagnostic should NOT be emitted +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] +struct StructC(String); + +// NOT packed + manual impls: additinal dignostic should NOT be emitted +struct StructD(String); + +impl Debug for StructD { + fn fmt(&self, f: &mut Formatter) -> Result { + let x = &{ self.0 }; //~ ERROR: cannot move out of `self` which is behind a shared reference + write!(f, "{}", x) + } +} + +impl PartialEq for StructD { + fn eq(&self, other: &StructD) -> bool { + ({ self.0 }) == ({ other.0 }) + //~^ ERROR: cannot move out of `self` which is behind a shared reference + //~| ERROR: cannot move out of `other` which is behind a shared reference + } +} + +impl PartialOrd for StructD { + fn partial_cmp(&self, other: &StructD) -> Option<Ordering> { + PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 }) + //~^ ERROR: cannot move out of `self` which is behind a shared reference + //~| ERROR: cannot move out of `other` which is behind a shared reference + } +} + +// Packed + derives but the move is outside of a derive +// expansion: additinal diagnostic should NOT be emitted +fn func(arg: &StructA) -> String { + arg.0 //~ ERROR: cannot move out of `arg` which is behind a shared reference +} + +fn main(){ +} diff --git a/tests/ui/derives/deriving-with-repr-packed-move-errors.stderr b/tests/ui/derives/deriving-with-repr-packed-move-errors.stderr new file mode 100644 index 000000000..c538061b3 --- /dev/null +++ b/tests/ui/derives/deriving-with-repr-packed-move-errors.stderr @@ -0,0 +1,174 @@ +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | ----- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | --------- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(PartialEq)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `other` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | --------- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(PartialEq)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | ---------- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(PartialOrd)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `other` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | ---------- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(PartialOrd)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | --- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(Ord)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `other` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | --- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(Ord)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | ---- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(Hash)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:13:16 + | +LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)] + | ----- in this derive macro expansion +LL | struct StructA(String); + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + | + = note: `#[derive(Clone)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour + = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:28:9 + | +LL | self.0 + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:38:20 + | +LL | let x = &{ self.0 }; + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:45:12 + | +LL | ({ self.0 }) == ({ other.0 }) + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `other` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:45:28 + | +LL | ({ self.0 }) == ({ other.0 }) + | ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:53:36 + | +LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 }) + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `other` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:53:49 + | +LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 }) + | ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:68:20 + | +LL | let x = &{ self.0 }; + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:75:12 + | +LL | ({ self.0 }) == ({ other.0 }) + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `other` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:75:28 + | +LL | ({ self.0 }) == ({ other.0 }) + | ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `self` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:83:36 + | +LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 }) + | ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `other` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:83:49 + | +LL | PartialOrd::partial_cmp(&{ self.0 }, &{ other.0 }) + | ^^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait + +error[E0507]: cannot move out of `arg` which is behind a shared reference + --> $DIR/deriving-with-repr-packed-move-errors.rs:92:5 + | +LL | arg.0 + | ^^^^^ move occurs because `arg.0` has type `String`, which does not implement the `Copy` trait + +error: aborting due to 21 previous errors + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/derives/deriving-with-repr-packed.stderr b/tests/ui/derives/deriving-with-repr-packed.stderr index 0cfe03869..bb1fab343 100644 --- a/tests/ui/derives/deriving-with-repr-packed.stderr +++ b/tests/ui/derives/deriving-with-repr-packed.stderr @@ -36,6 +36,7 @@ LL | #[repr(packed)] LL | struct X(Y); | ^ move occurs because `self.0` has type `Y`, which does not implement the `Copy` trait | + = note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error; 2 warnings emitted diff --git a/tests/ui/derives/issue-36617.stderr b/tests/ui/derives/issue-36617.stderr index 9cc0a29b0..98be7963e 100644 --- a/tests/ui/derives/issue-36617.stderr +++ b/tests/ui/derives/issue-36617.stderr @@ -43,55 +43,75 @@ error: `derive` attribute cannot be used at crate level | LL | #![derive(Copy)] | ^^^^^^^^^^^^^^^^ +... +LL | fn main() {} + | ---- the inner attribute doesn't annotate this function | help: perhaps you meant to use an outer attribute | -LL | #[derive(Copy)] - | ~~~~~~~~~~~~~~~ +LL - #![derive(Copy)] +LL + #[derive(Copy)] + | error: `test` attribute cannot be used at crate level --> $DIR/issue-36617.rs:4:1 | LL | #![test] | ^^^^^^^^ +... +LL | fn main() {} + | ---- the inner attribute doesn't annotate this function | help: perhaps you meant to use an outer attribute | -LL | #[test] - | ~~~~~~~ +LL - #![test] +LL + #[test] + | error: `test_case` attribute cannot be used at crate level --> $DIR/issue-36617.rs:7:1 | LL | #![test_case] | ^^^^^^^^^^^^^ +... +LL | fn main() {} + | ---- the inner attribute doesn't annotate this function | help: perhaps you meant to use an outer attribute | -LL | #[test_case] - | ~~~~~~~~~~~~ +LL - #![test_case] +LL + #[test_case] + | error: `bench` attribute cannot be used at crate level --> $DIR/issue-36617.rs:10:1 | LL | #![bench] | ^^^^^^^^^ +... +LL | fn main() {} + | ---- the inner attribute doesn't annotate this function | help: perhaps you meant to use an outer attribute | -LL | #[bench] - | ~~~~~~~~ +LL - #![bench] +LL + #[bench] + | error: `global_allocator` attribute cannot be used at crate level --> $DIR/issue-36617.rs:13:1 | LL | #![global_allocator] | ^^^^^^^^^^^^^^^^^^^^ +... +LL | fn main() {} + | ---- the inner attribute doesn't annotate this function | help: perhaps you meant to use an outer attribute | -LL | #[global_allocator] - | ~~~~~~~~~~~~~~~~~~~ +LL - #![global_allocator] +LL + #[global_allocator] + | error: aborting due to 10 previous errors |