88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
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.
1212
13+ use rustc:: hir:: def_id:: { DefId } ;
1314use rustc:: infer:: { InferCtxt } ;
1415use rustc:: ty:: { self , TyCtxt , ParamEnv } ;
16+ use rustc:: ty:: maps:: Providers ;
1517use rustc:: mir:: { AssertMessage , BasicBlock , BorrowKind , Location , Lvalue } ;
1618use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
1719use rustc:: mir:: { Statement , StatementKind , Terminator , TerminatorKind } ;
18- use rustc:: mir:: transform:: { MirPass , MirSource } ;
20+ use rustc:: mir:: transform:: { MirSource } ;
1921
2022use rustc_data_structures:: indexed_set:: { self , IdxSetBuf } ;
2123use rustc_data_structures:: indexed_vec:: { Idx } ;
@@ -34,35 +36,25 @@ use util::borrowck_errors::{BorrowckErrors, Origin};
3436use self :: MutateMode :: { JustWrite , WriteAndRead } ;
3537use self :: ConsumeKind :: { Consume } ;
3638
37- pub struct BorrowckMir ;
3839
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+ }
5046
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( ) ) ) ;
5251
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 ;
5755 }
58- }
5956
60- fn borrowck_mir < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , src : MirSource , mir : & Mir < ' tcx > )
61- {
6257 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-
6658 let attributes = tcx. get_attrs ( def_id) ;
6759 let param_env = tcx. param_env ( def_id) ;
6860 tcx. infer_ctxt ( ) . enter ( |_infcx| {
@@ -96,7 +88,7 @@ fn borrowck_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &Mir
9688 mbcx. analyze_results ( & mut state) ; // entry point for DataflowResultsConsumer
9789 } ) ;
9890
99- debug ! ( "borrowck_mir done" ) ;
91+ debug ! ( "mir_borrowck done" ) ;
10092}
10193
10294#[ allow( dead_code) ]
0 commit comments