Skip to content

Commit cfa4ffa

Browse files
committed
document and tweak the nll, use_mir, etc helpers
In particular, -Znll might as well imply -Zborrowck=mir by default, just like `#![feature(nll)]` does. Also, if NLL is in use, no reason to emit end regions. The NLL pass just strips them out anyway.
1 parent e980fb8 commit cfa4ffa

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/librustc/session/mod.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,25 +437,42 @@ impl Session {
437437
pub fn print_llvm_passes(&self) -> bool {
438438
self.opts.debugging_opts.print_llvm_passes
439439
}
440+
441+
/// If true, we should use NLL-style region checking instead of
442+
/// lexical style.
440443
pub fn nll(&self) -> bool {
441444
self.features.borrow().nll || self.opts.debugging_opts.nll
442445
}
446+
447+
/// If true, we should use the MIR-based borrowck (we may *also* use
448+
/// the AST-based borrowck).
443449
pub fn use_mir(&self) -> bool {
444-
self.features.borrow().nll || self.opts.borrowck_mode.use_mir()
450+
self.borrowck_mode().use_mir()
445451
}
452+
453+
/// If true, we should gather causal information during NLL
454+
/// checking. This will eventually be the normal thing, but right
455+
/// now it is too unoptimized.
446456
pub fn nll_dump_cause(&self) -> bool {
447457
self.opts.debugging_opts.nll_dump_cause
448458
}
459+
460+
/// If true, we should enable two-phase borrows checks. This is
461+
/// done with either `-Ztwo-phase-borrows` or with
462+
/// `#![feature(nll)]`.
449463
pub fn two_phase_borrows(&self) -> bool {
450464
self.features.borrow().nll || self.opts.debugging_opts.two_phase_borrows
451465
}
466+
467+
/// What mode(s) of borrowck should we run? AST? MIR? both?
468+
/// (Also considers the `#![feature(nll)]` setting.)
452469
pub fn borrowck_mode(&self) -> BorrowckMode {
453470
match self.opts.borrowck_mode {
454471
mode @ BorrowckMode::Mir |
455472
mode @ BorrowckMode::Compare => mode,
456473

457474
mode @ BorrowckMode::Ast => {
458-
if self.features.borrow().nll {
475+
if self.nll() {
459476
BorrowckMode::Mir
460477
} else {
461478
mode
@@ -464,11 +481,18 @@ impl Session {
464481

465482
}
466483
}
484+
485+
/// Should we emit EndRegion MIR statements? These are consumed by
486+
/// MIR borrowck, but not when NLL is used. They are also consumed
487+
/// by the validation stuff.
467488
pub fn emit_end_regions(&self) -> bool {
489+
// FIXME(#46875) -- we should not emit end regions when NLL is enabled,
490+
// but for now we can't stop doing so because it causes false positives
468491
self.opts.debugging_opts.emit_end_regions ||
469-
(self.opts.debugging_opts.mir_emit_validate > 0) ||
492+
self.opts.debugging_opts.mir_emit_validate > 0 ||
470493
self.use_mir()
471494
}
495+
472496
pub fn lto(&self) -> bool {
473497
self.opts.cg.lto || self.target.target.options.requires_lto
474498
}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ fn mir_borrowck<'a, 'tcx>(
7272
let input_mir = tcx.mir_validated(def_id);
7373
debug!("run query mir_borrowck: {}", tcx.item_path_str(def_id));
7474

75-
if {
76-
!tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.sess.use_mir()
77-
&& !tcx.sess.nll()
78-
} {
75+
if !tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.sess.use_mir() {
7976
return None;
8077
}
8178

0 commit comments

Comments
 (0)