summaryrefslogtreecommitdiffstats
path: root/tests/ui/derives
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/derives')
-rw-r--r--tests/ui/derives/deriving-copyclone.stderr24
-rw-r--r--tests/ui/derives/deriving-with-repr-packed-2.rs20
-rw-r--r--tests/ui/derives/deriving-with-repr-packed-2.stderr33
-rw-r--r--tests/ui/derives/deriving-with-repr-packed.rs53
-rw-r--r--tests/ui/derives/deriving-with-repr-packed.stderr138
5 files changed, 143 insertions, 125 deletions
diff --git a/tests/ui/derives/deriving-copyclone.stderr b/tests/ui/derives/deriving-copyclone.stderr
index 9c4ca01ff..c0c2215c0 100644
--- a/tests/ui/derives/deriving-copyclone.stderr
+++ b/tests/ui/derives/deriving-copyclone.stderr
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `B<C>: Copy` is not satisfied
- --> $DIR/deriving-copyclone.rs:31:13
+ --> $DIR/deriving-copyclone.rs:31:26
|
LL | is_copy(B { a: 1, b: C });
- | ------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `B<C>`
+ | ------- ^ the trait `Copy` is not implemented for `B<C>`
| |
| required by a bound introduced by this call
|
@@ -19,14 +19,14 @@ LL | fn is_copy<T: Copy>(_: T) {}
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider borrowing here
|
-LL | is_copy(&B { a: 1, b: C });
- | +
+LL | is_copy(B { a: 1, b: &C });
+ | +
error[E0277]: the trait bound `B<C>: Clone` is not satisfied
- --> $DIR/deriving-copyclone.rs:32:14
+ --> $DIR/deriving-copyclone.rs:32:27
|
LL | is_clone(B { a: 1, b: C });
- | -------- ^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `B<C>`
+ | -------- ^ the trait `Clone` is not implemented for `B<C>`
| |
| required by a bound introduced by this call
|
@@ -43,14 +43,14 @@ LL | fn is_clone<T: Clone>(_: T) {}
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider borrowing here
|
-LL | is_clone(&B { a: 1, b: C });
- | +
+LL | is_clone(B { a: 1, b: &C });
+ | +
error[E0277]: the trait bound `B<D>: Copy` is not satisfied
- --> $DIR/deriving-copyclone.rs:35:13
+ --> $DIR/deriving-copyclone.rs:35:26
|
LL | is_copy(B { a: 1, b: D });
- | ------- ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `B<D>`
+ | ------- ^ the trait `Copy` is not implemented for `B<D>`
| |
| required by a bound introduced by this call
|
@@ -67,8 +67,8 @@ LL | fn is_copy<T: Copy>(_: T) {}
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider borrowing here
|
-LL | is_copy(&B { a: 1, b: D });
- | +
+LL | is_copy(B { a: 1, b: &D });
+ | +
error: aborting due to 3 previous errors
diff --git a/tests/ui/derives/deriving-with-repr-packed-2.rs b/tests/ui/derives/deriving-with-repr-packed-2.rs
new file mode 100644
index 000000000..79aca74df
--- /dev/null
+++ b/tests/ui/derives/deriving-with-repr-packed-2.rs
@@ -0,0 +1,20 @@
+// Check that deriving certain builtin traits on certain packed structs cause
+// errors. To avoid potentially misaligned references, field copies must be
+// used, which involves adding `T: Copy` bounds.
+
+#[derive(Copy, Clone, Default, PartialEq, Eq)]
+#[repr(packed)]
+pub struct Foo<T>(T, T, T);
+
+struct NonCopy;
+
+fn main() {
+ // This one is fine because `u32` impls `Copy`.
+ let x: Foo<u32> = Foo(1, 2, 3);
+ _ = x.clone();
+
+ // This one is an error because `NonCopy` doesn't impl `Copy`.
+ let x: Foo<NonCopy> = Foo(NonCopy, NonCopy, NonCopy);
+ _ = x.clone();
+ //~^ ERROR the method `clone` exists for struct `Foo<NonCopy>`, but its trait bounds were not satisfied
+}
diff --git a/tests/ui/derives/deriving-with-repr-packed-2.stderr b/tests/ui/derives/deriving-with-repr-packed-2.stderr
new file mode 100644
index 000000000..ab3646057
--- /dev/null
+++ b/tests/ui/derives/deriving-with-repr-packed-2.stderr
@@ -0,0 +1,33 @@
+error[E0599]: the method `clone` exists for struct `Foo<NonCopy>`, but its trait bounds were not satisfied
+ --> $DIR/deriving-with-repr-packed-2.rs:18:11
+ |
+LL | pub struct Foo<T>(T, T, T);
+ | -----------------
+ | |
+ | method `clone` not found for this struct
+ | doesn't satisfy `Foo<NonCopy>: Clone`
+LL |
+LL | struct NonCopy;
+ | --------------
+ | |
+ | doesn't satisfy `NonCopy: Clone`
+ | doesn't satisfy `NonCopy: Copy`
+...
+LL | _ = x.clone();
+ | ^^^^^ method cannot be called on `Foo<NonCopy>` due to unsatisfied trait bounds
+ |
+note: the following trait bounds were not satisfied:
+ `NonCopy: Clone`
+ `NonCopy: Copy`
+ --> $DIR/deriving-with-repr-packed-2.rs:5:16
+ |
+LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
+ | ^^^^^ unsatisfied trait bound introduced in this `derive` macro
+help: consider annotating `NonCopy` with `#[derive(Clone, Copy)]`
+ |
+LL | #[derive(Clone, Copy)]
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/derives/deriving-with-repr-packed.rs b/tests/ui/derives/deriving-with-repr-packed.rs
index 3884e3977..58be45197 100644
--- a/tests/ui/derives/deriving-with-repr-packed.rs
+++ b/tests/ui/derives/deriving-with-repr-packed.rs
@@ -1,45 +1,46 @@
-#![deny(unaligned_references)]
-
// Check that deriving certain builtin traits on certain packed structs cause
-// errors. This happens when the derived trait would need to use a potentially
-// misaligned reference. But there are two cases that are allowed:
-// - If all the fields within the struct meet the required alignment: 1 for
-// `repr(packed)`, or `N` for `repr(packed(N))`.
-// - If `Default` is the only trait derived, because it doesn't involve any
-// references.
+// errors. To avoid potentially misaligned references, field copies must be
+// used, which involves adding `T: Copy` bounds.
#[derive(Copy, Clone, Default, PartialEq, Eq)]
-//~^ ERROR `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters
-//~| hard error
-//~^^^ ERROR `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters
-//~| hard error
#[repr(packed)]
pub struct Foo<T>(T, T, T);
+// This one is fine because the fields all impl `Copy`.
#[derive(Default, Hash)]
-//~^ ERROR `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
-//~| hard error
#[repr(packed)]
pub struct Bar(u32, u32, u32);
-// This one is fine because the field alignment is 1.
-#[derive(Default, Hash)]
-#[repr(packed)]
-pub struct Bar2(u8, i8, bool);
-
-// This one is fine because the field alignment is 2, matching `packed(2)`.
-#[derive(Default, Hash)]
-#[repr(packed(2))]
-pub struct Bar3(u16, i16, bool);
-
// This one is fine because it's not packed.
#[derive(Debug, Default)]
struct Y(usize);
+// This one has an error because `Y` doesn't impl `Copy`.
+// Note: there is room for improvement in the error message.
#[derive(Debug, Default)]
-//~^ ERROR `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
-//~| hard error
#[repr(packed)]
struct X(Y);
+//~^ ERROR cannot move out of `self` which is behind a shared reference
+
+// This is currently allowed, but will be phased out at some point. From
+// `zerovec` within icu4x-0.9.0.
+#[derive(Debug)]
+#[repr(packed)]
+struct FlexZeroSlice {
+ width: u8,
+ data: [u8],
+ //~^ WARNING byte slice in a packed struct that derives a built-in trait
+ //~^^ this was previously accepted
+}
+
+// Again, currently allowed, but will be phased out.
+#[derive(Debug)]
+#[repr(packed)]
+struct WithStr {
+ width: u8,
+ data: str,
+ //~^ WARNING string slice in a packed struct that derives a built-in trait
+ //~^^ this was previously accepted
+}
fn main() {}
diff --git a/tests/ui/derives/deriving-with-repr-packed.stderr b/tests/ui/derives/deriving-with-repr-packed.stderr
index 0ad800c39..0cfe03869 100644
--- a/tests/ui/derives/deriving-with-repr-packed.stderr
+++ b/tests/ui/derives/deriving-with-repr-packed.stderr
@@ -1,111 +1,75 @@
-error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters
- --> $DIR/deriving-with-repr-packed.rs:11:16
+warning: byte slice in a packed struct that derives a built-in trait
+ --> $DIR/deriving-with-repr-packed.rs:31:5
|
-LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
- | ^^^^^
+LL | #[derive(Debug)]
+ | ----- in this derive macro expansion
+...
+LL | data: [u8],
+ | ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
-note: the lint level is defined here
- --> $DIR/deriving-with-repr-packed.rs:1:9
- |
-LL | #![deny(unaligned_references)]
- | ^^^^^^^^^^^^^^^^^^^^
- = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters
- --> $DIR/deriving-with-repr-packed.rs:11:32
- |
-LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
- | ^^^^^^^^^
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
+ = help: consider implementing the trait by hand, or remove the `packed` attribute
+ = note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default
+ = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
- --> $DIR/deriving-with-repr-packed.rs:19:19
+warning: string slice in a packed struct that derives a built-in trait
+ --> $DIR/deriving-with-repr-packed.rs:41:5
|
-LL | #[derive(Default, Hash)]
- | ^^^^
+LL | #[derive(Debug)]
+ | ----- in this derive macro expansion
+...
+LL | data: str,
+ | ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
- = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
+ = help: consider implementing the trait by hand, or remove the `packed` attribute
+ = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
- --> $DIR/deriving-with-repr-packed.rs:39:10
+error[E0507]: cannot move out of `self` which is behind a shared reference
+ --> $DIR/deriving-with-repr-packed.rs:22:10
|
LL | #[derive(Debug, Default)]
- | ^^^^^
+ | ----- in this derive macro expansion
+LL | #[repr(packed)]
+LL | struct X(Y);
+ | ^ move occurs because `self.0` has type `Y`, which does not implement the `Copy` trait
|
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
-error: aborting due to 4 previous errors
+error: aborting due to previous error; 2 warnings emitted
+For more information about this error, try `rustc --explain E0507`.
Future incompatibility report: Future breakage diagnostic:
-error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters
- --> $DIR/deriving-with-repr-packed.rs:11:16
- |
-LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
- | ^^^^^
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
-note: the lint level is defined here
- --> $DIR/deriving-with-repr-packed.rs:1:9
- |
-LL | #![deny(unaligned_references)]
- | ^^^^^^^^^^^^^^^^^^^^
- = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-Future breakage diagnostic:
-error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters
- --> $DIR/deriving-with-repr-packed.rs:11:32
+warning: byte slice in a packed struct that derives a built-in trait
+ --> $DIR/deriving-with-repr-packed.rs:31:5
|
-LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
- | ^^^^^^^^^
+LL | #[derive(Debug)]
+ | ----- in this derive macro expansion
+...
+LL | data: [u8],
+ | ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
-note: the lint level is defined here
- --> $DIR/deriving-with-repr-packed.rs:1:9
- |
-LL | #![deny(unaligned_references)]
- | ^^^^^^^^^^^^^^^^^^^^
- = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
+ = help: consider implementing the trait by hand, or remove the `packed` attribute
+ = note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default
+ = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
-error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
- --> $DIR/deriving-with-repr-packed.rs:19:19
+warning: string slice in a packed struct that derives a built-in trait
+ --> $DIR/deriving-with-repr-packed.rs:41:5
|
-LL | #[derive(Default, Hash)]
- | ^^^^
+LL | #[derive(Debug)]
+ | ----- in this derive macro expansion
+...
+LL | data: str,
+ | ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
-note: the lint level is defined here
- --> $DIR/deriving-with-repr-packed.rs:1:9
- |
-LL | #![deny(unaligned_references)]
- | ^^^^^^^^^^^^^^^^^^^^
- = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
-
-Future breakage diagnostic:
-error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
- --> $DIR/deriving-with-repr-packed.rs:39:10
- |
-LL | #[derive(Debug, Default)]
- | ^^^^^
- |
- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
- = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
-note: the lint level is defined here
- --> $DIR/deriving-with-repr-packed.rs:1:9
- |
-LL | #![deny(unaligned_references)]
- | ^^^^^^^^^^^^^^^^^^^^
- = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: for more information, see issue #107457 <https://github.com/rust-lang/rust/issues/107457>
+ = help: consider implementing the trait by hand, or remove the `packed` attribute
+ = note: `#[warn(byte_slice_in_packed_struct_with_derive)]` on by default
+ = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)