Skip to content

Commit 48765de

Browse files
committed
Do not run AST borrowck when -Zborrowck=mir
1 parent 0e31e2f commit 48765de

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
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/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/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)