@@ -20,13 +20,15 @@ pub use self::MovedValueUseKind::*;
2020
2121use self :: InteriorKind :: * ;
2222
23+ use rustc:: hir:: HirId ;
2324use rustc:: hir:: map as hir_map;
2425use rustc:: hir:: map:: blocks:: FnLikeNode ;
2526use rustc:: cfg;
2627use rustc:: middle:: dataflow:: DataFlowContext ;
2728use rustc:: middle:: dataflow:: BitwiseOperator ;
2829use rustc:: middle:: dataflow:: DataFlowOperator ;
2930use rustc:: middle:: dataflow:: KillFrom ;
31+ use rustc:: middle:: borrowck:: BorrowCheckResult ;
3032use rustc:: hir:: def_id:: { DefId , DefIndex } ;
3133use rustc:: middle:: expr_use_visitor as euv;
3234use rustc:: middle:: mem_categorization as mc;
@@ -37,7 +39,9 @@ use rustc::middle::free_region::RegionRelations;
3739use rustc:: ty:: { self , Ty , TyCtxt } ;
3840use rustc:: ty:: maps:: Providers ;
3941use rustc_mir:: util:: borrowck_errors:: { BorrowckErrors , Origin } ;
42+ use rustc:: util:: nodemap:: FxHashSet ;
4043
44+ use std:: cell:: RefCell ;
4145use std:: fmt;
4246use std:: rc:: Rc ;
4347use std:: hash:: { Hash , Hasher } ;
@@ -54,6 +58,8 @@ pub mod gather_loans;
5458
5559pub mod move_data;
5660
61+ mod unused;
62+
5763#[ derive( Clone , Copy ) ]
5864pub struct LoanDataFlowOperator ;
5965
@@ -79,7 +85,9 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
7985 pub move_data : move_data:: FlowedMoveData < ' a , ' tcx > ,
8086}
8187
82- fn borrowck < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , owner_def_id : DefId ) {
88+ fn borrowck < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , owner_def_id : DefId )
89+ -> Rc < BorrowCheckResult >
90+ {
8391 debug ! ( "borrowck(body_owner_def_id={:?})" , owner_def_id) ;
8492
8593 let owner_id = tcx. hir . as_local_node_id ( owner_def_id) . unwrap ( ) ;
@@ -91,7 +99,9 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
9199 // those things (notably the synthesized constructors from
92100 // tuple structs/variants) do not have an associated body
93101 // and do not need borrowchecking.
94- return ;
102+ return Rc :: new ( BorrowCheckResult {
103+ used_mut_nodes : FxHashSet ( ) ,
104+ } )
95105 }
96106 _ => { }
97107 }
@@ -100,7 +110,14 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
100110 let tables = tcx. typeck_tables_of ( owner_def_id) ;
101111 let region_scope_tree = tcx. region_scope_tree ( owner_def_id) ;
102112 let body = tcx. hir . body ( body_id) ;
103- let bccx = & mut BorrowckCtxt { tcx, tables, region_scope_tree, owner_def_id, body } ;
113+ let mut bccx = BorrowckCtxt {
114+ tcx,
115+ tables,
116+ region_scope_tree,
117+ owner_def_id,
118+ body,
119+ used_mut_nodes : RefCell :: new ( FxHashSet ( ) ) ,
120+ } ;
104121
105122 // Eventually, borrowck will always read the MIR, but at the
106123 // moment we do not. So, for now, we always force MIR to be
@@ -118,14 +135,19 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
118135 if let Some ( AnalysisData { all_loans,
119136 loans : loan_dfcx,
120137 move_data : flowed_moves } ) =
121- build_borrowck_dataflow_data ( bccx, false , body_id,
138+ build_borrowck_dataflow_data ( & mut bccx, false , body_id,
122139 |bccx| {
123140 cfg = Some ( cfg:: CFG :: new ( bccx. tcx , & body) ) ;
124141 cfg. as_mut ( ) . unwrap ( )
125142 } )
126143 {
127- check_loans:: check_loans ( bccx, & loan_dfcx, & flowed_moves, & all_loans, body) ;
144+ check_loans:: check_loans ( & mut bccx, & loan_dfcx, & flowed_moves, & all_loans, body) ;
128145 }
146+ unused:: check ( & mut bccx, body) ;
147+
148+ Rc :: new ( BorrowCheckResult {
149+ used_mut_nodes : bccx. used_mut_nodes . into_inner ( ) ,
150+ } )
129151}
130152
131153fn build_borrowck_dataflow_data < ' a , ' c , ' tcx , F > ( this : & mut BorrowckCtxt < ' a , ' tcx > ,
@@ -198,7 +220,14 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
198220 let tables = tcx. typeck_tables_of ( owner_def_id) ;
199221 let region_scope_tree = tcx. region_scope_tree ( owner_def_id) ;
200222 let body = tcx. hir . body ( body_id) ;
201- let mut bccx = BorrowckCtxt { tcx, tables, region_scope_tree, owner_def_id, body } ;
223+ let mut bccx = BorrowckCtxt {
224+ tcx,
225+ tables,
226+ region_scope_tree,
227+ owner_def_id,
228+ body,
229+ used_mut_nodes : RefCell :: new ( FxHashSet ( ) ) ,
230+ } ;
202231
203232 let dataflow_data = build_borrowck_dataflow_data ( & mut bccx, true , body_id, |_| cfg) ;
204233 ( bccx, dataflow_data. unwrap ( ) )
@@ -219,6 +248,8 @@ pub struct BorrowckCtxt<'a, 'tcx: 'a> {
219248 owner_def_id : DefId ,
220249
221250 body : & ' tcx hir:: Body ,
251+
252+ used_mut_nodes : RefCell < FxHashSet < HirId > > ,
222253}
223254
224255impl < ' b , ' tcx : ' b > BorrowckErrors for BorrowckCtxt < ' b , ' tcx > {
0 commit comments