提交 1a59dafe 编写于 作者: F Felix S. Klock II

Bug fix: `#![feature(nll)]` takes precedence over `-Z borrowck=migrate`.

(Includes test illustrating desired behavior; compare its diagnostic
output to that of the file `borrowck-migreate-to-nll.rs`.)
上级 f8084053
......@@ -1405,9 +1405,11 @@ pub fn two_phase_borrows(self) -> bool {
pub fn borrowck_mode(&self) -> BorrowckMode {
match self.sess.opts.borrowck_mode {
mode @ BorrowckMode::Mir |
mode @ BorrowckMode::Migrate |
mode @ BorrowckMode::Compare => mode,
// `BorrowckMode::Ast` is synonymous with no `-Z
// borrowck=...` flag at all. Therefore, we definitely
// want `#![feature(nll)]` to override it.
mode @ BorrowckMode::Ast => {
if self.features().nll {
BorrowckMode::Mir
......@@ -1416,6 +1418,19 @@ pub fn borrowck_mode(&self) -> BorrowckMode {
}
}
// `BorrowckMode::Migrate` is modelling the behavior one
// will eventually specify via `--edition 2018`. 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.
mode @ BorrowckMode::Migrate => {
if self.features().nll {
BorrowckMode::Mir
} else {
mode
}
}
}
}
......
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This is a test that the `#![feature(nll)]` opt-in overrides the
// migration mode. The intention here is to emulate the goal behavior
// that `--edition 2018` effects on borrowck (modeled here by `-Z
// borrowck=migrate`) are themselves overridden by the
// `#![feature(nll)]` opt-in.
//
// Therefore, for developer convenience, under `#[feature(nll)]` the
// NLL checks will be emitted as errors *even* in the presence of `-Z
// borrowck=migrate`.
// compile-flags: -Z borrowck=migrate
#![feature(nll)]
fn main() {
match Some(&4) {
None => {},
ref mut foo
if {
(|| { let bar = foo; bar.take() })();
//~^ ERROR cannot move out of borrowed content [E0507]
false
} => {},
Some(ref _s) => println!("Note this arm is bogus; the `Some` became `None` in the guard."),
_ => println!("Here is some supposedly unreachable code."),
}
}
error[E0507]: cannot move out of borrowed content
--> $DIR/borrowck-feature-nll-overrides-migrate.rs:30:17
|
LL | (|| { let bar = foo; bar.take() })();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content
error: aborting due to previous error
For more information about this error, try `rustc --explain E0507`.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册