Skip to content

Commit c9af68e

Browse files
committed
Replace -Zborrowck-mir with -Zborrowck=mode
where mode is one of {ast,mir,compare}. This commit only implements the functionality. The tests will be updated in a follow up commit.
1 parent 2ca00a9 commit c9af68e

File tree

5 files changed

+160
-53
lines changed

5 files changed

+160
-53
lines changed

src/librustc/session/config.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ top_level_options!(
362362

363363
debugging_opts: DebuggingOptions [TRACKED],
364364
prints: Vec<PrintRequest> [UNTRACKED],
365+
// Determines which borrow checker(s) to run. This is the parsed, sanitized
366+
// version of `debugging_opts.borrowck`, which is just a plain string.
367+
borrowck_mode: BorrowckMode [UNTRACKED],
365368
cg: CodegenOptions [TRACKED],
366369
// FIXME(mw): We track this for now but it actually doesn't make too
367370
// much sense: The value of this option can stay the same
@@ -401,6 +404,32 @@ pub enum PrintRequest {
401404
NativeStaticLibs,
402405
}
403406

407+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
408+
pub enum BorrowckMode {
409+
Ast,
410+
Mir,
411+
Compare,
412+
}
413+
414+
impl BorrowckMode {
415+
/// Should we emit the AST-based borrow checker errors?
416+
pub fn use_ast(self) -> bool {
417+
match self {
418+
BorrowckMode::Ast => true,
419+
BorrowckMode::Compare => true,
420+
BorrowckMode::Mir => false,
421+
}
422+
}
423+
/// Should we emit the MIR-based borrow checker errors?
424+
pub fn use_mir(self) -> bool {
425+
match self {
426+
BorrowckMode::Ast => false,
427+
BorrowckMode::Compare => true,
428+
BorrowckMode::Mir => true,
429+
}
430+
}
431+
}
432+
404433
pub enum Input {
405434
/// Load source from file
406435
File(PathBuf),
@@ -526,6 +555,7 @@ pub fn basic_options() -> Options {
526555
incremental: None,
527556
debugging_opts: basic_debugging_options(),
528557
prints: Vec::new(),
558+
borrowck_mode: BorrowckMode::Ast,
529559
cg: basic_codegen_options(),
530560
error_format: ErrorOutputType::default(),
531561
externs: Externs(BTreeMap::new()),
@@ -973,8 +1003,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
9731003
"make unnamed regions display as '# (where # is some non-ident unique id)"),
9741004
emit_end_regions: bool = (false, parse_bool, [UNTRACKED],
9751005
"emit EndRegion as part of MIR; enable transforms that solely process EndRegion"),
976-
borrowck_mir: bool = (false, parse_bool, [UNTRACKED],
977-
"implicitly treat functions as if they have `#[rustc_mir_borrowck]` attribute"),
1006+
borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED],
1007+
"select which borrowck is used (`ast`, `mir`, or `compare`)"),
9781008
time_passes: bool = (false, parse_bool, [UNTRACKED],
9791009
"measure time of each rustc pass"),
9801010
count_llvm_insns: bool = (false, parse_bool,
@@ -1743,6 +1773,15 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17431773
}
17441774
}));
17451775

1776+
let borrowck_mode = match debugging_opts.borrowck.as_ref().map(|s| &s[..]) {
1777+
None | Some("ast") => BorrowckMode::Ast,
1778+
Some("mir") => BorrowckMode::Mir,
1779+
Some("compare") => BorrowckMode::Compare,
1780+
Some(m) => {
1781+
early_error(error_format, &format!("unknown borrowchk mode `{}`", m))
1782+
},
1783+
};
1784+
17461785
if !cg.remark.is_empty() && debuginfo == NoDebugInfo {
17471786
early_warn(error_format, "-C remark will not show source locations without \
17481787
--debuginfo");
@@ -1784,6 +1823,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17841823
incremental,
17851824
debugging_opts,
17861825
prints,
1826+
borrowck_mode,
17871827
cg,
17881828
error_format,
17891829
externs: Externs(externs),

src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl Session {
416416
pub fn emit_end_regions(&self) -> bool {
417417
self.opts.debugging_opts.emit_end_regions ||
418418
(self.opts.debugging_opts.mir_emit_validate > 0) ||
419-
self.opts.debugging_opts.borrowck_mir
419+
self.opts.borrowck_mode.use_mir()
420420
}
421421
pub fn lto(&self) -> bool {
422422
self.opts.cg.lto || self.target.target.options.requires_lto

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ impl<'b, 'tcx: 'b> BorrowckErrors for BorrowckCtxt<'b, 'tcx> {
269269
{
270270
self.tcx.sess.struct_span_err(sp, msg)
271271
}
272+
273+
fn cancel_if_wrong_origin<'a>(&'a self,
274+
mut diag: DiagnosticBuilder<'a>,
275+
o: Origin)
276+
-> DiagnosticBuilder<'a>
277+
{
278+
if !o.should_emit_errors(self.tcx.sess.opts.borrowck_mode) {
279+
self.tcx.sess.diagnostic().cancel(&mut diag);
280+
}
281+
diag
282+
}
272283
}
273284

274285
///////////////////////////////////////////////////////////////////////////

src/librustc_mir/borrow_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
5454

5555
if {
5656
!tcx.has_attr(def_id, "rustc_mir_borrowck") &&
57-
!tcx.sess.opts.debugging_opts.borrowck_mir &&
57+
!tcx.sess.opts.borrowck_mode.use_mir() &&
5858
!tcx.sess.opts.debugging_opts.nll
5959
} {
6060
return;

0 commit comments

Comments
 (0)