-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #55494 - pnkfelix:issue-55492-borrowck-migrate-must-l…
…ook-at-parents-of-closures, r=davidtwco borrowck=migrate must look at parents of closures This fixes the NLL migration mode (which is the default with edition=2018) to inspect all parents of a closure in addition to the closure itself when looking to see if AST-borrowck issues an error for the given code. This should be a candidate for beta backport. Fix #55492
- Loading branch information
Showing
11 changed files
with
269 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.ast.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
error[E0595]: closure cannot assign to immutable argument `x` | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:21:22 | ||
| | ||
LL | let mut c1 = |y: &'static mut isize| x = y; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow mutably | ||
help: consider removing the `&mut`, as it is an immutable binding to a mutable reference | ||
| | ||
LL | x | ||
| | ||
|
||
error[E0595]: closure cannot assign to immutable argument `x` | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:29:22 | ||
| | ||
LL | let mut c1 = |z: &'static mut isize| { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot borrow mutably | ||
help: consider removing the `&mut`, as it is an immutable binding to a mutable reference | ||
| | ||
LL | x | ||
| | ||
|
||
error[E0595]: closure cannot assign to immutable argument `x` | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:40:9 | ||
| | ||
LL | pub fn capture_assign_whole(x: (i32,)) { | ||
| - help: make this binding mutable: `mut x` | ||
LL | || { x = (1,); }; | ||
| ^^ cannot borrow mutably | ||
|
||
error[E0595]: closure cannot assign to immutable argument `x` | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:9 | ||
| | ||
LL | pub fn capture_assign_part(x: (i32,)) { | ||
| - help: make this binding mutable: `mut x` | ||
LL | || { x.0 = 1; }; | ||
| ^^ cannot borrow mutably | ||
|
||
error[E0595]: closure cannot assign to immutable argument `x` | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:46:9 | ||
| | ||
LL | pub fn capture_reborrow_whole(x: (i32,)) { | ||
| - help: make this binding mutable: `mut x` | ||
LL | || { &mut x; }; | ||
| ^^ cannot borrow mutably | ||
|
||
error[E0595]: closure cannot assign to immutable argument `x` | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:9 | ||
| | ||
LL | pub fn capture_reborrow_part(x: (i32,)) { | ||
| - help: make this binding mutable: `mut x` | ||
LL | || { &mut x.0; }; | ||
| ^^ cannot borrow mutably | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0595`. |
54 changes: 54 additions & 0 deletions
54
src/test/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.migrate.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
error[E0594]: cannot assign to `x`, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:21:46 | ||
| | ||
LL | pub fn e(x: &'static mut isize) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | static mut Y: isize = 3; | ||
LL | let mut c1 = |y: &'static mut isize| x = y; | ||
| ^^^^^ cannot assign | ||
|
||
error[E0594]: cannot assign to `x`, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:30:50 | ||
| | ||
LL | pub fn ee(x: &'static mut isize) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
... | ||
LL | let mut c2 = |y: &'static mut isize| x = y; | ||
| ^^^^^ cannot assign | ||
|
||
error[E0594]: cannot assign to `x`, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:40:14 | ||
| | ||
LL | pub fn capture_assign_whole(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { x = (1,); }; | ||
| ^^^^^^^^ cannot assign | ||
|
||
error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:14 | ||
| | ||
LL | pub fn capture_assign_part(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { x.0 = 1; }; | ||
| ^^^^^^^ cannot assign | ||
|
||
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:46:14 | ||
| | ||
LL | pub fn capture_reborrow_whole(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { &mut x; }; | ||
| ^^^^^^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:14 | ||
| | ||
LL | pub fn capture_reborrow_part(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { &mut x.0; }; | ||
| ^^^^^^^^ cannot borrow as mutable | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors occurred: E0594, E0596. | ||
For more information about an error, try `rustc --explain E0594`. |
54 changes: 54 additions & 0 deletions
54
src/test/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.nll.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
error[E0594]: cannot assign to `x`, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:21:46 | ||
| | ||
LL | pub fn e(x: &'static mut isize) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | static mut Y: isize = 3; | ||
LL | let mut c1 = |y: &'static mut isize| x = y; | ||
| ^^^^^ cannot assign | ||
|
||
error[E0594]: cannot assign to `x`, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:30:50 | ||
| | ||
LL | pub fn ee(x: &'static mut isize) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
... | ||
LL | let mut c2 = |y: &'static mut isize| x = y; | ||
| ^^^^^ cannot assign | ||
|
||
error[E0594]: cannot assign to `x`, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:40:14 | ||
| | ||
LL | pub fn capture_assign_whole(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { x = (1,); }; | ||
| ^^^^^^^^ cannot assign | ||
|
||
error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:14 | ||
| | ||
LL | pub fn capture_assign_part(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { x.0 = 1; }; | ||
| ^^^^^^^ cannot assign | ||
|
||
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:46:14 | ||
| | ||
LL | pub fn capture_reborrow_whole(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { &mut x; }; | ||
| ^^^^^^ cannot borrow as mutable | ||
|
||
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable | ||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:14 | ||
| | ||
LL | pub fn capture_reborrow_part(x: (i32,)) { | ||
| - help: consider changing this to be mutable: `mut x` | ||
LL | || { &mut x.0; }; | ||
| ^^^^^^^^ cannot borrow as mutable | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
Some errors occurred: E0594, E0596. | ||
For more information about an error, try `rustc --explain E0594`. |
61 changes: 61 additions & 0 deletions
61
src/test/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// rust-lang/rust#55492: errors detected during MIR-borrowck's | ||
// analysis of a closure body may only be caught when AST-borrowck | ||
// looks at some parent. | ||
|
||
// revisions: ast migrate nll | ||
|
||
// Since we are testing nll (and migration) explicitly as a separate | ||
// revisions, don't worry about the --compare-mode=nll on this test. | ||
|
||
// ignore-compare-mode-nll | ||
|
||
//[ast]compile-flags: -Z borrowck=ast | ||
//[migrate]compile-flags: -Z borrowck=migrate -Z two-phase-borrows | ||
//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows | ||
|
||
|
||
// transcribed from borrowck-closures-unique.rs | ||
mod borrowck_closures_unique { | ||
pub fn e(x: &'static mut isize) { | ||
static mut Y: isize = 3; | ||
let mut c1 = |y: &'static mut isize| x = y; | ||
unsafe { c1(&mut Y); } | ||
} | ||
} | ||
|
||
mod borrowck_closures_unique_grandparent { | ||
pub fn ee(x: &'static mut isize) { | ||
static mut Z: isize = 3; | ||
let mut c1 = |z: &'static mut isize| { | ||
let mut c2 = |y: &'static mut isize| x = y; | ||
c2(z); | ||
}; | ||
unsafe { c1(&mut Z); } | ||
} | ||
} | ||
|
||
// adapted from mutability_errors.rs | ||
mod mutability_errors { | ||
pub fn capture_assign_whole(x: (i32,)) { | ||
|| { x = (1,); }; | ||
} | ||
pub fn capture_assign_part(x: (i32,)) { | ||
|| { x.0 = 1; }; | ||
} | ||
pub fn capture_reborrow_whole(x: (i32,)) { | ||
|| { &mut x; }; | ||
} | ||
pub fn capture_reborrow_part(x: (i32,)) { | ||
|| { &mut x.0; }; | ||
} | ||
} | ||
|
||
fn main() { | ||
static mut X: isize = 2; | ||
unsafe { borrowck_closures_unique::e(&mut X); } | ||
|
||
mutability_errors::capture_assign_whole((1000,)); | ||
mutability_errors::capture_assign_part((2000,)); | ||
mutability_errors::capture_reborrow_whole((3000,)); | ||
mutability_errors::capture_reborrow_part((4000,)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.