@@ -74,6 +74,7 @@ use rustc_target::spec::abi;
7474use syntax:: ast:: { self , NodeId } ;
7575use syntax:: attr;
7676use syntax:: codemap:: MultiSpan ;
77+ use syntax:: edition:: Edition ;
7778use syntax:: feature_gate;
7879use syntax:: symbol:: { Symbol , keywords, InternedString } ;
7980use 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
0 commit comments