Skip to content

Commit 78ec12d

Browse files
committed
Auto merge of #53045 - pnkfelix:issue-53026-migrate-never-looser-than-ast-borrowck, r=estebank
Fix NLL migration mode so that reports region errors when necessary. The code here was trying to be clever, and say "lets not report diagnostics when we 'know' NLL will report an error about them in the future." The problem is that in migration mode, when no error was reported here, the NLL error that we "knew" was coming was downgraded to a warning (!). Thus causing #53026 (I hope it is the only instance of such a scenario, but we will see.) Anyway, this PR fixes that by only doing the "clever" skipping of region error reporting when we are not in migration mode. As noted in the FIXME, I'm not really thrilled with this band-aid, but it is small enough to be back-ported easily if that is necessary. Rather than make a separate test for issue 53026, I just took the test that uncovered this in a first place, and extended it (via our revisions system) to explicitly show all three modes in action: AST-borrowck, NLL, and NLL migration mode. (To be honest I hope not to have to add such revisions to many tests. Instead I hope to adopt some sort of new `compare-mode` for either borrowck=migrate or for the 2018 edition as a whole.) Fix #53026
2 parents 7c98d2e + abd81c9 commit 78ec12d

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

src/librustc/infer/error_reporting/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
303303
) {
304304
debug!("report_region_errors(): {} errors to start", errors.len());
305305

306-
if will_later_be_reported_by_nll && self.tcx.use_mir_borrowck() {
306+
if will_later_be_reported_by_nll &&
307+
// FIXME: `use_mir_borrowck` seems wrong here...
308+
self.tcx.use_mir_borrowck() &&
309+
// ... this is a band-aid; may be better to explicitly
310+
// match on every borrowck_mode variant to guide decision
311+
// here.
312+
!self.tcx.migrate_borrowck() {
313+
307314
// With `#![feature(nll)]`, we want to present a nice user
308315
// experience, so don't even mention the errors from the
309316
// AST checker.

src/test/ui/borrowck/issue-45983.stderr renamed to src/test/ui/borrowck/issue-45983.ast.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: borrowed data cannot be stored outside of its closure
2-
--> $DIR/issue-45983.rs:17:27
2+
--> $DIR/issue-45983.rs:36:27
33
|
44
LL | let x = None;
55
| - borrowed data cannot be stored into here...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: borrowed data cannot be stored outside of its closure
2+
--> $DIR/issue-45983.rs:36:27
3+
|
4+
LL | let x = None;
5+
| - borrowed data cannot be stored into here...
6+
LL | give_any(|y| x = Some(y));
7+
| --- ^ cannot be stored outside of its closure
8+
| |
9+
| ...because it cannot outlive this closure
10+
11+
error: aborting due to previous error
12+

src/test/ui/borrowck/issue-45983.nll.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: not reporting region error due to nll
2-
--> $DIR/issue-45983.rs:17:27
2+
--> $DIR/issue-45983.rs:36:27
33
|
44
LL | give_any(|y| x = Some(y));
55
| ^
66

77
error: borrowed data escapes outside of closure
8-
--> $DIR/issue-45983.rs:17:18
8+
--> $DIR/issue-45983.rs:36:18
99
|
1010
LL | let x = None;
1111
| - `x` is declared here, outside of the closure body
@@ -15,7 +15,7 @@ LL | give_any(|y| x = Some(y));
1515
| `y` is a reference that is only valid in the closure body
1616

1717
error[E0594]: cannot assign to `x`, as it is not declared as mutable
18-
--> $DIR/issue-45983.rs:17:18
18+
--> $DIR/issue-45983.rs:36:18
1919
|
2020
LL | let x = None;
2121
| - help: consider changing this to be mutable: `mut x`

src/test/ui/borrowck/issue-45983.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,35 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// As documented in Issue #45983, this test is evaluating the quality
12+
// of our diagnostics on erroneous code using higher-ranked closures.
13+
//
14+
// However, as documented on Issue #53026, this test also became a
15+
// prime example of our need to test the NLL migration mode
16+
// *separately* from the existing test suites that focus solely on
17+
// AST-borrwock and NLL.
18+
19+
// revisions: ast migrate nll
20+
21+
// Since we are testing nll (and migration) explicitly as a separate
22+
// revisions, dont worry about the --compare-mode=nll on this test.
23+
24+
// ignore-compare-mode-nll
25+
26+
//[ast]compile-flags: -Z borrowck=ast
27+
//[migrate]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
28+
//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows
29+
1130
fn give_any<F: for<'r> FnOnce(&'r ())>(f: F) {
1231
f(&());
1332
}
1433

1534
fn main() {
1635
let x = None;
1736
give_any(|y| x = Some(y));
18-
//~^ ERROR borrowed data cannot be stored outside of its closure
37+
//[ast]~^ ERROR borrowed data cannot be stored outside of its closure
38+
//[migrate]~^^ ERROR borrowed data cannot be stored outside of its closure
39+
//[nll]~^^^ WARN not reporting region error due to nll
40+
//[nll]~| ERROR borrowed data escapes outside of closure
41+
//[nll]~| ERROR cannot assign to `x`, as it is not declared as mutable
1942
}

0 commit comments

Comments
 (0)