Skip to content

Commit 4b2e553

Browse files
committed
integrate the edition code.
As a driveby change, I made `#![feature(nll)]` *always* take precedence over `-Z borrowck`. The main effect this had is that it means tests with `#![feature(nll)]` will ignore uses of `-Z borrowck=compare`. This affected only one test as far as I can tell, and I think that test used `-Z borrowck=compare` only as a historical accident.
1 parent 1a59daf commit 4b2e553

File tree

3 files changed

+52
-54
lines changed

3 files changed

+52
-54
lines changed

src/librustc/ty/context.rs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ use rustc_target::spec::abi;
7474
use syntax::ast::{self, NodeId};
7575
use syntax::attr;
7676
use syntax::codemap::MultiSpan;
77+
use syntax::edition::Edition;
7778
use syntax::feature_gate;
7879
use syntax::symbol::{Symbol, keywords, InternedString};
7980
use syntax_pos::Span;
@@ -1403,34 +1404,51 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14031404
/// What mode(s) of borrowck should we run? AST? MIR? both?
14041405
/// (Also considers the `#![feature(nll)]` setting.)
14051406
pub fn borrowck_mode(&self) -> BorrowckMode {
1407+
// Here are the main constraints we need to deal with:
1408+
//
1409+
// 1. An opts.borrowck_mode of `BorrowckMode::Ast` is
1410+
// synonymous with no `-Z borrowck=...` flag at all.
1411+
// (This is arguably a historical accident.)
1412+
//
1413+
// 2. `BorrowckMode::Migrate` is the limited migration to
1414+
// NLL that we are deploying with the 2018 edition.
1415+
//
1416+
// 3. We want to allow developers on the Nightly channel
1417+
// to opt back into the "hard error" mode for NLL,
1418+
// (which they can do via specifying `#![feature(nll)]`
1419+
// explicitly in their crate).
1420+
//
1421+
// So, this precedence list is how pnkfelix chose to work with
1422+
// the above constraints:
1423+
//
1424+
// * `#![feature(nll)]` *always* means use NLL with hard
1425+
// errors. (To simplify the code here, it now even overrides
1426+
// a user's attempt to specify `-Z borrowck=compare`, which
1427+
// we arguably do not need anymore and should remove.)
1428+
//
1429+
// * Otherwise, if no `-Z borrowck=...` flag was given (or
1430+
// if `borrowck=ast` was specified), then use the default
1431+
// as required by the edition.
1432+
//
1433+
// * Otherwise, use the behavior requested via `-Z borrowck=...`
1434+
1435+
if self.features().nll { return BorrowckMode::Mir; }
1436+
14061437
match self.sess.opts.borrowck_mode {
14071438
mode @ BorrowckMode::Mir |
1408-
mode @ BorrowckMode::Compare => mode,
1409-
1410-
// `BorrowckMode::Ast` is synonymous with no `-Z
1411-
// borrowck=...` flag at all. Therefore, we definitely
1412-
// want `#![feature(nll)]` to override it.
1413-
mode @ BorrowckMode::Ast => {
1414-
if self.features().nll {
1415-
BorrowckMode::Mir
1416-
} else {
1417-
mode
1418-
}
1419-
}
1420-
1421-
// `BorrowckMode::Migrate` is modelling the behavior one
1422-
// will eventually specify via `--edition 2018`. We want
1423-
// to allow developers on the Nightly channel to opt back
1424-
// into the "hard error" mode for NLL, which they can do
1425-
// via specifying `#![feature(nll)]` explicitly in their
1426-
// crate.
1427-
mode @ BorrowckMode::Migrate => {
1428-
if self.features().nll {
1429-
BorrowckMode::Mir
1430-
} else {
1431-
mode
1432-
}
1433-
}
1439+
mode @ BorrowckMode::Compare |
1440+
mode @ BorrowckMode::Migrate => mode,
1441+
1442+
BorrowckMode::Ast => match self.sess.edition() {
1443+
Edition::Edition2015 => BorrowckMode::Ast,
1444+
Edition::Edition2018 => BorrowckMode::Migrate,
1445+
1446+
// For now, future editions mean Migrate. (But it
1447+
// would make a lot of sense for it to be changed to
1448+
// `BorrowckMode::Mir`, depending on how we plan to
1449+
// time the forcing of full migration to NLL.)
1450+
_ => BorrowckMode::Migrate,
1451+
},
14341452
}
14351453
}
14361454

src/test/ui/generator/generator-with-nll.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -Z borrowck=compare
12-
1311
#![feature(generators)]
1412
#![feature(nll)]
1513

1614
fn main() {
1715
|| {
1816
// The reference in `_a` is a Legal with NLL since it ends before the yield
19-
let _a = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
20-
let b = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
21-
//~^ borrow may still be in use when generator yields (Mir)
17+
let _a = &mut true;
18+
let b = &mut true;
19+
//~^ borrow may still be in use when generator yields
2220
yield ();
2321
println!("{}", b);
2422
};
Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
1-
error[E0626]: borrow may still be in use when generator yields (Ast)
2-
--> $DIR/generator-with-nll.rs:19:23
1+
error[E0626]: borrow may still be in use when generator yields
2+
--> $DIR/generator-with-nll.rs:18:17
33
|
4-
LL | let _a = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
5-
| ^^^^
6-
...
7-
LL | yield ();
8-
| -------- possible yield occurs here
9-
10-
error[E0626]: borrow may still be in use when generator yields (Ast)
11-
--> $DIR/generator-with-nll.rs:20:22
12-
|
13-
LL | let b = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
14-
| ^^^^
15-
LL | //~^ borrow may still be in use when generator yields (Mir)
16-
LL | yield ();
17-
| -------- possible yield occurs here
18-
19-
error[E0626]: borrow may still be in use when generator yields (Mir)
20-
--> $DIR/generator-with-nll.rs:20:17
21-
|
22-
LL | let b = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
4+
LL | let b = &mut true;
235
| ^^^^^^^^^
24-
LL | //~^ borrow may still be in use when generator yields (Mir)
6+
LL | //~^ borrow may still be in use when generator yields
257
LL | yield ();
268
| -------- possible yield occurs here
279

28-
error: aborting due to 3 previous errors
10+
error: aborting due to previous error
2911

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

0 commit comments

Comments
 (0)