Skip to content

Commit b27d9cf

Browse files
committed
Auto merge of #52083 - spastorino:dont-run-ast-borrowck-on-mir-mode, r=<try>
Dont run ast borrowck on mir mode r? @nikomatsakis
2 parents 94eb176 + 48765de commit b27d9cf

File tree

12 files changed

+36
-20
lines changed

12 files changed

+36
-20
lines changed

src/librustc/ty/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13541354
!self.sess.opts.debugging_opts.disable_ast_check_for_mutation_in_guard
13551355
}
13561356

1357+
/// If true, we should use the AST-based borrowck (we may *also* use
1358+
/// the MIR-based borrowck).
1359+
pub fn use_ast_borrowck(self) -> bool {
1360+
self.borrowck_mode().use_ast()
1361+
}
1362+
13571363
/// If true, we should use the MIR-based borrowck (we may *also* use
13581364
/// the AST-based borrowck).
13591365
pub fn use_mir_borrowck(self) -> bool {

src/librustc_borrowck/borrowck/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use rustc::middle::mem_categorization::Categorization;
3636
use rustc::middle::mem_categorization::ImmutabilityBlame;
3737
use rustc::middle::region;
3838
use rustc::middle::free_region::RegionRelations;
39+
use rustc::session::config::BorrowckMode;
3940
use rustc::ty::{self, Ty, TyCtxt};
4041
use rustc::ty::query::Providers;
4142
use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
@@ -89,6 +90,8 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
8990
fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
9091
-> Lrc<BorrowCheckResult>
9192
{
93+
assert!(tcx.borrowck_mode() != BorrowckMode::Mir);
94+
9295
debug!("borrowck(body_owner_def_id={:?})", owner_def_id);
9396

9497
let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();

src/librustc_driver/driver.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,11 @@ where
12791279
middle::liveness::check_crate(tcx)
12801280
});
12811281

1282-
time(sess, "borrow checking", || borrowck::check_crate(tcx));
1282+
time(sess, "borrow checking", || {
1283+
if tcx.use_ast_borrowck() {
1284+
borrowck::check_crate(tcx);
1285+
}
1286+
});
12831287

12841288
time(sess,
12851289
"MIR borrow checking",

src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn mir_borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> BorrowC
8080
let mut return_early;
8181

8282
// Return early if we are not supposed to use MIR borrow checker for this function.
83-
return_early = !tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.use_mir_borrowck();
83+
return_early = !tcx.has_attr(def_id, "rustc_mir") && !tcx.use_mir_borrowck();
8484

8585
if tcx.is_struct_constructor(def_id) {
8686
// We are not borrow checking the automatically generated struct constructors

src/librustc_mir/transform/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
225225
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
226226
// execute before we can steal.
227227
let _ = tcx.mir_borrowck(def_id);
228-
let _ = tcx.borrowck(def_id);
228+
229+
if tcx.use_ast_borrowck() {
230+
let _ = tcx.borrowck(def_id);
231+
}
229232

230233
let mut mir = tcx.mir_validated(def_id).steal();
231234
run_passes![tcx, mir, def_id, 2;

src/librustc_mir/transform/rustc_peek.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl MirPass for SanityCheck {
3636
src: MirSource, mir: &mut Mir<'tcx>) {
3737
let def_id = src.def_id;
3838
let id = tcx.hir.as_local_node_id(def_id).unwrap();
39-
if !tcx.has_attr(def_id, "rustc_mir_borrowck") {
39+
if !tcx.has_attr(def_id, "rustc_mir") {
4040
debug!("skipping rustc_peek::SanityCheck on {}", tcx.item_path_str(def_id));
4141
return;
4242
} else {

src/test/compile-fail/mir-dataflow/def-inits-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
// General test of maybe_uninits state computed by MIR dataflow.
1212

13+
#![feature(nll)]
1314
#![feature(core_intrinsics, rustc_attrs)]
1415

1516
use std::intrinsics::rustc_peek;
1617
use std::mem::{drop, replace};
1718

1819
struct S(i32);
1920

20-
#[rustc_mir_borrowck]
2121
#[rustc_mir(rustc_peek_definite_init,stop_after_dataflow)]
2222
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
2323
let ret;

src/test/compile-fail/mir-dataflow/inits-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
// General test of maybe_inits state computed by MIR dataflow.
1212

13+
#![feature(nll)]
1314
#![feature(core_intrinsics, rustc_attrs)]
1415

1516
use std::intrinsics::rustc_peek;
1617
use std::mem::{drop, replace};
1718

1819
struct S(i32);
1920

20-
#[rustc_mir_borrowck]
2121
#[rustc_mir(rustc_peek_maybe_init,stop_after_dataflow)]
2222
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
2323
let ret;

src/test/compile-fail/mir-dataflow/uninits-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
// General test of maybe_uninits state computed by MIR dataflow.
1212

13+
#![feature(nll)]
1314
#![feature(core_intrinsics, rustc_attrs)]
1415

1516
use std::intrinsics::rustc_peek;
1617
use std::mem::{drop, replace};
1718

1819
struct S(i32);
1920

20-
#[rustc_mir_borrowck]
2121
#[rustc_mir(rustc_peek_maybe_uninit,stop_after_dataflow)]
2222
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
2323
let ret;

src/test/compile-fail/mir-dataflow/uninits-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
// General test of maybe_uninits state computed by MIR dataflow.
1212

13+
#![feature(nll)]
1314
#![feature(core_intrinsics, rustc_attrs)]
1415

1516
use std::intrinsics::rustc_peek;
1617
use std::mem::{drop, replace};
1718

1819
struct S(i32);
1920

20-
#[rustc_mir_borrowck]
2121
#[rustc_mir(rustc_peek_maybe_uninit,stop_after_dataflow)]
2222
fn foo(x: &mut S) {
2323
// `x` is initialized here, so maybe-uninit bit is 0.

src/test/ui/error-codes/E0017.nll.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ error[E0017]: references in statics may only refer to immutable values
1010
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
1111
| ^^^^^^ statics require immutable values
1212

13-
error[E0017]: references in statics may only refer to immutable values
14-
--> $DIR/E0017.rs:17:38
15-
|
16-
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
17-
| ^^^^^^ statics require immutable values
18-
1913
error[E0596]: cannot borrow immutable item `X` as mutable
2014
--> $DIR/E0017.rs:15:39
2115
|
2216
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
2317
| ^^^^^^ cannot borrow as mutable
2418

19+
error[E0017]: references in statics may only refer to immutable values
20+
--> $DIR/E0017.rs:17:38
21+
|
22+
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
23+
| ^^^^^^ statics require immutable values
24+
2525
error: aborting due to 4 previous errors
2626

2727
Some errors occurred: E0017, E0596.

src/test/ui/error-codes/E0388.nll.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ error[E0017]: references in statics may only refer to immutable values
1010
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
1111
| ^^^^^^ statics require immutable values
1212

13-
error[E0017]: references in statics may only refer to immutable values
14-
--> $DIR/E0388.rs:17:38
15-
|
16-
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
17-
| ^^^^^^ statics require immutable values
18-
1913
error[E0596]: cannot borrow immutable item `X` as mutable
2014
--> $DIR/E0388.rs:15:39
2115
|
2216
LL | static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
2317
| ^^^^^^ cannot borrow as mutable
2418

19+
error[E0017]: references in statics may only refer to immutable values
20+
--> $DIR/E0388.rs:17:38
21+
|
22+
LL | static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
23+
| ^^^^^^ statics require immutable values
24+
2525
error: aborting due to 4 previous errors
2626

2727
Some errors occurred: E0017, E0596.

0 commit comments

Comments
 (0)