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
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.
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.
14 fn test_missing_unsafe_warning_on_repr_packed() {
16 struct Foo { x: String }
18 let foo = Foo { x: String::new() };
21 println!("{}", foo.x);
22 //~^ ERROR: reference to packed field is unaligned
30 test_missing_unsafe_warning_on_repr_packed();