]> git.proxmox.com Git - rustc.git/blob - src/test/ui/binding/issue-53114-safety-checks.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / test / ui / binding / issue-53114-safety-checks.rs
1 // Issue #53114: NLL's borrow check had some deviations from the old borrow
2 // checker, and both had some deviations from our ideal state. This test
3 // captures the behavior of how `_` bindings are handled with respect to how we
4 // flag expressions that are meant to request unsafe blocks.
5
6 #![feature(untagged_unions)]
7
8 struct I(i64);
9 struct F(f64);
10
11 union U { a: I, b: F }
12
13 #[repr(packed)]
14 struct P {
15 a: &'static i8,
16 b: &'static u32,
17 }
18
19 fn let_wild_gets_unsafe_field() {
20 let u1 = U { a: I(0) };
21 let u2 = U { a: I(1) };
22 let p = P { a: &2, b: &3 };
23 let _ = &p.b; //~ WARN E0133
24 //~^ WARN will become a hard error
25 let _ = u1.a; // #53114: should eventually signal error as well
26 let _ = &u2.a; //~ ERROR [E0133]
27
28 // variation on above with `_` in substructure
29 let (_,) = (&p.b,); //~ WARN E0133
30 //~^ WARN will become a hard error
31 let (_,) = (u1.a,); //~ ERROR [E0133]
32 let (_,) = (&u2.a,); //~ ERROR [E0133]
33 }
34
35 fn match_unsafe_field_to_wild() {
36 let u1 = U { a: I(0) };
37 let u2 = U { a: I(1) };
38 let p = P { a: &2, b: &3 };
39 match &p.b { _ => { } } //~ WARN E0133
40 //~^ WARN will become a hard error
41 match u1.a { _ => { } } //~ ERROR [E0133]
42 match &u2.a { _ => { } } //~ ERROR [E0133]
43
44 // variation on above with `_` in substructure
45 match (&p.b,) { (_,) => { } } //~ WARN E0133
46 //~^ WARN will become a hard error
47 match (u1.a,) { (_,) => { } } //~ ERROR [E0133]
48 match (&u2.a,) { (_,) => { } } //~ ERROR [E0133]
49 }
50
51 fn main() { }