@@ -47,7 +47,7 @@ use syntax_pos::{MultiSpan, Span};
47
47
use errors:: DiagnosticBuilder ;
48
48
49
49
use rustc:: hir;
50
- use rustc:: hir:: intravisit:: { self , Visitor , FnKind } ;
50
+ use rustc:: hir:: intravisit:: { self , Visitor , FnKind , NestedVisitMode } ;
51
51
52
52
pub mod check_loans;
53
53
@@ -62,9 +62,13 @@ pub struct LoanDataFlowOperator;
62
62
63
63
pub type LoanDataFlow < ' a , ' tcx > = DataFlowContext < ' a , ' tcx , LoanDataFlowOperator > ;
64
64
65
- impl < ' a , ' tcx , ' v > Visitor < ' v > for BorrowckCtxt < ' a , ' tcx > {
66
- fn visit_fn ( & mut self , fk : FnKind < ' v > , fd : & ' v hir:: FnDecl ,
67
- b : & ' v hir:: Expr , s : Span , id : ast:: NodeId ) {
65
+ impl < ' a , ' tcx > Visitor < ' tcx > for BorrowckCtxt < ' a , ' tcx > {
66
+ fn nested_visit_map ( & mut self ) -> Option < ( & hir:: map:: Map < ' tcx > , NestedVisitMode ) > {
67
+ Some ( ( & self . tcx . map , NestedVisitMode :: OnlyBodies ) )
68
+ }
69
+
70
+ fn visit_fn ( & mut self , fk : FnKind < ' tcx > , fd : & ' tcx hir:: FnDecl ,
71
+ b : hir:: ExprId , s : Span , id : ast:: NodeId ) {
68
72
match fk {
69
73
FnKind :: ItemFn ( ..) |
70
74
FnKind :: Method ( ..) => {
@@ -79,18 +83,18 @@ impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> {
79
83
}
80
84
}
81
85
82
- fn visit_item ( & mut self , item : & hir:: Item ) {
86
+ fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
83
87
borrowck_item ( self , item) ;
84
88
}
85
89
86
- fn visit_trait_item ( & mut self , ti : & hir:: TraitItem ) {
90
+ fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem ) {
87
91
if let hir:: ConstTraitItem ( _, Some ( ref expr) ) = ti. node {
88
92
gather_loans:: gather_loans_in_static_initializer ( self , ti. id , & expr) ;
89
93
}
90
94
intravisit:: walk_trait_item ( self , ti) ;
91
95
}
92
96
93
- fn visit_impl_item ( & mut self , ii : & hir:: ImplItem ) {
97
+ fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem ) {
94
98
if let hir:: ImplItemKind :: Const ( _, ref expr) = ii. node {
95
99
gather_loans:: gather_loans_in_static_initializer ( self , ii. id , & expr) ;
96
100
}
@@ -131,7 +135,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
131
135
}
132
136
}
133
137
134
- fn borrowck_item ( this : & mut BorrowckCtxt , item : & hir:: Item ) {
138
+ fn borrowck_item < ' a , ' tcx > ( this : & mut BorrowckCtxt < ' a , ' tcx > , item : & ' tcx hir:: Item ) {
135
139
// Gather loans for items. Note that we don't need
136
140
// to check loans for single expressions. The check
137
141
// loan step is intended for things that have a data
@@ -154,15 +158,17 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
154
158
pub move_data : move_data:: FlowedMoveData < ' a , ' tcx > ,
155
159
}
156
160
157
- fn borrowck_fn ( this : & mut BorrowckCtxt ,
158
- fk : FnKind ,
159
- decl : & hir:: FnDecl ,
160
- body : & hir:: Expr ,
161
- sp : Span ,
162
- id : ast:: NodeId ,
163
- attributes : & [ ast:: Attribute ] ) {
161
+ fn borrowck_fn < ' a , ' tcx > ( this : & mut BorrowckCtxt < ' a , ' tcx > ,
162
+ fk : FnKind < ' tcx > ,
163
+ decl : & ' tcx hir:: FnDecl ,
164
+ body_id : hir:: ExprId ,
165
+ sp : Span ,
166
+ id : ast:: NodeId ,
167
+ attributes : & [ ast:: Attribute ] ) {
164
168
debug ! ( "borrowck_fn(id={})" , id) ;
165
169
170
+ let body = this. tcx . map . expr ( body_id) ;
171
+
166
172
if attributes. iter ( ) . any ( |item| item. check_name ( "rustc_mir_borrowck" ) ) {
167
173
this. with_temp_region_map ( id, |this| {
168
174
mir:: borrowck_mir ( this, fk, decl, body, sp, id, attributes)
@@ -191,14 +197,14 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
191
197
decl,
192
198
body) ;
193
199
194
- intravisit:: walk_fn ( this, fk, decl, body , sp, id) ;
200
+ intravisit:: walk_fn ( this, fk, decl, body_id , sp, id) ;
195
201
}
196
202
197
203
fn build_borrowck_dataflow_data < ' a , ' tcx > ( this : & mut BorrowckCtxt < ' a , ' tcx > ,
198
- fk : FnKind ,
199
- decl : & hir:: FnDecl ,
204
+ fk : FnKind < ' tcx > ,
205
+ decl : & ' tcx hir:: FnDecl ,
200
206
cfg : & cfg:: CFG ,
201
- body : & hir:: Expr ,
207
+ body : & ' tcx hir:: Expr ,
202
208
sp : Span ,
203
209
id : ast:: NodeId )
204
210
-> AnalysisData < ' a , ' tcx >
@@ -241,7 +247,7 @@ fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
241
247
/// the `BorrowckCtxt` itself , e.g. the flowgraph visualizer.
242
248
pub fn build_borrowck_dataflow_data_for_fn < ' a , ' tcx > (
243
249
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
244
- fn_parts : FnParts < ' a > ,
250
+ fn_parts : FnParts < ' tcx > ,
245
251
cfg : & cfg:: CFG )
246
252
-> ( BorrowckCtxt < ' a , ' tcx > , AnalysisData < ' a , ' tcx > )
247
253
{
@@ -257,11 +263,13 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
257
263
}
258
264
} ;
259
265
266
+ let body = tcx. map . expr ( fn_parts. body ) ;
267
+
260
268
let dataflow_data = build_borrowck_dataflow_data ( & mut bccx,
261
269
fn_parts. kind ,
262
270
& fn_parts. decl ,
263
271
cfg,
264
- & fn_parts . body ,
272
+ body,
265
273
fn_parts. span ,
266
274
fn_parts. id ) ;
267
275
@@ -407,8 +415,8 @@ pub fn closure_to_block(closure_id: ast::NodeId,
407
415
tcx : TyCtxt ) -> ast:: NodeId {
408
416
match tcx. map . get ( closure_id) {
409
417
hir_map:: NodeExpr ( expr) => match expr. node {
410
- hir:: ExprClosure ( .., ref block , _) => {
411
- block . id
418
+ hir:: ExprClosure ( .., body_id , _) => {
419
+ body_id . node_id ( )
412
420
}
413
421
_ => {
414
422
bug ! ( "encountered non-closure id: {}" , closure_id)
0 commit comments