]>
Commit | Line | Data |
---|---|---|
136023e0 | 1 | // edition:2021 |
6a06907d | 2 | |
6a06907d XL |
3 | // Given how the closure desugaring is implemented (at least at the time of writing this test), |
4 | // we don't need to truncate the captured path to a reference into a packed-struct if the field | |
5 | // being referenced will be moved into the closure, since it's safe to move out a field from a | |
6 | // packed-struct. | |
7 | // | |
8 | // However to avoid surprises for the user, or issues when the closure is | |
9 | // inlined we will truncate the capture to access just the struct regardless of if the field | |
10 | // might get moved into the closure. | |
11 | // | |
04454e1e FG |
12 | // It is possible for someone to try writing the code that relies on the desugaring to create a ref |
13 | // into a packed-struct. Here we test that the compiler still detects that case. | |
6a06907d XL |
14 | fn test_missing_unsafe_warning_on_repr_packed() { |
15 | #[repr(packed)] | |
16 | struct Foo { x: String } | |
17 | ||
18 | let foo = Foo { x: String::new() }; | |
19 | ||
20 | let c = || { | |
21 | println!("{}", foo.x); | |
04454e1e | 22 | //~^ ERROR: reference to packed field is unaligned |
6a06907d XL |
23 | //~| WARNING: this was previously accepted by the compiler but is being phased out |
24 | let _z = foo.x; | |
25 | }; | |
26 | ||
27 | c(); | |
28 | } | |
29 | ||
30 | fn main() { | |
31 | test_missing_unsafe_warning_on_repr_packed(); | |
32 | } |