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
Rollup merge of #95372 - RalfJung:unaligned_references, r=oli-obk
make unaligned_references lint deny-by-default
This lint has been warn-by-default for a year now (since #82525), so I think it is time to crank it up a bit. Code that triggers the lint causes UB (without `unsafe`) when executed, so we really don't want people to write code like this.
Copy file name to clipboardExpand all lines: src/test/ui/binding/issue-53114-safety-checks.stderr
+58-6
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
-
warning: reference to packed field is unaligned
1
+
error: reference to packed field is unaligned
2
2
--> $DIR/issue-53114-safety-checks.rs:23:13
3
3
|
4
4
LL | let _ = &p.b;
5
5
| ^^^^
6
6
|
7
-
= note: `#[warn(unaligned_references)]` on by default
7
+
= note: `#[deny(unaligned_references)]` on by default
8
8
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9
9
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
10
10
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
11
11
= 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)
12
12
13
-
warning: reference to packed field is unaligned
13
+
error: reference to packed field is unaligned
14
14
--> $DIR/issue-53114-safety-checks.rs:29:17
15
15
|
16
16
LL | let (_,) = (&p.b,);
@@ -21,7 +21,7 @@ LL | let (_,) = (&p.b,);
21
21
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
22
22
= 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)
23
23
24
-
warning: reference to packed field is unaligned
24
+
error: reference to packed field is unaligned
25
25
--> $DIR/issue-53114-safety-checks.rs:39:11
26
26
|
27
27
LL | match &p.b { _ => { } }
@@ -32,7 +32,7 @@ LL | match &p.b { _ => { } }
32
32
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
33
33
= 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: `#[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)
= note: `#[warn(unaligned_references)]` on by default
7
+
= note: `#[deny(unaligned_references)]` on by default
8
8
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9
9
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
10
10
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
11
11
= 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)
12
-
= note: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
12
+
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
= 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)
0 commit comments