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.
5 // revisions: migrate nll
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.
10 // ignore-compare-mode-nll
12 //[nll]compile-flags: -Z borrowck=mir
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); }
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
35 unsafe { c1(&mut Z); }
39 // adapted from mutability_errors.rs
40 mod mutability_errors {
41 pub fn capture_assign_whole(x: (i32,)) {
43 //[migrate]~^ ERROR is not declared as mutable
44 //[nll]~^^ ERROR is not declared as mutable
46 pub fn capture_assign_part(x: (i32,)) {
48 //[migrate]~^ ERROR is not declared as mutable
49 //[nll]~^^ ERROR is not declared as mutable
51 pub fn capture_reborrow_whole(x: (i32,)) {
53 //[migrate]~^ ERROR is not declared as mutable
54 //[nll]~^^ ERROR is not declared as mutable
56 pub fn capture_reborrow_part(x: (i32,)) {
58 //[migrate]~^ ERROR is not declared as mutable
59 //[nll]~^^ ERROR is not declared as mutable
64 static mut X: isize = 2;
65 unsafe { borrowck_closures_unique::e(&mut X); }
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,));