]>
Commit | Line | Data |
---|---|---|
ba9703b0 XL |
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 | #![allow(irrefutable_let_patterns)] | |
6 | struct M; | |
7 | ||
8 | fn let_wild_gets_moved_expr() { | |
9 | let m = M; | |
10 | drop(m); | |
11 | let _ = m; // accepted, and want it to continue to be | |
12 | ||
13 | let mm = (M, M); // variation on above with `_` in substructure | |
14 | let (_x, _) = mm; | |
15 | let (_, _y) = mm; | |
16 | let (_, _) = mm; | |
17 | } | |
18 | ||
19 | fn match_moved_expr_to_wild() { | |
20 | let m = M; | |
21 | drop(m); | |
22 | match m { _ => { } } // #53114: should eventually be accepted too | |
23 | //~^ ERROR [E0382] | |
24 | ||
25 | let mm = (M, M); // variation on above with `_` in substructure | |
26 | match mm { (_x, _) => { } } | |
27 | match mm { (_, _y) => { } } | |
28 | //~^ ERROR [E0382] | |
29 | match mm { (_, _) => { } } | |
30 | //~^ ERROR [E0382] | |
31 | } | |
32 | ||
33 | fn if_let_moved_expr_to_wild() { | |
34 | let m = M; | |
35 | drop(m); | |
36 | if let _ = m { } // #53114: should eventually be accepted too | |
37 | //~^ ERROR [E0382] | |
38 | ||
39 | let mm = (M, M); // variation on above with `_` in substructure | |
40 | if let (_x, _) = mm { } | |
41 | if let (_, _y) = mm { } | |
42 | //~^ ERROR [E0382] | |
43 | if let (_, _) = mm { } | |
44 | //~^ ERROR [E0382] | |
45 | } | |
46 | ||
47 | fn let_wild_gets_borrowed_expr() { | |
48 | let mut m = M; | |
49 | let r = &mut m; | |
50 | let _ = m; // accepted, and want it to continue to be | |
51 | // let _x = m; // (compare with this error.) | |
52 | drop(r); | |
53 | ||
54 | let mut mm = (M, M); // variation on above with `_` in substructure | |
55 | let (r1, r2) = (&mut mm.0, &mut mm.1); | |
56 | let (_, _) = mm; | |
57 | drop((r1, r2)); | |
58 | } | |
59 | ||
60 | fn match_borrowed_expr_to_wild() { | |
61 | let mut m = M; | |
62 | let r = &mut m; | |
63 | match m { _ => {} } ; // accepted, and want it to continue to be | |
64 | drop(r); | |
65 | ||
66 | let mut mm = (M, M); // variation on above with `_` in substructure | |
67 | let (r1, r2) = (&mut mm.0, &mut mm.1); | |
68 | match mm { (_, _) => { } } | |
69 | drop((r1, r2)); | |
70 | } | |
71 | ||
72 | fn if_let_borrowed_expr_to_wild() { | |
73 | let mut m = M; | |
74 | let r = &mut m; | |
75 | if let _ = m { } // accepted, and want it to continue to be | |
76 | drop(r); | |
77 | ||
78 | let mut mm = (M, M); // variation on above with `_` in substructure | |
79 | let (r1, r2) = (&mut mm.0, &mut mm.1); | |
80 | if let (_, _) = mm { } | |
81 | drop((r1, r2)); | |
82 | } | |
83 | ||
84 | fn main() { } |