@@ -20,13 +20,15 @@ pub use self::MovedValueUseKind::*;
20
20
21
21
use self :: InteriorKind :: * ;
22
22
23
+ use rustc:: hir:: HirId ;
23
24
use rustc:: hir:: map as hir_map;
24
25
use rustc:: hir:: map:: blocks:: FnLikeNode ;
25
26
use rustc:: cfg;
26
27
use rustc:: middle:: dataflow:: DataFlowContext ;
27
28
use rustc:: middle:: dataflow:: BitwiseOperator ;
28
29
use rustc:: middle:: dataflow:: DataFlowOperator ;
29
30
use rustc:: middle:: dataflow:: KillFrom ;
31
+ use rustc:: middle:: borrowck:: BorrowCheckResult ;
30
32
use rustc:: hir:: def_id:: { DefId , DefIndex } ;
31
33
use rustc:: middle:: expr_use_visitor as euv;
32
34
use rustc:: middle:: mem_categorization as mc;
@@ -37,7 +39,9 @@ use rustc::middle::free_region::RegionRelations;
37
39
use rustc:: ty:: { self , Ty , TyCtxt } ;
38
40
use rustc:: ty:: maps:: Providers ;
39
41
use rustc_mir:: util:: borrowck_errors:: { BorrowckErrors , Origin } ;
42
+ use rustc:: util:: nodemap:: FxHashSet ;
40
43
44
+ use std:: cell:: RefCell ;
41
45
use std:: fmt;
42
46
use std:: rc:: Rc ;
43
47
use std:: hash:: { Hash , Hasher } ;
@@ -54,6 +58,8 @@ pub mod gather_loans;
54
58
55
59
pub mod move_data;
56
60
61
+ mod unused;
62
+
57
63
#[ derive( Clone , Copy ) ]
58
64
pub struct LoanDataFlowOperator ;
59
65
@@ -79,7 +85,9 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
79
85
pub move_data : move_data:: FlowedMoveData < ' a , ' tcx > ,
80
86
}
81
87
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
+ {
83
91
debug ! ( "borrowck(body_owner_def_id={:?})" , owner_def_id) ;
84
92
85
93
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) {
91
99
// those things (notably the synthesized constructors from
92
100
// tuple structs/variants) do not have an associated body
93
101
// and do not need borrowchecking.
94
- return ;
102
+ return Rc :: new ( BorrowCheckResult {
103
+ used_mut_nodes : FxHashSet ( ) ,
104
+ } )
95
105
}
96
106
_ => { }
97
107
}
@@ -100,7 +110,14 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
100
110
let tables = tcx. typeck_tables_of ( owner_def_id) ;
101
111
let region_scope_tree = tcx. region_scope_tree ( owner_def_id) ;
102
112
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
+ } ;
104
121
105
122
// Eventually, borrowck will always read the MIR, but at the
106
123
// 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) {
118
135
if let Some ( AnalysisData { all_loans,
119
136
loans : loan_dfcx,
120
137
move_data : flowed_moves } ) =
121
- build_borrowck_dataflow_data ( bccx, false , body_id,
138
+ build_borrowck_dataflow_data ( & mut bccx, false , body_id,
122
139
|bccx| {
123
140
cfg = Some ( cfg:: CFG :: new ( bccx. tcx , & body) ) ;
124
141
cfg. as_mut ( ) . unwrap ( )
125
142
} )
126
143
{
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) ;
128
145
}
146
+ unused:: check ( & mut bccx, body) ;
147
+
148
+ Rc :: new ( BorrowCheckResult {
149
+ used_mut_nodes : bccx. used_mut_nodes . into_inner ( ) ,
150
+ } )
129
151
}
130
152
131
153
fn 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>(
198
220
let tables = tcx. typeck_tables_of ( owner_def_id) ;
199
221
let region_scope_tree = tcx. region_scope_tree ( owner_def_id) ;
200
222
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
+ } ;
202
231
203
232
let dataflow_data = build_borrowck_dataflow_data ( & mut bccx, true , body_id, |_| cfg) ;
204
233
( bccx, dataflow_data. unwrap ( ) )
@@ -219,6 +248,8 @@ pub struct BorrowckCtxt<'a, 'tcx: 'a> {
219
248
owner_def_id : DefId ,
220
249
221
250
body : & ' tcx hir:: Body ,
251
+
252
+ used_mut_nodes : RefCell < FxHashSet < HirId > > ,
222
253
}
223
254
224
255
impl < ' b , ' tcx : ' b > BorrowckErrors for BorrowckCtxt < ' b , ' tcx > {
0 commit comments