Skip to content

Commit 827cb0d

Browse files
committed
Auto merge of #46106 - est31:master, r=nikomatsakis
Add a MIR-borrowck-only output mode Removes the `-Z borrowck-mir` flag in favour of a `-Z borrowck=mode` flag where mode can be `mir`, `ast`, or `compare`. * The `ast` mode represents the current default, passing `-Z borrowck=ast` is equivalent to not passing it at all. * The `compare` mode outputs both the output of the MIR borrow checker and the AST borrow checker, each error with `(Ast)` and `(Mir)` appended. This mode has the same behaviour as `-Z borrowck-mir` had before this commit. * The `mir` mode only outputs the results of the MIR borrow checker, while suppressing the errors of the ast borrow checker The PR also updates the tests to use the new flags. closes #46097
2 parents 71b21ed + d791798 commit 827cb0d

File tree

62 files changed

+354
-373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+354
-373
lines changed

src/librustc/session/config.rs

+42-2
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 borrowck 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

+1-1
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

+11
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

+1-1
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)