@@ -111,9 +111,6 @@ struct LoweringContext<'a, 'hir> {
111111 is_in_trait_impl : bool ,
112112 is_in_dyn_type : bool ,
113113
114- /// Used to handle lifetimes appearing in impl-traits.
115- captured_lifetimes : Option < LifetimeCaptureContext > ,
116-
117114 current_hir_id_owner : LocalDefId ,
118115 item_local_id_counter : hir:: ItemLocalId ,
119116 local_id_to_def_id : SortedMap < ItemLocalId , LocalDefId > ,
@@ -130,19 +127,6 @@ struct LoweringContext<'a, 'hir> {
130127 allow_into_future : Option < Lrc < [ Symbol ] > > ,
131128}
132129
133- /// When we lower a lifetime, it is inserted in `captures`, and the resolution is modified so
134- /// to point to the lifetime parameter impl-trait will generate.
135- /// When traversing `for<...>` binders, they are inserted in `binders_to_ignore` so we know *not*
136- /// to rebind the introduced lifetimes.
137- #[ derive( Debug ) ]
138- struct LifetimeCaptureContext {
139- /// Set of lifetimes to rebind.
140- captures : Vec < (
141- Lifetime , // Lifetime parameter
142- LifetimeRes , // original resolution
143- ) > ,
144- }
145-
146130trait ResolverAstLoweringExt {
147131 fn legacy_const_generic_args ( & self , expr : & Expr ) -> Option < Vec < usize > > ;
148132 fn get_partial_res ( & self , id : NodeId ) -> Option < PartialRes > ;
@@ -1361,28 +1345,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13611345
13621346 self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
13631347 if origin != hir:: OpaqueTyOrigin :: TyAlias {
1364- debug ! ( ?lctx. captured_lifetimes) ;
1365-
1366- let lifetime_stash = std:: mem:: replace (
1367- & mut lctx. captured_lifetimes ,
1368- Some ( LifetimeCaptureContext {
1369- captures : std:: mem:: take ( & mut collected_lifetimes) ,
1370- } ) ,
1371- ) ;
1372-
13731348 let lifetimes_in_bounds =
13741349 lifetime_collector:: lifetimes_in_bounds ( & lctx. resolver , bounds) ;
13751350 debug ! ( ?lifetimes_in_bounds) ;
13761351
1377- lctx. create_and_capture_lifetime_defs (
1352+ collected_lifetimes = lctx. create_and_capture_lifetime_defs (
13781353 opaque_ty_def_id,
13791354 & lifetimes_in_bounds,
13801355 & mut new_remapping,
13811356 ) ;
1382-
1383- let ctxt = std:: mem:: replace ( & mut lctx. captured_lifetimes , lifetime_stash) . unwrap ( ) ;
1384-
1385- collected_lifetimes = ctxt. captures ;
13861357 } ;
13871358 debug ! ( ?new_remapping) ;
13881359 debug ! ( ?collected_lifetimes) ;
@@ -1481,58 +1452,58 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14811452 parent_def_id : LocalDefId ,
14821453 lifetimes_in_bounds : & [ Lifetime ] ,
14831454 remapping : & mut FxHashMap < LocalDefId , LocalDefId > ,
1484- ) {
1455+ ) -> Vec < ( Lifetime , LifetimeRes ) > {
1456+ let mut result = Vec :: new ( ) ;
1457+
14851458 for lifetime in lifetimes_in_bounds {
14861459 let res = self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ;
14871460 debug ! ( ?res) ;
14881461
1489- if let Some ( mut captured_lifetimes) = self . captured_lifetimes . take ( ) {
1490- match res {
1491- LifetimeRes :: Param { param : old_def_id, binder : _ } => {
1492- if remapping. get ( & old_def_id) . is_none ( ) {
1493- let node_id = self . next_node_id ( ) ;
1494-
1495- let new_def_id = self . create_def (
1496- parent_def_id,
1497- node_id,
1498- DefPathData :: LifetimeNs ( lifetime. ident . name ) ,
1499- ) ;
1500- remapping. insert ( old_def_id, new_def_id) ;
1501-
1502- let new_lifetime = Lifetime { id : node_id, ident : lifetime. ident } ;
1503- captured_lifetimes. captures . push ( ( new_lifetime, res) ) ;
1504- }
1505- }
1462+ match res {
1463+ LifetimeRes :: Param { param : old_def_id, binder : _ } => {
1464+ if remapping. get ( & old_def_id) . is_none ( ) {
1465+ let node_id = self . next_node_id ( ) ;
15061466
1507- LifetimeRes :: Fresh { param, binder : _ } => {
1508- debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
1509- let old_def_id = self . local_def_id ( param) ;
1510- if remapping. get ( & old_def_id) . is_none ( ) {
1511- let node_id = self . next_node_id ( ) ;
1512-
1513- let new_def_id = self . create_def (
1514- parent_def_id,
1515- node_id,
1516- DefPathData :: LifetimeNs ( kw:: UnderscoreLifetime ) ,
1517- ) ;
1518- remapping. insert ( old_def_id, new_def_id) ;
1519-
1520- let new_lifetime = Lifetime { id : node_id, ident : lifetime. ident } ;
1521- captured_lifetimes. captures . push ( ( new_lifetime, res) ) ;
1522- }
1467+ let new_def_id = self . create_def (
1468+ parent_def_id,
1469+ node_id,
1470+ DefPathData :: LifetimeNs ( lifetime. ident . name ) ,
1471+ ) ;
1472+ remapping. insert ( old_def_id, new_def_id) ;
1473+
1474+ let new_lifetime = Lifetime { id : node_id, ident : lifetime. ident } ;
1475+ result. push ( ( new_lifetime, res) ) ;
15231476 }
1477+ }
15241478
1525- LifetimeRes :: Static | LifetimeRes :: Error => { }
1479+ LifetimeRes :: Fresh { param, binder : _ } => {
1480+ debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
1481+ let old_def_id = self . local_def_id ( param) ;
1482+ if remapping. get ( & old_def_id) . is_none ( ) {
1483+ let node_id = self . next_node_id ( ) ;
15261484
1527- res => panic ! (
1528- "Unexpected lifetime resolution {:?} for {:?} at {:?}" ,
1529- res, lifetime. ident, lifetime. ident. span
1530- ) ,
1485+ let new_def_id = self . create_def (
1486+ parent_def_id,
1487+ node_id,
1488+ DefPathData :: LifetimeNs ( kw:: UnderscoreLifetime ) ,
1489+ ) ;
1490+ remapping. insert ( old_def_id, new_def_id) ;
1491+
1492+ let new_lifetime = Lifetime { id : node_id, ident : lifetime. ident } ;
1493+ result. push ( ( new_lifetime, res) ) ;
1494+ }
15311495 }
15321496
1533- self . captured_lifetimes = Some ( captured_lifetimes) ;
1497+ LifetimeRes :: Static | LifetimeRes :: Error => { }
1498+
1499+ res => panic ! (
1500+ "Unexpected lifetime resolution {:?} for {:?} at {:?}" ,
1501+ res, lifetime. ident, lifetime. ident. span
1502+ ) ,
15341503 }
15351504 }
1505+
1506+ result
15361507 }
15371508
15381509 fn lower_fn_params_to_names ( & mut self , decl : & FnDecl ) -> & ' hir [ Ident ] {
@@ -1768,24 +1739,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17681739 debug ! ( ?captures) ;
17691740
17701741 self . with_hir_id_owner ( opaque_ty_node_id, |this| {
1771- let lifetime_stash = std:: mem:: replace (
1772- & mut this. captured_lifetimes ,
1773- Some ( LifetimeCaptureContext { captures : std:: mem:: take ( & mut captures) } ) ,
1774- ) ;
1775-
17761742 let lifetimes_in_bounds =
17771743 lifetime_collector:: lifetimes_in_ret_ty ( & this. resolver , output) ;
17781744 debug ! ( ?lifetimes_in_bounds) ;
17791745
1780- this. create_and_capture_lifetime_defs (
1746+ captures . extend ( this. create_and_capture_lifetime_defs (
17811747 opaque_ty_def_id,
17821748 & lifetimes_in_bounds,
17831749 & mut new_remapping,
1784- ) ;
1785-
1786- let ctxt = std:: mem:: replace ( & mut this. captured_lifetimes , lifetime_stash) . unwrap ( ) ;
1787-
1788- captures = ctxt. captures ;
1750+ ) ) ;
17891751
17901752 this. with_remapping ( new_remapping, |this| {
17911753 // We have to be careful to get elision right here. The
0 commit comments