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.
This commit is contained in:
parent
1a59dafe11
commit
4b2e553dac
@ -74,6 +74,7 @@ use rustc_target::spec::abi;
|
|||||||
use syntax::ast::{self, NodeId};
|
use syntax::ast::{self, NodeId};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::codemap::MultiSpan;
|
use syntax::codemap::MultiSpan;
|
||||||
|
use syntax::edition::Edition;
|
||||||
use syntax::feature_gate;
|
use syntax::feature_gate;
|
||||||
use syntax::symbol::{Symbol, keywords, InternedString};
|
use syntax::symbol::{Symbol, keywords, InternedString};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
@ -1403,34 +1404,51 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
/// What mode(s) of borrowck should we run? AST? MIR? both?
|
/// What mode(s) of borrowck should we run? AST? MIR? both?
|
||||||
/// (Also considers the `#![feature(nll)]` setting.)
|
/// (Also considers the `#![feature(nll)]` setting.)
|
||||||
pub fn borrowck_mode(&self) -> BorrowckMode {
|
pub fn borrowck_mode(&self) -> BorrowckMode {
|
||||||
|
// Here are the main constraints we need to deal with:
|
||||||
|
//
|
||||||
|
// 1. An opts.borrowck_mode of `BorrowckMode::Ast` is
|
||||||
|
// synonymous with no `-Z borrowck=...` flag at all.
|
||||||
|
// (This is arguably a historical accident.)
|
||||||
|
//
|
||||||
|
// 2. `BorrowckMode::Migrate` is the limited migration to
|
||||||
|
// NLL that we are deploying with the 2018 edition.
|
||||||
|
//
|
||||||
|
// 3. We want to allow developers on the Nightly channel
|
||||||
|
// to opt back into the "hard error" mode for NLL,
|
||||||
|
// (which they can do via specifying `#![feature(nll)]`
|
||||||
|
// explicitly in their crate).
|
||||||
|
//
|
||||||
|
// So, this precedence list is how pnkfelix chose to work with
|
||||||
|
// the above constraints:
|
||||||
|
//
|
||||||
|
// * `#![feature(nll)]` *always* means use NLL with hard
|
||||||
|
// errors. (To simplify the code here, it now even overrides
|
||||||
|
// a user's attempt to specify `-Z borrowck=compare`, which
|
||||||
|
// we arguably do not need anymore and should remove.)
|
||||||
|
//
|
||||||
|
// * Otherwise, if no `-Z borrowck=...` flag was given (or
|
||||||
|
// if `borrowck=ast` was specified), then use the default
|
||||||
|
// as required by the edition.
|
||||||
|
//
|
||||||
|
// * Otherwise, use the behavior requested via `-Z borrowck=...`
|
||||||
|
|
||||||
|
if self.features().nll { return BorrowckMode::Mir; }
|
||||||
|
|
||||||
match self.sess.opts.borrowck_mode {
|
match self.sess.opts.borrowck_mode {
|
||||||
mode @ BorrowckMode::Mir |
|
mode @ BorrowckMode::Mir |
|
||||||
mode @ BorrowckMode::Compare => mode,
|
mode @ BorrowckMode::Compare |
|
||||||
|
mode @ BorrowckMode::Migrate => mode,
|
||||||
|
|
||||||
// `BorrowckMode::Ast` is synonymous with no `-Z
|
BorrowckMode::Ast => match self.sess.edition() {
|
||||||
// borrowck=...` flag at all. Therefore, we definitely
|
Edition::Edition2015 => BorrowckMode::Ast,
|
||||||
// want `#![feature(nll)]` to override it.
|
Edition::Edition2018 => BorrowckMode::Migrate,
|
||||||
mode @ BorrowckMode::Ast => {
|
|
||||||
if self.features().nll {
|
|
||||||
BorrowckMode::Mir
|
|
||||||
} else {
|
|
||||||
mode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// `BorrowckMode::Migrate` is modelling the behavior one
|
// For now, future editions mean Migrate. (But it
|
||||||
// will eventually specify via `--edition 2018`. We want
|
// would make a lot of sense for it to be changed to
|
||||||
// to allow developers on the Nightly channel to opt back
|
// `BorrowckMode::Mir`, depending on how we plan to
|
||||||
// into the "hard error" mode for NLL, which they can do
|
// time the forcing of full migration to NLL.)
|
||||||
// via specifying `#![feature(nll)]` explicitly in their
|
_ => BorrowckMode::Migrate,
|
||||||
// crate.
|
},
|
||||||
mode @ BorrowckMode::Migrate => {
|
|
||||||
if self.features().nll {
|
|
||||||
BorrowckMode::Mir
|
|
||||||
} else {
|
|
||||||
mode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,17 +8,15 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// compile-flags: -Z borrowck=compare
|
|
||||||
|
|
||||||
#![feature(generators)]
|
#![feature(generators)]
|
||||||
#![feature(nll)]
|
#![feature(nll)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|| {
|
|| {
|
||||||
// The reference in `_a` is a Legal with NLL since it ends before the yield
|
// The reference in `_a` is a Legal with NLL since it ends before the yield
|
||||||
let _a = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
|
let _a = &mut true;
|
||||||
let b = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
|
let b = &mut true;
|
||||||
//~^ borrow may still be in use when generator yields (Mir)
|
//~^ borrow may still be in use when generator yields
|
||||||
yield ();
|
yield ();
|
||||||
println!("{}", b);
|
println!("{}", b);
|
||||||
};
|
};
|
||||||
|
@ -1,30 +1,12 @@
|
|||||||
error[E0626]: borrow may still be in use when generator yields (Ast)
|
error[E0626]: borrow may still be in use when generator yields
|
||||||
--> $DIR/generator-with-nll.rs:19:23
|
--> $DIR/generator-with-nll.rs:18:17
|
||||||
|
|
|
|
||||||
LL | let _a = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
|
LL | let b = &mut true;
|
||||||
| ^^^^
|
|
||||||
...
|
|
||||||
LL | yield ();
|
|
||||||
| -------- possible yield occurs here
|
|
||||||
|
|
||||||
error[E0626]: borrow may still be in use when generator yields (Ast)
|
|
||||||
--> $DIR/generator-with-nll.rs:20:22
|
|
||||||
|
|
|
||||||
LL | let b = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
|
|
||||||
| ^^^^
|
|
||||||
LL | //~^ borrow may still be in use when generator yields (Mir)
|
|
||||||
LL | yield ();
|
|
||||||
| -------- possible yield occurs here
|
|
||||||
|
|
||||||
error[E0626]: borrow may still be in use when generator yields (Mir)
|
|
||||||
--> $DIR/generator-with-nll.rs:20:17
|
|
||||||
|
|
|
||||||
LL | let b = &mut true; //~ ERROR borrow may still be in use when generator yields (Ast)
|
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
LL | //~^ borrow may still be in use when generator yields (Mir)
|
LL | //~^ borrow may still be in use when generator yields
|
||||||
LL | yield ();
|
LL | yield ();
|
||||||
| -------- possible yield occurs here
|
| -------- possible yield occurs here
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0626`.
|
For more information about this error, try `rustc --explain E0626`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user