Skip to content

Commit d5798c9

Browse files
committed
Regression test for issue 55492.
1 parent 98c9a3e commit d5798c9

4 files changed

+224
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error[E0595]: closure cannot assign to immutable argument `x`
2+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:21:22
3+
|
4+
LL | let mut c1 = |y: &'static mut isize| x = y;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow mutably
6+
help: consider removing the `&mut`, as it is an immutable binding to a mutable reference
7+
|
8+
LL | x
9+
|
10+
11+
error[E0595]: closure cannot assign to immutable argument `x`
12+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:29:22
13+
|
14+
LL | let mut c1 = |z: &'static mut isize| {
15+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow mutably
16+
help: consider removing the `&mut`, as it is an immutable binding to a mutable reference
17+
|
18+
LL | x
19+
|
20+
21+
error[E0595]: closure cannot assign to immutable argument `x`
22+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:40:9
23+
|
24+
LL | pub fn capture_assign_whole(x: (i32,)) {
25+
| - help: make this binding mutable: `mut x`
26+
LL | || { x = (1,); };
27+
| ^^ cannot borrow mutably
28+
29+
error[E0595]: closure cannot assign to immutable argument `x`
30+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:9
31+
|
32+
LL | pub fn capture_assign_part(x: (i32,)) {
33+
| - help: make this binding mutable: `mut x`
34+
LL | || { x.0 = 1; };
35+
| ^^ cannot borrow mutably
36+
37+
error[E0595]: closure cannot assign to immutable argument `x`
38+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:46:9
39+
|
40+
LL | pub fn capture_reborrow_whole(x: (i32,)) {
41+
| - help: make this binding mutable: `mut x`
42+
LL | || { &mut x; };
43+
| ^^ cannot borrow mutably
44+
45+
error[E0595]: closure cannot assign to immutable argument `x`
46+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:9
47+
|
48+
LL | pub fn capture_reborrow_part(x: (i32,)) {
49+
| - help: make this binding mutable: `mut x`
50+
LL | || { &mut x.0; };
51+
| ^^ cannot borrow mutably
52+
53+
error: aborting due to 6 previous errors
54+
55+
For more information about this error, try `rustc --explain E0595`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
2+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:21:46
3+
|
4+
LL | pub fn e(x: &'static mut isize) {
5+
| - help: consider changing this to be mutable: `mut x`
6+
LL | static mut Y: isize = 3;
7+
LL | let mut c1 = |y: &'static mut isize| x = y;
8+
| ^^^^^ cannot assign
9+
10+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
11+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:30:50
12+
|
13+
LL | pub fn ee(x: &'static mut isize) {
14+
| - help: consider changing this to be mutable: `mut x`
15+
...
16+
LL | let mut c2 = |y: &'static mut isize| x = y;
17+
| ^^^^^ cannot assign
18+
19+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
20+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:40:14
21+
|
22+
LL | pub fn capture_assign_whole(x: (i32,)) {
23+
| - help: consider changing this to be mutable: `mut x`
24+
LL | || { x = (1,); };
25+
| ^^^^^^^^ cannot assign
26+
27+
error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
28+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:14
29+
|
30+
LL | pub fn capture_assign_part(x: (i32,)) {
31+
| - help: consider changing this to be mutable: `mut x`
32+
LL | || { x.0 = 1; };
33+
| ^^^^^^^ cannot assign
34+
35+
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
36+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:46:14
37+
|
38+
LL | pub fn capture_reborrow_whole(x: (i32,)) {
39+
| - help: consider changing this to be mutable: `mut x`
40+
LL | || { &mut x; };
41+
| ^^^^^^ cannot borrow as mutable
42+
43+
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
44+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:14
45+
|
46+
LL | pub fn capture_reborrow_part(x: (i32,)) {
47+
| - help: consider changing this to be mutable: `mut x`
48+
LL | || { &mut x.0; };
49+
| ^^^^^^^^ cannot borrow as mutable
50+
51+
error: aborting due to 6 previous errors
52+
53+
Some errors occurred: E0594, E0596.
54+
For more information about an error, try `rustc --explain E0594`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
2+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:21:46
3+
|
4+
LL | pub fn e(x: &'static mut isize) {
5+
| - help: consider changing this to be mutable: `mut x`
6+
LL | static mut Y: isize = 3;
7+
LL | let mut c1 = |y: &'static mut isize| x = y;
8+
| ^^^^^ cannot assign
9+
10+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
11+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:30:50
12+
|
13+
LL | pub fn ee(x: &'static mut isize) {
14+
| - help: consider changing this to be mutable: `mut x`
15+
...
16+
LL | let mut c2 = |y: &'static mut isize| x = y;
17+
| ^^^^^ cannot assign
18+
19+
error[E0594]: cannot assign to `x`, as it is not declared as mutable
20+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:40:14
21+
|
22+
LL | pub fn capture_assign_whole(x: (i32,)) {
23+
| - help: consider changing this to be mutable: `mut x`
24+
LL | || { x = (1,); };
25+
| ^^^^^^^^ cannot assign
26+
27+
error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
28+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:14
29+
|
30+
LL | pub fn capture_assign_part(x: (i32,)) {
31+
| - help: consider changing this to be mutable: `mut x`
32+
LL | || { x.0 = 1; };
33+
| ^^^^^^^ cannot assign
34+
35+
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
36+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:46:14
37+
|
38+
LL | pub fn capture_reborrow_whole(x: (i32,)) {
39+
| - help: consider changing this to be mutable: `mut x`
40+
LL | || { &mut x; };
41+
| ^^^^^^ cannot borrow as mutable
42+
43+
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
44+
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:14
45+
|
46+
LL | pub fn capture_reborrow_part(x: (i32,)) {
47+
| - help: consider changing this to be mutable: `mut x`
48+
LL | || { &mut x.0; };
49+
| ^^^^^^^^ cannot borrow as mutable
50+
51+
error: aborting due to 6 previous errors
52+
53+
Some errors occurred: E0594, E0596.
54+
For more information about an error, try `rustc --explain E0594`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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: ast 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+
//[ast]compile-flags: -Z borrowck=ast
13+
//[migrate]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
14+
//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows
15+
16+
17+
// transcribed from borrowck-closures-unique.rs
18+
mod borrowck_closures_unique {
19+
pub fn e(x: &'static mut isize) {
20+
static mut Y: isize = 3;
21+
let mut c1 = |y: &'static mut isize| x = y;
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+
c2(z);
32+
};
33+
unsafe { c1(&mut Z); }
34+
}
35+
}
36+
37+
// adapted from mutability_errors.rs
38+
mod mutability_errors {
39+
pub fn capture_assign_whole(x: (i32,)) {
40+
|| { x = (1,); };
41+
}
42+
pub fn capture_assign_part(x: (i32,)) {
43+
|| { x.0 = 1; };
44+
}
45+
pub fn capture_reborrow_whole(x: (i32,)) {
46+
|| { &mut x; };
47+
}
48+
pub fn capture_reborrow_part(x: (i32,)) {
49+
|| { &mut x.0; };
50+
}
51+
}
52+
53+
fn main() {
54+
static mut X: isize = 2;
55+
unsafe { borrowck_closures_unique::e(&mut X); }
56+
57+
mutability_errors::capture_assign_whole((1000,));
58+
mutability_errors::capture_assign_part((2000,));
59+
mutability_errors::capture_reborrow_whole((3000,));
60+
mutability_errors::capture_reborrow_part((4000,));
61+
}

0 commit comments

Comments
 (0)