]> git.proxmox.com Git - rustc.git/blame - tests/ui/binding/issue-53114-borrow-checks.rs
New upstream version 1.75.0+dfsg1
[rustc.git] / tests / ui / binding / issue-53114-borrow-checks.rs
CommitLineData
ed00b5ec 1// check-pass
ba9703b0
XL
2// Issue #53114: NLL's borrow check had some deviations from the old borrow
3// checker, and both had some deviations from our ideal state. This test
4// captures the behavior of how `_` bindings are handled with respect to how we
5// flag expressions that are meant to request unsafe blocks.
ed00b5ec 6#![allow(irrefutable_let_patterns, dropping_references)]
ba9703b0
XL
7struct M;
8
9fn let_wild_gets_moved_expr() {
10 let m = M;
11 drop(m);
12 let _ = m; // accepted, and want it to continue to be
13
14 let mm = (M, M); // variation on above with `_` in substructure
15 let (_x, _) = mm;
16 let (_, _y) = mm;
17 let (_, _) = mm;
18}
19
20fn match_moved_expr_to_wild() {
21 let m = M;
22 drop(m);
ed00b5ec 23 match m { _ => { } } // #53114: accepted too
ba9703b0
XL
24
25 let mm = (M, M); // variation on above with `_` in substructure
26 match mm { (_x, _) => { } }
27 match mm { (_, _y) => { } }
ba9703b0 28 match mm { (_, _) => { } }
ba9703b0
XL
29}
30
31fn if_let_moved_expr_to_wild() {
32 let m = M;
33 drop(m);
ed00b5ec 34 if let _ = m { } // #53114: accepted too
ba9703b0
XL
35
36 let mm = (M, M); // variation on above with `_` in substructure
37 if let (_x, _) = mm { }
38 if let (_, _y) = mm { }
ba9703b0 39 if let (_, _) = mm { }
ba9703b0
XL
40}
41
42fn let_wild_gets_borrowed_expr() {
43 let mut m = M;
44 let r = &mut m;
45 let _ = m; // accepted, and want it to continue to be
46 // let _x = m; // (compare with this error.)
47 drop(r);
48
49 let mut mm = (M, M); // variation on above with `_` in substructure
50 let (r1, r2) = (&mut mm.0, &mut mm.1);
51 let (_, _) = mm;
52 drop((r1, r2));
53}
54
55fn match_borrowed_expr_to_wild() {
56 let mut m = M;
57 let r = &mut m;
58 match m { _ => {} } ; // accepted, and want it to continue to be
59 drop(r);
60
61 let mut mm = (M, M); // variation on above with `_` in substructure
62 let (r1, r2) = (&mut mm.0, &mut mm.1);
63 match mm { (_, _) => { } }
64 drop((r1, r2));
65}
66
67fn if_let_borrowed_expr_to_wild() {
68 let mut m = M;
69 let r = &mut m;
70 if let _ = m { } // accepted, and want it to continue to be
71 drop(r);
72
73 let mut mm = (M, M); // variation on above with `_` in substructure
74 let (r1, r2) = (&mut mm.0, &mut mm.1);
75 if let (_, _) = mm { }
76 drop((r1, r2));
77}
78
79fn main() { }