Skip to content

Commit 1a6c2ff

Browse files
committed
make unaligned_reference warning visible in future compat report
1 parent e30d6d9 commit 1a6c2ff

10 files changed

+451
-0
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ declare_lint! {
11411141
"detects unaligned references to fields of packed structs",
11421142
@future_incompatible = FutureIncompatibleInfo {
11431143
reference: "issue #82523 <https://github.com./rust-lang/rust/issues/82523>",
1144+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
11441145
};
11451146
report_in_external_macro
11461147
}

src/test/ui/binding/issue-53114-safety-checks.stderr

+52
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,55 @@ LL | match (&u2.a,) { (_,) => { } }
102102
error: aborting due to 11 previous errors
103103

104104
For more information about this error, try `rustc --explain E0133`.
105+
Future incompatibility report: Future breakage diagnostic:
106+
error: reference to packed field is unaligned
107+
--> $DIR/issue-53114-safety-checks.rs:23:13
108+
|
109+
LL | let _ = &p.b;
110+
| ^^^^
111+
|
112+
= note: `#[deny(unaligned_references)]` on by default
113+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
114+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
115+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
116+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
117+
118+
Future breakage diagnostic:
119+
error: reference to packed field is unaligned
120+
--> $DIR/issue-53114-safety-checks.rs:29:17
121+
|
122+
LL | let (_,) = (&p.b,);
123+
| ^^^^
124+
|
125+
= note: `#[deny(unaligned_references)]` on by default
126+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
127+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
128+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
129+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
130+
131+
Future breakage diagnostic:
132+
error: reference to packed field is unaligned
133+
--> $DIR/issue-53114-safety-checks.rs:39:11
134+
|
135+
LL | match &p.b { _ => { } }
136+
| ^^^^
137+
|
138+
= note: `#[deny(unaligned_references)]` on by default
139+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
140+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
141+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
142+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
143+
144+
Future breakage diagnostic:
145+
error: reference to packed field is unaligned
146+
--> $DIR/issue-53114-safety-checks.rs:45:12
147+
|
148+
LL | match (&p.b,) { (_,) => { } }
149+
| ^^^^
150+
|
151+
= note: `#[deny(unaligned_references)]` on by default
152+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
153+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
154+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
155+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
156+

src/test/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ LL | println!("{}", foo.x);
1313

1414
error: aborting due to previous error
1515

16+
Future incompatibility report: Future breakage diagnostic:
17+
error: reference to packed field is unaligned
18+
--> $DIR/repr_packed.rs:21:24
19+
|
20+
LL | println!("{}", foo.x);
21+
| ^^^^^
22+
|
23+
= note: `#[deny(unaligned_references)]` on by default
24+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
25+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
26+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
27+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
28+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
29+

src/test/ui/derives/deriving-with-repr-packed.stderr

+64
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,67 @@ LL | #[derive(PartialEq)]
4545

4646
error: aborting due to 4 previous errors
4747

48+
Future incompatibility report: Future breakage diagnostic:
49+
error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133)
50+
--> $DIR/deriving-with-repr-packed.rs:8:16
51+
|
52+
LL | #[derive(Copy, Clone, PartialEq, Eq)]
53+
| ^^^^^
54+
|
55+
note: the lint level is defined here
56+
--> $DIR/deriving-with-repr-packed.rs:1:9
57+
|
58+
LL | #![deny(unaligned_references)]
59+
| ^^^^^^^^^^^^^^^^^^^^
60+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
61+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
62+
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
63+
64+
Future breakage diagnostic:
65+
error: `#[derive]` can't be used on a `#[repr(packed)]` struct with type or const parameters (error E0133)
66+
--> $DIR/deriving-with-repr-packed.rs:8:23
67+
|
68+
LL | #[derive(Copy, Clone, PartialEq, Eq)]
69+
| ^^^^^^^^^
70+
|
71+
note: the lint level is defined here
72+
--> $DIR/deriving-with-repr-packed.rs:1:9
73+
|
74+
LL | #![deny(unaligned_references)]
75+
| ^^^^^^^^^^^^^^^^^^^^
76+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
77+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
78+
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
79+
80+
Future breakage diagnostic:
81+
error: `#[derive]` can't be used on a `#[repr(packed)]` struct that does not derive Copy (error E0133)
82+
--> $DIR/deriving-with-repr-packed.rs:16:10
83+
|
84+
LL | #[derive(PartialEq, Eq)]
85+
| ^^^^^^^^^
86+
|
87+
note: the lint level is defined here
88+
--> $DIR/deriving-with-repr-packed.rs:1:9
89+
|
90+
LL | #![deny(unaligned_references)]
91+
| ^^^^^^^^^^^^^^^^^^^^
92+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
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)
95+
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
99+
|
100+
LL | #[derive(PartialEq)]
101+
| ^^^^^^^^^
102+
|
103+
note: the lint level is defined here
104+
--> $DIR/deriving-with-repr-packed.rs:1:9
105+
|
106+
LL | #![deny(unaligned_references)]
107+
| ^^^^^^^^^^^^^^^^^^^^
108+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
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)
111+

src/test/ui/lint/unaligned_references.stderr

+119
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,122 @@ LL | let _ = &packed2.x;
8282

8383
error: aborting due to 7 previous errors
8484

85+
Future incompatibility report: Future breakage diagnostic:
86+
error: reference to packed field is unaligned
87+
--> $DIR/unaligned_references.rs:22:17
88+
|
89+
LL | let _ = &good.ptr;
90+
| ^^^^^^^^^
91+
|
92+
note: the lint level is defined here
93+
--> $DIR/unaligned_references.rs:1:9
94+
|
95+
LL | #![deny(unaligned_references)]
96+
| ^^^^^^^^^^^^^^^^^^^^
97+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
98+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
99+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
100+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
101+
102+
Future breakage diagnostic:
103+
error: reference to packed field is unaligned
104+
--> $DIR/unaligned_references.rs:24:17
105+
|
106+
LL | let _ = &good.data;
107+
| ^^^^^^^^^^
108+
|
109+
note: the lint level is defined here
110+
--> $DIR/unaligned_references.rs:1:9
111+
|
112+
LL | #![deny(unaligned_references)]
113+
| ^^^^^^^^^^^^^^^^^^^^
114+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
115+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
116+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
117+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
118+
119+
Future breakage diagnostic:
120+
error: reference to packed field is unaligned
121+
--> $DIR/unaligned_references.rs:27:17
122+
|
123+
LL | let _ = &good.data as *const _;
124+
| ^^^^^^^^^^
125+
|
126+
note: the lint level is defined here
127+
--> $DIR/unaligned_references.rs:1:9
128+
|
129+
LL | #![deny(unaligned_references)]
130+
| ^^^^^^^^^^^^^^^^^^^^
131+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
132+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
133+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
134+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
135+
136+
Future breakage diagnostic:
137+
error: reference to packed field is unaligned
138+
--> $DIR/unaligned_references.rs:29:27
139+
|
140+
LL | let _: *const _ = &good.data;
141+
| ^^^^^^^^^^
142+
|
143+
note: the lint level is defined here
144+
--> $DIR/unaligned_references.rs:1:9
145+
|
146+
LL | #![deny(unaligned_references)]
147+
| ^^^^^^^^^^^^^^^^^^^^
148+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
149+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
150+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
151+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
152+
153+
Future breakage diagnostic:
154+
error: reference to packed field is unaligned
155+
--> $DIR/unaligned_references.rs:32:17
156+
|
157+
LL | let _ = good.data.clone();
158+
| ^^^^^^^^^^^^^^^^^
159+
|
160+
note: the lint level is defined here
161+
--> $DIR/unaligned_references.rs:1:9
162+
|
163+
LL | #![deny(unaligned_references)]
164+
| ^^^^^^^^^^^^^^^^^^^^
165+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
166+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
167+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
168+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
169+
170+
Future breakage diagnostic:
171+
error: reference to packed field is unaligned
172+
--> $DIR/unaligned_references.rs:35:17
173+
|
174+
LL | let _ = &good.data2[0];
175+
| ^^^^^^^^^^^^^^
176+
|
177+
note: the lint level is defined here
178+
--> $DIR/unaligned_references.rs:1:9
179+
|
180+
LL | #![deny(unaligned_references)]
181+
| ^^^^^^^^^^^^^^^^^^^^
182+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
183+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
184+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
185+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
186+
187+
Future breakage diagnostic:
188+
error: reference to packed field is unaligned
189+
--> $DIR/unaligned_references.rs:45:17
190+
|
191+
LL | let _ = &packed2.x;
192+
| ^^^^^^^^^^
193+
|
194+
note: the lint level is defined here
195+
--> $DIR/unaligned_references.rs:1:9
196+
|
197+
LL | #![deny(unaligned_references)]
198+
| ^^^^^^^^^^^^^^^^^^^^
199+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
200+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
201+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
202+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
203+

src/test/ui/lint/unaligned_references_external_macro.stderr

+30
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,33 @@ LL | | }
2929

3030
error: aborting due to previous error
3131

32+
Future incompatibility report: Future breakage diagnostic:
33+
error: reference to packed field is unaligned
34+
--> $DIR/unaligned_references_external_macro.rs:5:1
35+
|
36+
LL | / unaligned_references_external_crate::mac! {
37+
LL | |
38+
LL | | #[repr(packed)]
39+
LL | | pub struct X {
40+
LL | | pub field: u16
41+
LL | | }
42+
LL | | }
43+
| |_^
44+
|
45+
note: the lint level is defined here
46+
--> $DIR/unaligned_references_external_macro.rs:5:1
47+
|
48+
LL | / unaligned_references_external_crate::mac! {
49+
LL | |
50+
LL | | #[repr(packed)]
51+
LL | | pub struct X {
52+
LL | | pub field: u16
53+
LL | | }
54+
LL | | }
55+
| |_^
56+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
57+
= note: for more information, see issue #82523 <https://github.com./rust-lang/rust/issues/82523>
58+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
59+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
60+
= note: this error originates in the macro `unaligned_references_external_crate::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
61+

0 commit comments

Comments
 (0)