8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- //! This pass borrow-checks the MIR to (further) ensure it is not broken.
11
+ //! This query borrow-checks the MIR to (further) ensure it is not broken.
12
12
13
+ use rustc:: hir:: def_id:: { DefId } ;
13
14
use rustc:: infer:: { InferCtxt } ;
14
15
use rustc:: ty:: { self , TyCtxt , ParamEnv } ;
16
+ use rustc:: ty:: maps:: Providers ;
15
17
use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Location , Lvalue } ;
16
18
use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
17
19
use rustc:: mir:: { Statement , StatementKind , Terminator , TerminatorKind } ;
18
- use rustc:: mir:: transform:: { MirPass , MirSource } ;
20
+ use rustc:: mir:: transform:: { MirSource } ;
19
21
20
22
use rustc_data_structures:: indexed_set:: { self , IdxSetBuf } ;
21
23
use rustc_data_structures:: indexed_vec:: { Idx } ;
@@ -34,35 +36,25 @@ use util::borrowck_errors::{BorrowckErrors, Origin};
34
36
use self :: MutateMode :: { JustWrite , WriteAndRead } ;
35
37
use self :: ConsumeKind :: { Consume } ;
36
38
37
- pub struct BorrowckMir ;
38
39
39
- impl MirPass for BorrowckMir {
40
- fn run_pass < ' a , ' tcx > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > , src : MirSource , mir : & mut Mir < ' tcx > ) {
41
-
42
- // let err_count = tcx.sess.err_count();
43
- // if err_count > 0 {
44
- // // compiling a broken program can obviously result in a
45
- // // broken MIR, so try not to report duplicate errors.
46
- // debug!("skipping BorrowckMir: {} due to {} previous errors",
47
- // tcx.node_path_str(src.item_id()), err_count);
48
- // return;
49
- // }
40
+ pub fn provide ( providers : & mut Providers ) {
41
+ * providers = Providers {
42
+ mir_borrowck,
43
+ ..* providers
44
+ } ;
45
+ }
50
46
51
- debug ! ( "run_pass BorrowckMir: {}" , tcx. node_path_str( src. item_id( ) ) ) ;
47
+ fn mir_borrowck < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) {
48
+ let mir = tcx. mir_validated ( def_id) ;
49
+ let src = MirSource :: from_local_def_id ( tcx, def_id) ;
50
+ debug ! ( "run query mir_borrowck: {}" , tcx. node_path_str( src. item_id( ) ) ) ;
52
51
53
- let def_id = tcx. hir . local_def_id ( src. item_id ( ) ) ;
54
- if tcx. has_attr ( def_id, "rustc_mir_borrowck" ) || tcx. sess . opts . debugging_opts . borrowck_mir {
55
- borrowck_mir ( tcx, src, mir) ;
56
- }
52
+ let mir: & Mir < ' tcx > = & mir. borrow ( ) ;
53
+ if !tcx. has_attr ( def_id, "rustc_mir_borrowck" ) || !tcx. sess . opts . debugging_opts . borrowck_mir {
54
+ return ;
57
55
}
58
- }
59
56
60
- fn borrowck_mir < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , src : MirSource , mir : & Mir < ' tcx > )
61
- {
62
57
let id = src. item_id ( ) ;
63
- let def_id = tcx. hir . local_def_id ( id) ;
64
- debug ! ( "borrowck_mir({}) UNIMPLEMENTED" , tcx. item_path_str( def_id) ) ;
65
-
66
58
let attributes = tcx. get_attrs ( def_id) ;
67
59
let param_env = tcx. param_env ( def_id) ;
68
60
tcx. infer_ctxt ( ) . enter ( |_infcx| {
@@ -96,7 +88,7 @@ fn borrowck_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &Mir
96
88
mbcx. analyze_results ( & mut state) ; // entry point for DataflowResultsConsumer
97
89
} ) ;
98
90
99
- debug ! ( "borrowck_mir done" ) ;
91
+ debug ! ( "mir_borrowck done" ) ;
100
92
}
101
93
102
94
#[ allow( dead_code) ]
0 commit comments