You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve error messages involving derive and packed.
There are two errors involving `derive` and `packed`.
```
`#[derive]` can't be derived on a `#[repr(packed)]` struct with type or const parameters
`#[derive]` can't be derived on a `#[repr(packed)]` struct that does not derive Copy
```
The second one overstates things. It is possible to use derive on a
repr(packed) struct that doesn't derive Copy in two cases.
- 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.
This commit improves things in a few ways.
- Changes the errors to say `$TRAIT can't be derived on this ...`.
This is more accurate, because it's just $TRAIT and *this* packed
struct that are a problem, not *all* derived traits on *all* packed
structs.
- Removed the E0133 error code, because it's incorrect, being a code
relating to `unsafe`.
- Adds more details to the "ERROR" lines in the test case, enough to
distinguish between the two error messages.
- Adds more cases to the test case that don't cause errors, e.g. `Default`
derives.
- Uses a wider variety of builtin traits in the test case, for better coverage.
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
14
14
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
15
15
16
-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133)
17
-
--> $DIR/deriving-with-repr-packed.rs:8:23
16
+
error: `PartialEq` can't be derived on this `#[repr(packed)]` struct with type or const parameters
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23
23
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
24
24
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
25
25
26
-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
27
-
--> $DIR/deriving-with-repr-packed.rs:16:10
26
+
error: `Hash` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
27
+
--> $DIR/deriving-with-repr-packed.rs:19:19
28
28
|
29
-
LL | #[derive(PartialEq, Eq)]
30
-
| ^^^^^^^^^
29
+
LL | #[derive(Default, Hash)]
30
+
| ^^^^
31
31
|
32
32
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
33
33
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
34
-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
34
+
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
35
35
36
-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
37
-
--> $DIR/deriving-with-repr-packed.rs:25:10
36
+
error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
37
+
--> $DIR/deriving-with-repr-packed.rs:39:10
38
38
|
39
-
LL | #[derive(PartialEq)]
40
-
| ^^^^^^^^^
39
+
LL | #[derive(Debug, Default)]
40
+
| ^^^^^
41
41
|
42
42
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
43
43
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
44
-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
44
+
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
93
93
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
94
-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
94
+
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
95
95
96
96
Future breakage diagnostic:
97
-
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
98
-
--> $DIR/deriving-with-repr-packed.rs:25:10
97
+
error: `Debug` can't be derived on this `#[repr(packed)]` struct that does not derive `Copy`
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
109
109
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
110
-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
110
+
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
0 commit comments