]> git.lizzy.rs Git - rust.git/blob - tests/ui/nll/closure-access-spans.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / ui / nll / closure-access-spans.rs
1 // check that accesses due to a closure capture give a special note
2
3 fn closure_imm_capture_conflict(mut x: i32) {
4     let r = &mut x;
5     || x; //~ ERROR
6     r.use_mut();
7 }
8
9 fn closure_mut_capture_conflict(mut x: i32) {
10     let r = &mut x;
11     || x = 2; //~ ERROR
12     r.use_mut();
13 }
14
15 fn closure_unique_capture_conflict(mut x: &mut i32) {
16     let r = &mut x;
17     || *x = 2; //~ ERROR
18     r.use_mut();
19 }
20
21 fn closure_copy_capture_conflict(mut x: i32) {
22     let r = &mut x;
23     move || x; //~ ERROR
24     r.use_ref();
25 }
26
27 fn closure_move_capture_conflict(mut x: String) {
28     let r = &x;
29     || x; //~ ERROR
30     r.use_ref();
31 }
32
33 fn closure_imm_capture_moved(mut x: String) {
34     let r = x;
35     || x.len(); //~ ERROR
36 }
37
38 fn closure_mut_capture_moved(mut x: String) {
39     let r = x;
40     || x = String::new(); //~ ERROR
41 }
42
43 fn closure_unique_capture_moved(x: &mut String) {
44     let r = x;
45     || *x = String::new(); //~ ERROR
46 }
47
48 fn closure_move_capture_moved(x: &mut String) {
49     let r = x;
50     || x; //~ ERROR
51 }
52
53 fn main() {}
54
55 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
56 impl<T> Fake for T { }