@@ -202,7 +202,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
202
202
// inference algorithm will reject it).
203
203
204
204
// Equate the type variables for the upvars with the actual types.
205
- let final_upvar_tys = self . final_upvar_tys ( closure_hir_id ) ;
205
+ let final_upvar_tys = self . final_upvar_tys ( closure_def_id ) ;
206
206
debug ! (
207
207
"analyze_closure: id={:?} substs={:?} final_upvar_tys={:?}" ,
208
208
closure_hir_id, substs, final_upvar_tys
@@ -222,36 +222,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
222
222
}
223
223
224
224
// Returns a list of `Ty`s for each upvar.
225
- fn final_upvar_tys ( & self , closure_id : hir :: HirId ) -> Vec < Ty < ' tcx > > {
225
+ fn final_upvar_tys ( & self , closure_id : DefId ) -> Vec < Ty < ' tcx > > {
226
226
// Presently an unboxed closure type cannot "escape" out of a
227
227
// function, so we will only encounter ones that originated in the
228
228
// local crate or were inlined into it along with some function.
229
229
// This may change if abstract return types of some sort are
230
230
// implemented.
231
231
let tcx = self . tcx ;
232
- let closure_def_id = tcx. hir ( ) . local_def_id ( closure_id) ;
233
232
234
233
self . typeck_results
235
234
. borrow ( )
236
- . closure_captures
237
- . get ( & closure_def_id. to_def_id ( ) )
238
- . iter ( )
239
- . flat_map ( |upvars| {
240
- upvars. iter ( ) . map ( |( & var_hir_id, _) | {
241
- let upvar_ty = self . node_ty ( var_hir_id) ;
242
- let upvar_id = ty:: UpvarId :: new ( var_hir_id, closure_def_id) ;
243
- let capture = self . typeck_results . borrow ( ) . upvar_capture ( upvar_id) ;
244
-
245
- debug ! ( "var_id={:?} upvar_ty={:?} capture={:?}" , var_hir_id, upvar_ty, capture) ;
246
-
247
- match capture {
248
- ty:: UpvarCapture :: ByValue ( _) => upvar_ty,
249
- ty:: UpvarCapture :: ByRef ( borrow) => tcx. mk_ref (
250
- borrow. region ,
251
- ty:: TypeAndMut { ty : upvar_ty, mutbl : borrow. kind . to_mutbl_lossy ( ) } ,
252
- ) ,
253
- }
254
- } )
235
+ . closure_min_captures_flattened ( closure_id)
236
+ . map ( |captured_place| {
237
+ let upvar_ty = captured_place. place . ty ( ) ;
238
+ let capture = captured_place. info . capture_kind ;
239
+
240
+ debug ! (
241
+ "place={:?} upvar_ty={:?} capture={:?}" ,
242
+ captured_place. place, upvar_ty, capture
243
+ ) ;
244
+
245
+ match capture {
246
+ ty:: UpvarCapture :: ByValue ( _) => upvar_ty,
247
+ ty:: UpvarCapture :: ByRef ( borrow) => tcx. mk_ref (
248
+ borrow. region ,
249
+ ty:: TypeAndMut { ty : upvar_ty, mutbl : borrow. kind . to_mutbl_lossy ( ) } ,
250
+ ) ,
251
+ }
255
252
} )
256
253
. collect ( )
257
254
}
0 commit comments