]>
git.proxmox.com Git - rustc.git/blob - tests/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.
11 union U { a: I, b: F }
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
; //~ ERROR reference to packed field
24 let _
= u1
.a
; //~ ERROR [E0133]
25 let _
= &u2
.a
; //~ ERROR [E0133]
27 // variation on above with `_` in substructure
28 let (_
,) = (&p
.b
,); //~ ERROR reference to packed field
29 let (_
,) = (u1
.a
,); //~ ERROR [E0133]
30 let (_
,) = (&u2
.a
,); //~ ERROR [E0133]
33 fn let_ascribe_gets_unsafe_field() {
34 let u1
= U { a: I(0) }
;
35 let u2
= U { a: I(1) }
;
36 let p
= P { a: &2, b: &3 }
;
37 let _
: _
= &p
.b
; //~ ERROR reference to packed field
38 let _
: _
= u1
.a
; //~ ERROR [E0133]
39 let _
: _
= &u2
.a
; //~ ERROR [E0133]
41 // variation on above with `_` in substructure
42 let (_
,): _
= (&p
.b
,); //~ ERROR reference to packed field
43 let (_
,): _
= (u1
.a
,); //~ ERROR [E0133]
44 let (_
,): _
= (&u2
.a
,); //~ ERROR [E0133]
47 fn match_unsafe_field_to_wild() {
48 let u1
= U { a: I(0) }
;
49 let u2
= U { a: I(1) }
;
50 let p
= P { a: &2, b: &3 }
;
51 match &p
.b { _ => { }
} //~ ERROR reference to packed field
52 match u1
.a { _ => { }
} //~ ERROR [E0133]
53 match &u2
.a { _ => { }
} //~ ERROR [E0133]
55 // variation on above with `_` in substructure
56 match (&p
.b
,) { (_,) => { }
} //~ ERROR reference to packed field
57 match (u1
.a
,) { (_,) => { }
} //~ ERROR [E0133]
58 match (&u2
.a
,) { (_,) => { }
} //~ ERROR [E0133]