]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs
Auto merge of #87284 - Aaron1011:remove-paren-special, r=petrochenkov
[rust.git] / src / test / ui / borrowck / issue-55492-borrowck-migrate-scans-parents.rs
1 // rust-lang/rust#55492: errors detected during MIR-borrowck's
2 // analysis of a closure body may only be caught when AST-borrowck
3 // looks at some parent.
4
5 // revisions: migrate nll
6
7 // Since we are testing nll (and migration) explicitly as a separate
8 // revisions, don't worry about the --compare-mode=nll on this test.
9
10 // ignore-compare-mode-nll
11
12 //[nll]compile-flags: -Z borrowck=mir
13
14
15 // transcribed from borrowck-closures-unique.rs
16 mod borrowck_closures_unique {
17     pub fn e(x: &'static mut isize) {
18         static mut Y: isize = 3;
19         let mut c1 = |y: &'static mut isize| x = y;
20         //[migrate]~^ ERROR is not declared as mutable
21         //[nll]~^^ ERROR is not declared as mutable
22         unsafe { c1(&mut Y); }
23     }
24 }
25
26 mod borrowck_closures_unique_grandparent {
27     pub fn ee(x: &'static mut isize) {
28         static mut Z: isize = 3;
29         let mut c1 = |z: &'static mut isize| {
30             let mut c2 = |y: &'static mut isize| x = y;
31         //[migrate]~^ ERROR is not declared as mutable
32         //[nll]~^^ ERROR is not declared as mutable
33             c2(z);
34         };
35         unsafe { c1(&mut Z); }
36     }
37 }
38
39 // adapted from mutability_errors.rs
40 mod mutability_errors {
41     pub fn capture_assign_whole(x: (i32,)) {
42         || { x = (1,); };
43         //[migrate]~^ ERROR is not declared as mutable
44         //[nll]~^^ ERROR is not declared as mutable
45     }
46     pub fn capture_assign_part(x: (i32,)) {
47         || { x.0 = 1; };
48         //[migrate]~^ ERROR is not declared as mutable
49         //[nll]~^^ ERROR is not declared as mutable
50     }
51     pub fn capture_reborrow_whole(x: (i32,)) {
52         || { &mut x; };
53         //[migrate]~^ ERROR is not declared as mutable
54         //[nll]~^^ ERROR is not declared as mutable
55     }
56     pub fn capture_reborrow_part(x: (i32,)) {
57         || { &mut x.0; };
58         //[migrate]~^ ERROR is not declared as mutable
59         //[nll]~^^ ERROR is not declared as mutable
60     }
61 }
62
63 fn main() {
64     static mut X: isize = 2;
65     unsafe { borrowck_closures_unique::e(&mut X); }
66
67     mutability_errors::capture_assign_whole((1000,));
68     mutability_errors::capture_assign_part((2000,));
69     mutability_errors::capture_reborrow_whole((3000,));
70     mutability_errors::capture_reborrow_part((4000,));
71 }