@@ -221,6 +221,12 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
221
221
Project ,
222
222
Local ,
223
223
}
224
+ // Here we are looking for a chain of access to extract a place reference for
225
+ // a local variable.
226
+ // For instance, given `&*(&*x[y]).z().u`, `probe` will pick out
227
+ // the sub-expressions `&*x[y]` and `y` as expressions making accesses to locals.
228
+ // The place references generated can be discarded earlier as MIR allows,
229
+ // and, thus, can be assigned a smaller region.
224
230
loop {
225
231
match nested_expr. kind {
226
232
hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
@@ -268,6 +274,9 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
268
274
}
269
275
}
270
276
OpTy :: Project => {
277
+ // The generated MIR produces temporaries for the each of the nested references,
278
+ // such as `&x`, `&&x` in `(&&&x).y` for the field access of `y`.
279
+ // These temporaries must stay alive even after the field access.
271
280
ref_level. clear ( ) ;
272
281
}
273
282
OpTy :: Local => {
@@ -290,6 +299,8 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
290
299
| hir:: ExprKind :: Field ( ..)
291
300
| hir:: ExprKind :: Index ( ..)
292
301
| hir:: ExprKind :: Path ( ..) => self . probe ( expr) ,
302
+
303
+ // We do not probe into other function bodies or blocks.
293
304
hir:: ExprKind :: Block ( ..)
294
305
| hir:: ExprKind :: Closure ( ..)
295
306
| hir:: ExprKind :: ConstBlock ( ..) => { }
@@ -300,7 +311,6 @@ fn mark_local_terminating_scopes<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> FxHashSet
300
311
let mut locals = Default :: default ( ) ;
301
312
let mut resolution_visitor = LocalAccessResolutionVisitor { locals : & mut locals } ;
302
313
resolution_visitor. visit_expr ( expr) ;
303
- // visitor.terminating_scopes.extend(locals.iter().copied());
304
314
locals
305
315
}
306
316
0 commit comments