Skip to content

Commit

Permalink
Auto merge of #55134 - davidtwco:issue-55118, r=pnkfelix
Browse files Browse the repository at this point in the history
NLL: change compare-mode=nll to use borrowck=migrate

Fixes #55118.

This PR is split into two parts:

The first commit is a minor change that fixes a flaw in the existing `borrowck=migrate` implementation whereby a lint that was promoted to an error in the AST borrow checker would result in the same lint from the NLL borrow checker being downgraded to a warning in migrate mode. This PR fixes this by ensuring lints are exempt from buffering in the NLL borrow checker.

The second commit updates `compiletest` to make the NLL compare mode use `-Z borrowck=migrate` rather than `-Z borrowck=mir`. The third commit shows all the test output changes that result from this.

r? @pnkfelix
  • Loading branch information
bors committed Oct 17, 2018
2 parents 1dceadd + 539404b commit f7eb7fb
Show file tree
Hide file tree
Showing 206 changed files with 928 additions and 2,966 deletions.
14 changes: 7 additions & 7 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,20 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
continue;
}

let mut err = tcx.struct_span_lint_node(
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
tcx.struct_span_lint_node(
UNUSED_MUT,
vsi[local_decl.source_info.scope].lint_root,
span,
"variable does not need to be mutable",
);
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
err.span_suggestion_short_with_applicability(
)
.span_suggestion_short_with_applicability(
mut_span,
"remove this `mut`",
String::new(),
Applicability::MachineApplicable);

err.buffer(&mut mbcx.errors_buffer);
Applicability::MachineApplicable,
)
.emit();
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/test/ui/access-mode-in-closures.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ note: move occurs because `v` has type `std::vec::Vec<isize>`, which does not im
LL | match *s { sty(v) => v } //~ ERROR cannot move out
| ^

error: aborting due to previous error
error[E0507]: cannot move out of `s.0` which is behind a `&` reference
--> $DIR/access-mode-in-closures.rs:19:24
|
LL | let _foo = unpack(|s| {
| - help: consider changing this to be a mutable reference: `&mut sty`
LL | // Test that `s` is moved here.
LL | match *s { sty(v) => v } //~ ERROR cannot move out
| ^
| |
| cannot move out of `s.0` which is behind a `&` reference
| `s` is a `&` reference, so the data it refers to cannot be moved

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0507`.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 13 additions & 1 deletion src/test/ui/binop/binop-move-semantics.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ error[E0507]: cannot move out of borrowed content
LL | *n; //~ ERROR: cannot move out of borrowed content
| ^^ cannot move out of borrowed content

error[E0507]: cannot move out of `*n` which is behind a `&` reference
--> $DIR/binop-move-semantics.rs:42:5
|
LL | let n = &y;
| -- help: consider changing this to be a mutable reference: `&mut y`
...
LL | *n; //~ ERROR: cannot move out of borrowed content
| ^^
| |
| cannot move out of `*n` which is behind a `&` reference
| `n` is a `&` reference, so the data it refers to cannot be moved

error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable
--> $DIR/binop-move-semantics.rs:64:5
|
Expand Down Expand Up @@ -62,7 +74,7 @@ LL | | &mut f; //~ ERROR: cannot borrow `f` as mutable because it is also b
| | immutable borrow later used here
| mutable borrow occurs here

error: aborting due to 6 previous errors
error: aborting due to 7 previous errors

Some errors occurred: E0382, E0502, E0507.
For more information about an error, try `rustc --explain E0382`.
8 changes: 6 additions & 2 deletions src/test/ui/borrowck/borrowck-closures-unique.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@ LL | let c2 = || set(x); //~ ERROR two closures require unique access to `x`
LL | c1;
| -- first borrow later used here

error[E0594]: cannot assign to `x`, as it is not declared as mutable
warning[E0594]: cannot assign to `x`, as it is not declared as mutable
--> $DIR/borrowck-closures-unique.rs:57:38
|
LL | fn e(x: &'static mut isize) {
| - help: consider changing this to be mutable: `mut x`
LL | let c1 = |y: &'static mut isize| x = y; //~ ERROR closure cannot assign to immutable argument
| ^^^^^ cannot assign
|
= warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

Some errors occurred: E0500, E0524, E0594.
For more information about an error, try `rustc --explain E0500`.
19 changes: 15 additions & 4 deletions src/test/ui/borrowck/borrowck-describe-lvalue.ast.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL | //[mir]~^ ERROR cannot borrow `x` as mutable more than o
LL | *y = 1;
| ------ first borrow later used here

error: captured variable cannot escape `FnMut` closure body
warning: captured variable cannot escape `FnMut` closure body
--> $DIR/borrowck-describe-lvalue.rs:305:16
|
LL | || {
Expand All @@ -36,6 +36,9 @@ LL | | }
|
= note: `FnMut` closures only have access to their captured variables while they are executing...
= note: ...therefore, they cannot allow references to captured variables to escape
= warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

error[E0503]: cannot use `f.x` because it was mutably borrowed
--> $DIR/borrowck-describe-lvalue.rs:53:9
Expand Down Expand Up @@ -339,7 +342,7 @@ LL | &[_, F {x: ref xf, ..}] => println!("{}", xf),
LL | drop(x);
| - mutable borrow later used here

error[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
warning[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-describe-lvalue.rs:245:29
|
LL | let x = &mut block;
Expand All @@ -349,8 +352,12 @@ LL | let p: &'a u8 = &*block.current;
...
LL | drop(x);
| - mutable borrow later used here
|
= warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

error[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
warning[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-describe-lvalue.rs:260:33
|
LL | let x = &mut block;
Expand All @@ -360,6 +367,10 @@ LL | let p : *const u8 = &*(*block).current;
...
LL | drop(x);
| - mutable borrow later used here
|
= warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

error[E0382]: use of moved value: `x`
--> $DIR/borrowck-describe-lvalue.rs:318:22
Expand All @@ -371,7 +382,7 @@ LL | drop(x); //[ast]~ ERROR use of moved value: `x`
|
= note: move occurs because `x` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait

error: aborting due to 32 previous errors
error: aborting due to 29 previous errors

Some errors occurred: E0382, E0499, E0502, E0503.
For more information about an error, try `rustc --explain E0382`.
20 changes: 20 additions & 0 deletions src/test/ui/borrowck/borrowck-fn-in-const-a.ast.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0507]: cannot move out of borrowed content
--> $DIR/borrowck-fn-in-const-a.rs:19:16
|
LL | return *x //[ast]~ ERROR cannot move out of borrowed content [E0507]
| ^^ cannot move out of borrowed content

error[E0507]: cannot move out of `*x` which is behind a `&` reference
--> $DIR/borrowck-fn-in-const-a.rs:19:16
|
LL | fn broken(x: &String) -> String {
| ------- help: consider changing this to be a mutable reference: `&mut std::string::String`
LL | return *x //[ast]~ ERROR cannot move out of borrowed content [E0507]
| ^^
| |
| cannot move out of `*x` which is behind a `&` reference
| `x` is a `&` reference, so the data it refers to cannot be moved

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0507`.
Loading

0 comments on commit f7eb7fb

Please sign in to comment.