Skip to content

Commit 5b6ed25

Browse files
committedJan 31, 2023
Auto merge of #102513 - RalfJung:no-more-unaligned-reference, r=cjgillot,scottmcm
make unaligned_reference a hard error The `unaligned_references` lint has been warn-by-default since Rust 1.53 (#82525) and deny-by-default with mention in cargo future-incompat reports since Rust 1.62 (#95372). Current nightly will become Rust 1.66, so (unless major surprises show up with crater) I think it is time we make this a hard error, and close this old soundness gap in the language. EDIT: Turns out this will only land for Rust 1.67, so there is another 6 weeks of time here for crates to adjust. Fixes #82523.
2 parents dc1d9d5 + dfc4a7b commit 5b6ed25

27 files changed

+170
-686
lines changed
 

‎compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// /!\ IMPORTANT /!\
66
//
77
// Error messages' format must follow the RFC 1567 available here:
8-
// https://github.com/rust-lang/rfcs/pull/1567
8+
// https://rust-lang.github.io/rfcs/1567-long-error-codes-explanation-normalization.html
99

1010
register_diagnostics! {
1111
E0001: include_str!("./error_codes/E0001.md"),
@@ -510,6 +510,7 @@ E0789: include_str!("./error_codes/E0789.md"),
510510
E0790: include_str!("./error_codes/E0790.md"),
511511
E0791: include_str!("./error_codes/E0791.md"),
512512
E0792: include_str!("./error_codes/E0792.md"),
513+
E0793: include_str!("./error_codes/E0793.md"),
513514
;
514515
// E0006, // merged with E0005
515516
// E0008, // cannot bind by-move into a pattern guard
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
An unaligned references to a field of a [packed] struct got created.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0793
6+
#[repr(packed)]
7+
pub struct Foo {
8+
field1: u64,
9+
field2: u8,
10+
}
11+
12+
unsafe {
13+
let foo = Foo { field1: 0, field2: 0 };
14+
// Accessing the field directly is fine.
15+
let val = foo.field1;
16+
// A reference to a packed field causes a error.
17+
let val = &foo.field1; // ERROR
18+
// An implicit `&` is added in format strings, causing the same error.
19+
println!("{}", foo.field1); // ERROR
20+
}
21+
```
22+
23+
Creating a reference to an insufficiently aligned packed field is
24+
[undefined behavior] and therefore disallowed. Using an `unsafe` block does not
25+
change anything about this. Instead, the code should do a copy of the data in
26+
the packed field or use raw pointers and unaligned accesses.
27+
28+
```
29+
#[repr(packed)]
30+
pub struct Foo {
31+
field1: u64,
32+
field2: u8,
33+
}
34+
35+
unsafe {
36+
let foo = Foo { field1: 0, field2: 0 };
37+
38+
// Instead of a reference, we can create a raw pointer...
39+
let ptr = std::ptr::addr_of!(foo.field1);
40+
// ... and then (crucially!) access it in an explicitly unaligned way.
41+
let val = unsafe { ptr.read_unaligned() };
42+
// This would *NOT* be correct:
43+
// let val = unsafe { *ptr }; // Undefined Behavior due to unaligned load!
44+
45+
// For formatting, we can create a copy to avoid the direct reference.
46+
let copy = foo.field1;
47+
println!("{}", copy);
48+
// Creating a copy can be written in a single line with curly braces.
49+
// (This is equivalent to the two lines above.)
50+
println!("{}", { foo.field1 });
51+
}
52+
```
53+
54+
### Additional information
55+
56+
Note that this error is specifically about *references* to packed fields.
57+
Direct by-value access of those fields is fine, since then the compiler has
58+
enough information to generate the correct kind of access.
59+
60+
See [issue #82523] for more information.
61+
62+
[packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
63+
[undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
64+
[issue #82523]: https://github.com/rust-lang/rust/issues/82523

‎compiler/rustc_lint/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ fn register_builtins(store: &mut LintStore) {
324324
store.register_renamed("exceeding_bitshifts", "arithmetic_overflow");
325325
store.register_renamed("redundant_semicolon", "redundant_semicolons");
326326
store.register_renamed("overlapping_patterns", "overlapping_range_endpoints");
327-
store.register_renamed("safe_packed_borrows", "unaligned_references");
328327
store.register_renamed("disjoint_capture_migration", "rust_2021_incompatible_closure_captures");
329328
store.register_renamed("or_patterns_back_compat", "rust_2021_incompatible_or_patterns");
330329
store.register_renamed("non_fmt_panic", "non_fmt_panics");
@@ -487,6 +486,16 @@ fn register_builtins(store: &mut LintStore) {
487486
"converted into hard error, see issue #71800 \
488487
<https://github.com/rust-lang/rust/issues/71800> for more information",
489488
);
489+
store.register_removed(
490+
"safe_packed_borrows",
491+
"converted into hard error, see issue #82523 \
492+
<https://github.com/rust-lang/rust/issues/82523> for more information",
493+
);
494+
store.register_removed(
495+
"unaligned_references",
496+
"converted into hard error, see issue #82523 \
497+
<https://github.com/rust-lang/rust/issues/82523> for more information",
498+
);
490499
}
491500

492501
fn register_internals(store: &mut LintStore) {

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,51 +1187,6 @@ declare_lint! {
11871187
"lints that have been renamed or removed"
11881188
}
11891189

1190-
declare_lint! {
1191-
/// The `unaligned_references` lint detects unaligned references to fields
1192-
/// of [packed] structs.
1193-
///
1194-
/// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
1195-
///
1196-
/// ### Example
1197-
///
1198-
/// ```rust,compile_fail
1199-
/// #[repr(packed)]
1200-
/// pub struct Foo {
1201-
/// field1: u64,
1202-
/// field2: u8,
1203-
/// }
1204-
///
1205-
/// fn main() {
1206-
/// unsafe {
1207-
/// let foo = Foo { field1: 0, field2: 0 };
1208-
/// let _ = &foo.field1;
1209-
/// println!("{}", foo.field1); // An implicit `&` is added here, triggering the lint.
1210-
/// }
1211-
/// }
1212-
/// ```
1213-
///
1214-
/// {{produces}}
1215-
///
1216-
/// ### Explanation
1217-
///
1218-
/// Creating a reference to an insufficiently aligned packed field is [undefined behavior] and
1219-
/// should be disallowed. Using an `unsafe` block does not change anything about this. Instead,
1220-
/// the code should do a copy of the data in the packed field or use raw pointers and unaligned
1221-
/// accesses. See [issue #82523] for more information.
1222-
///
1223-
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1224-
/// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
1225-
pub UNALIGNED_REFERENCES,
1226-
Deny,
1227-
"detects unaligned references to fields of packed structs",
1228-
@future_incompatible = FutureIncompatibleInfo {
1229-
reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
1230-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
1231-
};
1232-
report_in_external_macro
1233-
}
1234-
12351190
declare_lint! {
12361191
/// The `const_item_mutation` lint detects attempts to mutate a `const`
12371192
/// item.
@@ -3308,7 +3263,6 @@ declare_lint_pass! {
33083263
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
33093264
INVALID_TYPE_PARAM_DEFAULT,
33103265
RENAMED_AND_REMOVED_LINTS,
3311-
UNALIGNED_REFERENCES,
33123266
CONST_ITEM_MUTATION,
33133267
PATTERNS_IN_FNS_WITHOUT_BODY,
33143268
MISSING_FRAGMENT_SPECIFIER,

‎compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use rustc_errors::struct_span_err;
12
use rustc_middle::mir::visit::{PlaceContext, Visitor};
23
use rustc_middle::mir::*;
34
use rustc_middle::ty::{self, TyCtxt};
4-
use rustc_session::lint::builtin::UNALIGNED_REFERENCES;
55

66
use crate::util;
77
use crate::MirLint;
@@ -49,31 +49,22 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
4949
// shouldn't do.
5050
unreachable!();
5151
} else {
52-
let source_info = self.source_info;
53-
let lint_root = self.body.source_scopes[source_info.scope]
54-
.local_data
55-
.as_ref()
56-
.assert_crate_local()
57-
.lint_root;
58-
self.tcx.struct_span_lint_hir(
59-
UNALIGNED_REFERENCES,
60-
lint_root,
61-
source_info.span,
62-
"reference to packed field is unaligned",
63-
|lint| {
64-
lint
65-
.note(
66-
"fields of packed structs are not properly aligned, and creating \
67-
a misaligned reference is undefined behavior (even if that \
68-
reference is never dereferenced)",
69-
)
70-
.help(
71-
"copy the field contents to a local variable, or replace the \
72-
reference with a raw pointer and use `read_unaligned`/`write_unaligned` \
73-
(loads and stores via `*p` must be properly aligned even when using raw pointers)"
74-
)
75-
},
76-
);
52+
struct_span_err!(
53+
self.tcx.sess,
54+
self.source_info.span,
55+
E0793,
56+
"reference to packed field is unaligned"
57+
)
58+
.note(
59+
"fields of packed structs are not properly aligned, and creating \
60+
a misaligned reference is undefined behavior (even if that \
61+
reference is never dereferenced)",
62+
).help(
63+
"copy the field contents to a local variable, or replace the \
64+
reference with a raw pointer and use `read_unaligned`/`write_unaligned` \
65+
(loads and stores via `*p` must be properly aligned even when using raw pointers)"
66+
)
67+
.emit();
7768
}
7869
}
7970
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
// This should fail even without validation/SB
22
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
33

4-
#![allow(dead_code, unused_variables, unaligned_references)]
4+
#![allow(dead_code, unused_variables)]
5+
6+
use std::{ptr, mem};
57

68
#[repr(packed)]
79
struct Foo {
810
x: i32,
911
y: i32,
1012
}
1113

14+
unsafe fn raw_to_ref<'a, T>(x: *const T) -> &'a T {
15+
mem::transmute(x)
16+
}
17+
1218
fn main() {
1319
// Try many times as this might work by chance.
1420
for _ in 0..20 {
1521
let foo = Foo { x: 42, y: 99 };
16-
let p = &foo.x;
17-
let i = *p; //~ERROR: alignment 4 is required
22+
// There seem to be implicit reborrows, which make the error already appear here
23+
let p: &i32 = unsafe { raw_to_ref(ptr::addr_of!(foo.x)) }; //~ERROR: alignment 4 is required
24+
let i = *p;
1825
}
1926
}

‎src/tools/miri/tests/fail/unaligned_pointers/reference_to_packed.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/reference_to_packed.rs:LL:CC
33
|
4-
LL | let i = *p;
5-
| ^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
4+
LL | let p: &i32 = unsafe { raw_to_ref(ptr::addr_of!(foo.x)) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

‎tests/ui/binding/issue-53114-safety-checks.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ fn let_wild_gets_unsafe_field() {
2121
let u2 = U { a: I(1) };
2222
let p = P { a: &2, b: &3 };
2323
let _ = &p.b; //~ ERROR reference to packed field
24-
//~^ WARN will become a hard error
2524
let _ = u1.a; // #53114: should eventually signal error as well
2625
let _ = &u2.a; //~ ERROR [E0133]
2726

2827
// variation on above with `_` in substructure
2928
let (_,) = (&p.b,); //~ ERROR reference to packed field
30-
//~^ WARN will become a hard error
3129
let (_,) = (u1.a,); //~ ERROR [E0133]
3230
let (_,) = (&u2.a,); //~ ERROR [E0133]
3331
}
@@ -37,13 +35,11 @@ fn match_unsafe_field_to_wild() {
3735
let u2 = U { a: I(1) };
3836
let p = P { a: &2, b: &3 };
3937
match &p.b { _ => { } } //~ ERROR reference to packed field
40-
//~^ WARN will become a hard error
4138
match u1.a { _ => { } } //~ ERROR [E0133]
4239
match &u2.a { _ => { } } //~ ERROR [E0133]
4340

4441
// variation on above with `_` in substructure
4542
match (&p.b,) { (_,) => { } } //~ ERROR reference to packed field
46-
//~^ WARN will become a hard error
4743
match (u1.a,) { (_,) => { } } //~ ERROR [E0133]
4844
match (&u2.a,) { (_,) => { } } //~ ERROR [E0133]
4945
}
Lines changed: 16 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,89 @@
1-
error: reference to packed field is unaligned
1+
error[E0793]: reference to packed field is unaligned
22
--> $DIR/issue-53114-safety-checks.rs:23:13
33
|
44
LL | let _ = &p.b;
55
| ^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
97
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
108
= 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)
11-
= note: `#[deny(unaligned_references)]` on by default
129

13-
error: reference to packed field is unaligned
14-
--> $DIR/issue-53114-safety-checks.rs:29:17
10+
error[E0793]: reference to packed field is unaligned
11+
--> $DIR/issue-53114-safety-checks.rs:28:17
1512
|
1613
LL | let (_,) = (&p.b,);
1714
| ^^^^
1815
|
19-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
20-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
2116
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
2217
= 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)
2318

24-
error: reference to packed field is unaligned
25-
--> $DIR/issue-53114-safety-checks.rs:39:11
19+
error[E0793]: reference to packed field is unaligned
20+
--> $DIR/issue-53114-safety-checks.rs:37:11
2621
|
2722
LL | match &p.b { _ => { } }
2823
| ^^^^
2924
|
30-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
3225
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
3326
= 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)
3427

35-
error: reference to packed field is unaligned
36-
--> $DIR/issue-53114-safety-checks.rs:45:12
28+
error[E0793]: reference to packed field is unaligned
29+
--> $DIR/issue-53114-safety-checks.rs:42:12
3730
|
3831
LL | match (&p.b,) { (_,) => { } }
3932
| ^^^^
4033
|
41-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
42-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
4334
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
4435
= 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)
4536

4637
error[E0133]: access to union field is unsafe and requires unsafe function or block
47-
--> $DIR/issue-53114-safety-checks.rs:26:13
38+
--> $DIR/issue-53114-safety-checks.rs:25:13
4839
|
4940
LL | let _ = &u2.a;
5041
| ^^^^^ access to union field
5142
|
5243
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
5344

5445
error[E0133]: access to union field is unsafe and requires unsafe function or block
55-
--> $DIR/issue-53114-safety-checks.rs:31:17
46+
--> $DIR/issue-53114-safety-checks.rs:29:17
5647
|
5748
LL | let (_,) = (u1.a,);
5849
| ^^^^ access to union field
5950
|
6051
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
6152

6253
error[E0133]: access to union field is unsafe and requires unsafe function or block
63-
--> $DIR/issue-53114-safety-checks.rs:32:17
54+
--> $DIR/issue-53114-safety-checks.rs:30:17
6455
|
6556
LL | let (_,) = (&u2.a,);
6657
| ^^^^^ access to union field
6758
|
6859
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
6960

7061
error[E0133]: access to union field is unsafe and requires unsafe function or block
71-
--> $DIR/issue-53114-safety-checks.rs:41:11
62+
--> $DIR/issue-53114-safety-checks.rs:38:11
7263
|
7364
LL | match u1.a { _ => { } }
7465
| ^^^^ access to union field
7566
|
7667
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
7768

7869
error[E0133]: access to union field is unsafe and requires unsafe function or block
79-
--> $DIR/issue-53114-safety-checks.rs:42:11
70+
--> $DIR/issue-53114-safety-checks.rs:39:11
8071
|
8172
LL | match &u2.a { _ => { } }
8273
| ^^^^^ access to union field
8374
|
8475
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
8576

8677
error[E0133]: access to union field is unsafe and requires unsafe function or block
87-
--> $DIR/issue-53114-safety-checks.rs:47:12
78+
--> $DIR/issue-53114-safety-checks.rs:43:12
8879
|
8980
LL | match (u1.a,) { (_,) => { } }
9081
| ^^^^ access to union field
9182
|
9283
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
9384

9485
error[E0133]: access to union field is unsafe and requires unsafe function or block
95-
--> $DIR/issue-53114-safety-checks.rs:48:12
86+
--> $DIR/issue-53114-safety-checks.rs:44:12
9687
|
9788
LL | match (&u2.a,) { (_,) => { } }
9889
| ^^^^^ access to union field
@@ -101,56 +92,5 @@ LL | match (&u2.a,) { (_,) => { } }
10192

10293
error: aborting due to 11 previous errors
10394

104-
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-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
113-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
114-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
115-
= 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)
116-
= note: `#[deny(unaligned_references)]` on by default
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-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
126-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
127-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
128-
= 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)
129-
= note: `#[deny(unaligned_references)]` on by default
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-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
139-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
140-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
141-
= 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)
142-
= note: `#[deny(unaligned_references)]` on by default
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-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
152-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
153-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
154-
= 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)
155-
= note: `#[deny(unaligned_references)]` on by default
156-
95+
Some errors have detailed explanations: E0133, E0793.
96+
For more information about an error, try `rustc --explain E0133`.

‎tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ fn test_missing_unsafe_warning_on_repr_packed() {
2020
let c = || {
2121
println!("{}", foo.x);
2222
//~^ ERROR: reference to packed field is unaligned
23-
//~| WARNING: this was previously accepted by the compiler but is being phased out
2423
let _z = foo.x;
2524
};
2625

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
error: reference to packed field is unaligned
1+
error[E0793]: reference to packed field is unaligned
22
--> $DIR/repr_packed.rs:21:24
33
|
44
LL | println!("{}", foo.x);
55
| ^^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
97
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
108
= 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)
11-
= note: `#[deny(unaligned_references)]` on by default
129
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
1310

1411
error: aborting due to previous error
1512

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-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
25-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
26-
= 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)
27-
= note: `#[deny(unaligned_references)]` on by default
28-
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
29-
13+
For more information about this error, try `rustc --explain E0793`.

‎tests/ui/derives/deriving-with-repr-packed-2.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unaligned_references)]
2-
31
// Check that deriving certain builtin traits on certain packed structs cause
42
// errors. To avoid potentially misaligned references, field copies must be
53
// used, which involves adding `T: Copy` bounds.

‎tests/ui/derives/deriving-with-repr-packed-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0599]: the method `clone` exists for struct `Foo<NonCopy>`, but its trait bounds were not satisfied
2-
--> $DIR/deriving-with-repr-packed-2.rs:20:11
2+
--> $DIR/deriving-with-repr-packed-2.rs:18:11
33
|
44
LL | pub struct Foo<T>(T, T, T);
55
| -----------------
@@ -19,7 +19,7 @@ LL | _ = x.clone();
1919
note: the following trait bounds were not satisfied:
2020
`NonCopy: Clone`
2121
`NonCopy: Copy`
22-
--> $DIR/deriving-with-repr-packed-2.rs:7:16
22+
--> $DIR/deriving-with-repr-packed-2.rs:5:16
2323
|
2424
LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
2525
| ^^^^^ unsatisfied trait bound introduced in this `derive` macro

‎tests/ui/derives/deriving-with-repr-packed.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unaligned_references)]
2-
31
// Check that deriving certain builtin traits on certain packed structs cause
42
// errors. To avoid potentially misaligned references, field copies must be
53
// used, which involves adding `T: Copy` bounds.

‎tests/ui/derives/deriving-with-repr-packed.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: byte slice in a packed struct that derives a built-in trait
2-
--> $DIR/deriving-with-repr-packed.rs:33:5
2+
--> $DIR/deriving-with-repr-packed.rs:31:5
33
|
44
LL | #[derive(Debug)]
55
| ----- in this derive macro expansion
@@ -14,7 +14,7 @@ LL | data: [u8],
1414
= note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
1515

1616
error[E0507]: cannot move out of `self` which is behind a shared reference
17-
--> $DIR/deriving-with-repr-packed.rs:24:10
17+
--> $DIR/deriving-with-repr-packed.rs:22:10
1818
|
1919
LL | #[derive(Debug, Default)]
2020
| ----- in this derive macro expansion
@@ -29,7 +29,7 @@ error: aborting due to previous error; 1 warning emitted
2929
For more information about this error, try `rustc --explain E0507`.
3030
Future incompatibility report: Future breakage diagnostic:
3131
warning: byte slice in a packed struct that derives a built-in trait
32-
--> $DIR/deriving-with-repr-packed.rs:33:5
32+
--> $DIR/deriving-with-repr-packed.rs:31:5
3333
|
3434
LL | #[derive(Debug)]
3535
| ----- in this derive macro expansion

‎tests/ui/lint/unaligned_references.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![deny(unaligned_references)]
2-
31
#[repr(packed)]
42
pub struct Good {
53
data: u64,
@@ -20,20 +18,14 @@ fn main() {
2018
let good = Good { data: 0, ptr: &0, data2: [0, 0], aligned: [0; 32] };
2119

2220
let _ = &good.ptr; //~ ERROR reference to packed field
23-
//~^ previously accepted
2421
let _ = &good.data; //~ ERROR reference to packed field
25-
//~^ previously accepted
2622
// Error even when turned into raw pointer immediately.
2723
let _ = &good.data as *const _; //~ ERROR reference to packed field
28-
//~^ previously accepted
2924
let _: *const _ = &good.data; //~ ERROR reference to packed field
30-
//~^ previously accepted
3125
// Error on method call.
3226
let _ = good.data.clone(); //~ ERROR reference to packed field
33-
//~^ previously accepted
3427
// Error for nested fields.
3528
let _ = &good.data2[0]; //~ ERROR reference to packed field
36-
//~^ previously accepted
3729

3830
let _ = &*good.ptr; // ok, behind a pointer
3931
let _ = &good.aligned; // ok, has align 1
@@ -43,7 +35,6 @@ fn main() {
4335
unsafe {
4436
let packed2 = Packed2 { x: 0, y: 0, z: 0 };
4537
let _ = &packed2.x; //~ ERROR reference to packed field
46-
//~^ previously accepted
4738
let _ = &packed2.y; // ok, has align 2 in packed(2) struct
4839
let _ = &packed2.z; // ok, has align 1
4940
}
@@ -88,7 +79,6 @@ fn main() {
8879
},
8980
);
9081
let _ref = &m1.1.a; //~ ERROR reference to packed field
91-
//~^ previously accepted
9282

9383
let m2 = Misalign(
9484
0,
@@ -98,6 +88,5 @@ fn main() {
9888
},
9989
);
10090
let _ref = &m2.1.a; //~ ERROR reference to packed field
101-
//~^ previously accepted
10291
}
10392
}

‎tests/ui/lint/unaligned_references.stderr

Lines changed: 19 additions & 194 deletions
Large diffs are not rendered by default.

‎tests/ui/lint/unaligned_references_external_macro.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
extern crate unaligned_references_external_crate;
44

55
unaligned_references_external_crate::mac! { //~ERROR reference to packed field is unaligned
6-
//~^ previously accepted
76
#[repr(packed)]
87
pub struct X {
98
pub field: u16
Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,18 @@
1-
error: reference to packed field is unaligned
1+
error[E0793]: reference to packed field is unaligned
22
--> $DIR/unaligned_references_external_macro.rs:5:1
33
|
44
LL | / unaligned_references_external_crate::mac! {
5-
LL | |
65
LL | | #[repr(packed)]
76
LL | | pub struct X {
87
LL | | pub field: u16
98
LL | | }
109
LL | | }
1110
| |_^
1211
|
13-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
1512
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
1613
= 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)
17-
note: the lint level is defined here
18-
--> $DIR/unaligned_references_external_macro.rs:5:1
19-
|
20-
LL | / unaligned_references_external_crate::mac! {
21-
LL | |
22-
LL | | #[repr(packed)]
23-
LL | | pub struct X {
24-
LL | | pub field: u16
25-
LL | | }
26-
LL | | }
27-
| |_^
2814
= note: this error originates in the macro `unaligned_references_external_crate::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
2915

3016
error: aborting due to previous error
3117

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-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
46-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
47-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
48-
= 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)
49-
note: the lint level is defined here
50-
--> $DIR/unaligned_references_external_macro.rs:5:1
51-
|
52-
LL | / unaligned_references_external_crate::mac! {
53-
LL | |
54-
LL | | #[repr(packed)]
55-
LL | | pub struct X {
56-
LL | | pub field: u16
57-
LL | | }
58-
LL | | }
59-
| |_^
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-
18+
For more information about this error, try `rustc --explain E0793`.

‎tests/ui/packed/issue-27060-rpass.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎tests/ui/packed/issue-27060-rpass.stderr

Lines changed: 0 additions & 68 deletions
This file was deleted.

‎tests/ui/packed/issue-27060.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ fn main() {
1313
};
1414

1515
let _ = &good.data; //~ ERROR reference to packed field
16-
//~| hard error
1716
let _ = &good.data2[0]; //~ ERROR reference to packed field
18-
//~| hard error
1917

2018
let _ = &good.data; //~ ERROR reference to packed field
21-
//~| hard error
2219
let _ = &good.data2[0]; //~ ERROR reference to packed field
23-
//~| hard error
2420
let _ = &*good.data; // ok, behind a pointer
2521
let _ = &good.aligned; // ok, has align 1
2622
let _ = &good.aligned[2]; // ok, has align 1

‎tests/ui/packed/issue-27060.stderr

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,39 @@
1-
error: reference to packed field is unaligned
1+
error[E0793]: reference to packed field is unaligned
22
--> $DIR/issue-27060.rs:15:13
33
|
44
LL | let _ = &good.data;
55
| ^^^^^^^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
97
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
108
= 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)
11-
= note: `#[deny(unaligned_references)]` on by default
129

13-
error: reference to packed field is unaligned
14-
--> $DIR/issue-27060.rs:17:13
10+
error[E0793]: reference to packed field is unaligned
11+
--> $DIR/issue-27060.rs:16:13
1512
|
1613
LL | let _ = &good.data2[0];
1714
| ^^^^^^^^^^^^^^
1815
|
19-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
20-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
2116
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
2217
= 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)
2318

24-
error: reference to packed field is unaligned
25-
--> $DIR/issue-27060.rs:20:13
19+
error[E0793]: reference to packed field is unaligned
20+
--> $DIR/issue-27060.rs:18:13
2621
|
2722
LL | let _ = &good.data;
2823
| ^^^^^^^^^^
2924
|
30-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
3225
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
3326
= 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)
3427

35-
error: reference to packed field is unaligned
36-
--> $DIR/issue-27060.rs:22:13
28+
error[E0793]: reference to packed field is unaligned
29+
--> $DIR/issue-27060.rs:19:13
3730
|
3831
LL | let _ = &good.data2[0];
3932
| ^^^^^^^^^^^^^^
4033
|
41-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
42-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
4334
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
4435
= 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)
4536

4637
error: aborting due to 4 previous errors
4738

48-
Future incompatibility report: Future breakage diagnostic:
49-
error: reference to packed field is unaligned
50-
--> $DIR/issue-27060.rs:15:13
51-
|
52-
LL | let _ = &good.data;
53-
| ^^^^^^^^^^
54-
|
55-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
56-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
57-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
58-
= 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)
59-
= note: `#[deny(unaligned_references)]` on by default
60-
61-
Future breakage diagnostic:
62-
error: reference to packed field is unaligned
63-
--> $DIR/issue-27060.rs:17:13
64-
|
65-
LL | let _ = &good.data2[0];
66-
| ^^^^^^^^^^^^^^
67-
|
68-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
69-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
70-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
71-
= 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)
72-
= note: `#[deny(unaligned_references)]` on by default
73-
74-
Future breakage diagnostic:
75-
error: reference to packed field is unaligned
76-
--> $DIR/issue-27060.rs:20:13
77-
|
78-
LL | let _ = &good.data;
79-
| ^^^^^^^^^^
80-
|
81-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
82-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
83-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
84-
= 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)
85-
= note: `#[deny(unaligned_references)]` on by default
86-
87-
Future breakage diagnostic:
88-
error: reference to packed field is unaligned
89-
--> $DIR/issue-27060.rs:22:13
90-
|
91-
LL | let _ = &good.data2[0];
92-
| ^^^^^^^^^^^^^^
93-
|
94-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
95-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
96-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
97-
= 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)
98-
= note: `#[deny(unaligned_references)]` on by default
99-
39+
For more information about this error, try `rustc --explain E0793`.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-pass (note: this is spec-UB, but it works for now)
21
// ignore-32bit (needs `usize` to be 8-aligned to reproduce all the errors below)
32
#![allow(dead_code)]
43
// ignore-emscripten weird assertion?
@@ -9,10 +8,8 @@ struct Foo4C {
98
baz: usize
109
}
1110

12-
#[warn(unaligned_references)]
1311
pub fn main() {
1412
let foo = Foo4C { bar: 1, baz: 2 };
15-
let brw = &foo.baz; //~WARN reference to packed field is unaligned
16-
//~^ previously accepted
13+
let brw = &foo.baz; //~ERROR reference to packed field is unaligned
1714
assert_eq!(*brw, 2);
1815
}
Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
1-
warning: reference to packed field is unaligned
2-
--> $DIR/packed-struct-borrow-element-64bit.rs:15:15
1+
error[E0793]: reference to packed field is unaligned
2+
--> $DIR/packed-struct-borrow-element-64bit.rs:13:15
33
|
44
LL | let brw = &foo.baz;
55
| ^^^^^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
97
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
108
= 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)
11-
note: the lint level is defined here
12-
--> $DIR/packed-struct-borrow-element-64bit.rs:12:8
13-
|
14-
LL | #[warn(unaligned_references)]
15-
| ^^^^^^^^^^^^^^^^^^^^
16-
17-
warning: 1 warning emitted
189

19-
Future incompatibility report: Future breakage diagnostic:
20-
warning: reference to packed field is unaligned
21-
--> $DIR/packed-struct-borrow-element-64bit.rs:15:15
22-
|
23-
LL | let brw = &foo.baz;
24-
| ^^^^^^^^
25-
|
26-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
28-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
29-
= 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)
30-
note: the lint level is defined here
31-
--> $DIR/packed-struct-borrow-element-64bit.rs:12:8
32-
|
33-
LL | #[warn(unaligned_references)]
34-
| ^^^^^^^^^^^^^^^^^^^^
10+
error: aborting due to previous error
3511

12+
For more information about this error, try `rustc --explain E0793`.

‎tests/ui/packed/packed-struct-borrow-element.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-pass (note: this is spec-UB, but it works for now)
21
#![allow(dead_code)]
32
// ignore-emscripten weird assertion?
43

@@ -20,15 +19,12 @@ struct Foo4C {
2019
baz: usize
2120
}
2221

23-
#[warn(unaligned_references)]
2422
pub fn main() {
2523
let foo = Foo1 { bar: 1, baz: 2 };
26-
let brw = &foo.baz; //~WARN reference to packed field is unaligned
27-
//~^ previously accepted
24+
let brw = &foo.baz; //~ERROR reference to packed field is unaligned
2825
assert_eq!(*brw, 2);
2926

3027
let foo = Foo2 { bar: 1, baz: 2 };
31-
let brw = &foo.baz; //~WARN reference to packed field is unaligned
32-
//~^ previously accepted
28+
let brw = &foo.baz; //~ERROR reference to packed field is unaligned
3329
assert_eq!(*brw, 2);
3430
}
Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,21 @@
1-
warning: reference to packed field is unaligned
2-
--> $DIR/packed-struct-borrow-element.rs:26:15
1+
error[E0793]: reference to packed field is unaligned
2+
--> $DIR/packed-struct-borrow-element.rs:24:15
33
|
44
LL | let brw = &foo.baz;
55
| ^^^^^^^^
66
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
97
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
108
= 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)
11-
note: the lint level is defined here
12-
--> $DIR/packed-struct-borrow-element.rs:23:8
13-
|
14-
LL | #[warn(unaligned_references)]
15-
| ^^^^^^^^^^^^^^^^^^^^
169

17-
warning: reference to packed field is unaligned
18-
--> $DIR/packed-struct-borrow-element.rs:31:15
10+
error[E0793]: reference to packed field is unaligned
11+
--> $DIR/packed-struct-borrow-element.rs:28:15
1912
|
2013
LL | let brw = &foo.baz;
2114
| ^^^^^^^^
2215
|
23-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
2516
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
2617
= 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)
2718

28-
warning: 2 warnings emitted
29-
30-
Future incompatibility report: Future breakage diagnostic:
31-
warning: reference to packed field is unaligned
32-
--> $DIR/packed-struct-borrow-element.rs:26:15
33-
|
34-
LL | let brw = &foo.baz;
35-
| ^^^^^^^^
36-
|
37-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
38-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
39-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
40-
= 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)
41-
note: the lint level is defined here
42-
--> $DIR/packed-struct-borrow-element.rs:23:8
43-
|
44-
LL | #[warn(unaligned_references)]
45-
| ^^^^^^^^^^^^^^^^^^^^
46-
47-
Future breakage diagnostic:
48-
warning: reference to packed field is unaligned
49-
--> $DIR/packed-struct-borrow-element.rs:31:15
50-
|
51-
LL | let brw = &foo.baz;
52-
| ^^^^^^^^
53-
|
54-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
55-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
56-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
57-
= 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)
58-
note: the lint level is defined here
59-
--> $DIR/packed-struct-borrow-element.rs:23:8
60-
|
61-
LL | #[warn(unaligned_references)]
62-
| ^^^^^^^^^^^^^^^^^^^^
19+
error: aborting due to 2 previous errors
6320

21+
For more information about this error, try `rustc --explain E0793`.

0 commit comments

Comments
 (0)
Please sign in to comment.