diff options
| author | bors <bors@rust-lang.org> | 2022-07-25 10:33:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-25 10:33:32 +0000 |
| commit | 2fdbf075cf502431ca9fee6616331b32e34f25de (patch) | |
| tree | add0764cba6c9fc11092ab9199a1a8cc4e3af598 /src | |
| parent | 2f320a224e827b400be25966755a621779f797cc (diff) | |
| parent | d1e4342d118e2c9a6a3336970f1af76be0ad0920 (diff) | |
| download | rust-2fdbf075cf502431ca9fee6616331b32e34f25de.tar.gz rust-2fdbf075cf502431ca9fee6616331b32e34f25de.zip | |
Auto merge of #99707 - JohnTitor:rollup-74rb8vq, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #95040 (protect `std::io::Take::limit` from overflow in `read`) - #95916 (kmc-solid: Use `libc::abort` to abort a program) - #99494 (Use non-relocatable code in nofile-limit.rs test) - #99581 (Improve error messages involving `derive` and `packed`.) - #99643 (Add `sign-ext` target feature to the WASM target) - #99659 (Use `VecMap::get` in `ConstraintLocator::check`) - #99690 (add miri-track-caller to more intrinsic-exposing methods) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/derives/deriving-with-repr-packed.rs | 38 | ||||
| -rw-r--r-- | src/test/ui/derives/deriving-with-repr-packed.stderr | 68 | ||||
| -rw-r--r-- | src/test/ui/process/nofile-limit.rs | 2 |
3 files changed, 61 insertions, 47 deletions
diff --git a/src/test/ui/derives/deriving-with-repr-packed.rs b/src/test/ui/derives/deriving-with-repr-packed.rs index b78eeaa9055..3884e397764 100644 --- a/src/test/ui/derives/deriving-with-repr-packed.rs +++ b/src/test/ui/derives/deriving-with-repr-packed.rs @@ -1,29 +1,43 @@ #![deny(unaligned_references)] -// check that derive on a packed struct with non-Copy fields -// correctly. This can't be made to work perfectly because -// we can't just use the field from the struct as it might -// not be aligned. +// 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. -#[derive(Copy, Clone, PartialEq, Eq)] -//~^ ERROR `#[derive]` can't be used +#[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 `#[derive]` can't be used +//~^^^ 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); -#[derive(PartialEq, Eq)] -//~^ ERROR `#[derive]` can't be used +#[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); -#[derive(PartialEq)] +// 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); -#[derive(PartialEq)] -//~^ ERROR `#[derive]` can't be used +#[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); diff --git a/src/test/ui/derives/deriving-with-repr-packed.stderr b/src/test/ui/derives/deriving-with-repr-packed.stderr index 1002b359f60..1f98da5b70e 100644 --- a/src/test/ui/derives/deriving-with-repr-packed.stderr +++ b/src/test/ui/derives/deriving-with-repr-packed.stderr @@ -1,7 +1,7 @@ -error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133) - --> $DIR/deriving-with-repr-packed.rs:8:16 +error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133) + --> $DIR/deriving-with-repr-packed.rs:11:16 | -LL | #[derive(Copy, Clone, PartialEq, Eq)] +LL | #[derive(Copy, Clone, Default, PartialEq, Eq)] | ^^^^^ | note: the lint level is defined here @@ -13,43 +13,43 @@ LL | #![deny(unaligned_references)] = note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523> = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133) - --> $DIR/deriving-with-repr-packed.rs:8:23 +error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133) + --> $DIR/deriving-with-repr-packed.rs:11:32 | -LL | #[derive(Copy, Clone, PartialEq, Eq)] - | ^^^^^^^^^ +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) -error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133) - --> $DIR/deriving-with-repr-packed.rs:16:10 +error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133) + --> $DIR/deriving-with-repr-packed.rs:19:19 | -LL | #[derive(PartialEq, Eq)] - | ^^^^^^^^^ +LL | #[derive(Default, Hash)] + | ^^^^ | = 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: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) -error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133) - --> $DIR/deriving-with-repr-packed.rs:25:10 +error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133) + --> $DIR/deriving-with-repr-packed.rs:39:10 | -LL | #[derive(PartialEq)] - | ^^^^^^^^^ +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: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) + = 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 Future incompatibility report: Future breakage diagnostic: -error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133) - --> $DIR/deriving-with-repr-packed.rs:8:16 +error: `Clone` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133) + --> $DIR/deriving-with-repr-packed.rs:11:16 | -LL | #[derive(Copy, Clone, PartialEq, Eq)] +LL | #[derive(Copy, Clone, Default, PartialEq, Eq)] | ^^^^^ | note: the lint level is defined here @@ -62,11 +62,11 @@ 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: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133) - --> $DIR/deriving-with-repr-packed.rs:8:23 +error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters (error E0133) + --> $DIR/deriving-with-repr-packed.rs:11:32 | -LL | #[derive(Copy, Clone, PartialEq, Eq)] - | ^^^^^^^^^ +LL | #[derive(Copy, Clone, Default, PartialEq, Eq)] + | ^^^^^^^^^ | note: the lint level is defined here --> $DIR/deriving-with-repr-packed.rs:1:9 @@ -78,11 +78,11 @@ LL | #![deny(unaligned_references)] = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) Future breakage diagnostic: -error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133) - --> $DIR/deriving-with-repr-packed.rs:16:10 +error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133) + --> $DIR/deriving-with-repr-packed.rs:19:19 | -LL | #[derive(PartialEq, Eq)] - | ^^^^^^^^^ +LL | #[derive(Default, Hash)] + | ^^^^ | note: the lint level is defined here --> $DIR/deriving-with-repr-packed.rs:1:9 @@ -91,14 +91,14 @@ LL | #![deny(unaligned_references)] | ^^^^^^^^^^^^^^^^^^^^ = 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: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) Future breakage diagnostic: -error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133) - --> $DIR/deriving-with-repr-packed.rs:25:10 +error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy` (error E0133) + --> $DIR/deriving-with-repr-packed.rs:39:10 | -LL | #[derive(PartialEq)] - | ^^^^^^^^^ +LL | #[derive(Debug, Default)] + | ^^^^^ | note: the lint level is defined here --> $DIR/deriving-with-repr-packed.rs:1:9 @@ -107,5 +107,5 @@ LL | #![deny(unaligned_references)] | ^^^^^^^^^^^^^^^^^^^^ = 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: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/src/test/ui/process/nofile-limit.rs b/src/test/ui/process/nofile-limit.rs index 549135a46cf..3ddf8d6ef24 100644 --- a/src/test/ui/process/nofile-limit.rs +++ b/src/test/ui/process/nofile-limit.rs @@ -6,7 +6,7 @@ // dont-check-compiler-stderr // only-linux // no-prefer-dynamic -// compile-flags: -Ctarget-feature=+crt-static -Crpath=no +// compile-flags: -Ctarget-feature=+crt-static -Crpath=no -Crelocation-model=static #![feature(exit_status_error)] #![feature(rustc_private)] extern crate libc; |
