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
Auto merge of #100064 - RalfJung:disaligned, r=petrochenkov
fix is_disaligned logic for nested packed structs
#83605 broke the `is_disaligned` logic by bailing out of the loop in `is_within_packed` early. This PR fixes that problem and adds suitable tests.
Fixes#99838
Copy file name to clipboardExpand all lines: src/test/ui/lint/unaligned_references.stderr
+57-1
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,29 @@ LL | let _ = &packed2.x;
80
80
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
81
81
= 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)
82
82
83
-
error: aborting due to 7 previous errors
83
+
error: reference to packed field is unaligned
84
+
--> $DIR/unaligned_references.rs:90:20
85
+
|
86
+
LL | let _ref = &m1.1.a;
87
+
| ^^^^^^^
88
+
|
89
+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
90
+
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
91
+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
92
+
= 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)
93
+
94
+
error: reference to packed field is unaligned
95
+
--> $DIR/unaligned_references.rs:100:20
96
+
|
97
+
LL | let _ref = &m2.1.a;
98
+
| ^^^^^^^
99
+
|
100
+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
101
+
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
102
+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
103
+
= 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)
= 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
224
= 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
225
226
+
Future breakage diagnostic:
227
+
error: reference to packed field is unaligned
228
+
--> $DIR/unaligned_references.rs:90:20
229
+
|
230
+
LL | let _ref = &m1.1.a;
231
+
| ^^^^^^^
232
+
|
233
+
note: the lint level is defined here
234
+
--> $DIR/unaligned_references.rs:1:9
235
+
|
236
+
LL | #![deny(unaligned_references)]
237
+
| ^^^^^^^^^^^^^^^^^^^^
238
+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
239
+
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
240
+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
241
+
= 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)
242
+
243
+
Future breakage diagnostic:
244
+
error: reference to packed field is unaligned
245
+
--> $DIR/unaligned_references.rs:100:20
246
+
|
247
+
LL | let _ref = &m2.1.a;
248
+
| ^^^^^^^
249
+
|
250
+
note: the lint level is defined here
251
+
--> $DIR/unaligned_references.rs:1:9
252
+
|
253
+
LL | #![deny(unaligned_references)]
254
+
| ^^^^^^^^^^^^^^^^^^^^
255
+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
256
+
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
257
+
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
258
+
= 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)
0 commit comments