Skip to content

Commit 1ab05c1

Browse files
committedMar 28, 2021
adjust old test
1 parent ee1caae commit 1ab05c1

4 files changed

+31
-16
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass (note: this is spec-UB, but it works for now)
2+
// ignore-32bit (needs `usize` to be 8-aligned to reproduce all the errors below)
3+
#![allow(dead_code)]
4+
// ignore-emscripten weird assertion?
5+
6+
#[repr(C, packed(4))]
7+
struct Foo4C {
8+
bar: u8,
9+
baz: usize
10+
}
11+
12+
pub fn main() {
13+
let foo = Foo4C { bar: 1, baz: 2 };
14+
let brw = &foo.baz; //~WARN reference to packed field is unaligned
15+
//~^ previously accepted
16+
assert_eq!(*brw, 2);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: reference to packed field is unaligned
2+
--> $DIR/packed-struct-borrow-element-64bit.rs:14:15
3+
|
4+
LL | let brw = &foo.baz;
5+
| ^^^^^^^^
6+
|
7+
= note: `#[warn(unaligned_references)]` on by default
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+
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
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+
12+
warning: 1 warning emitted
13+

‎src/test/ui/packed/packed-struct-borrow-element.rs

-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,4 @@ pub fn main() {
3030
let brw = &foo.baz; //~WARN reference to packed field is unaligned
3131
//~^ previously accepted
3232
assert_eq!(*brw, 2);
33-
34-
let foo = Foo4C { bar: 1, baz: 2 };
35-
let brw = &foo.baz; //~WARN reference to packed field is unaligned
36-
//~^ previously accepted
37-
assert_eq!(*brw, 2);
3833
}

‎src/test/ui/packed/packed-struct-borrow-element.stderr

+1-11
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,5 @@ LL | let brw = &foo.baz;
1919
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
2020
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
2121

22-
warning: reference to packed field is unaligned
23-
--> $DIR/packed-struct-borrow-element.rs:35:15
24-
|
25-
LL | let brw = &foo.baz;
26-
| ^^^^^^^^
27-
|
28-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
29-
= note: for more information, see issue #82523 <https://github.com/rust-lang/rust/issues/82523>
30-
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
31-
32-
warning: 3 warnings emitted
22+
warning: 2 warnings emitted
3323

0 commit comments

Comments
 (0)
Please sign in to comment.