@@ -1481,20 +1481,29 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14811481 /// work during the type-checking of the enclosing function and
14821482 /// return the closure signature in its partially inferred state.
14831483 pub fn fn_sig ( & self , def_id : DefId ) -> ty:: PolyFnSig < ' tcx > {
1484+ // Do we have an in-progress set of tables we are inferring?
14841485 if let Some ( tables) = self . in_progress_tables {
1486+ // Is this a local item?
14851487 if let Some ( id) = self . tcx . hir . as_local_node_id ( def_id) {
1486- let hir_id = self . tcx . hir . node_to_hir_id ( id) ;
1487- let closure_ty = tables. borrow ( ) . node_id_to_type ( hir_id) ;
1488- let ( closure_def_id, closure_substs) = match closure_ty. sty {
1489- ty:: TyClosure ( closure_def_id, closure_substs) =>
1490- ( closure_def_id, closure_substs) ,
1491- _ =>
1492- bug ! ( "closure with non-closure type: {:?}" , closure_ty) ,
1493- } ;
1494- assert_eq ! ( def_id, closure_def_id) ;
1495- let closure_sig_ty = closure_substs. closure_sig_ty ( def_id, self . tcx ) ;
1496- let closure_sig_ty = self . shallow_resolve ( & closure_sig_ty) ;
1497- return closure_sig_ty. fn_sig ( self . tcx ) ;
1488+ // Is it a local *closure*?
1489+ if self . tcx . is_closure ( def_id) {
1490+ let hir_id = self . tcx . hir . node_to_hir_id ( id) ;
1491+ // Is this local closure contained within the tables we are inferring?
1492+ if tables. borrow ( ) . local_id_root == Some ( DefId :: local ( hir_id. owner ) ) {
1493+ // if so, extract signature from there.
1494+ let closure_ty = tables. borrow ( ) . node_id_to_type ( hir_id) ;
1495+ let ( closure_def_id, closure_substs) = match closure_ty. sty {
1496+ ty:: TyClosure ( closure_def_id, closure_substs) =>
1497+ ( closure_def_id, closure_substs) ,
1498+ _ =>
1499+ bug ! ( "closure with non-closure type: {:?}" , closure_ty) ,
1500+ } ;
1501+ assert_eq ! ( def_id, closure_def_id) ;
1502+ let closure_sig_ty = closure_substs. closure_sig_ty ( def_id, self . tcx ) ;
1503+ let closure_sig_ty = self . shallow_resolve ( & closure_sig_ty) ;
1504+ return closure_sig_ty. fn_sig ( self . tcx ) ;
1505+ }
1506+ }
14981507 }
14991508 }
15001509
0 commit comments