@@ -111,9 +111,6 @@ struct LoweringContext<'a, 'hir> {
111
111
is_in_trait_impl : bool ,
112
112
is_in_dyn_type : bool ,
113
113
114
- /// Used to handle lifetimes appearing in impl-traits.
115
- captured_lifetimes : Option < LifetimeCaptureContext > ,
116
-
117
114
current_hir_id_owner : LocalDefId ,
118
115
item_local_id_counter : hir:: ItemLocalId ,
119
116
local_id_to_def_id : SortedMap < ItemLocalId , LocalDefId > ,
@@ -130,19 +127,6 @@ struct LoweringContext<'a, 'hir> {
130
127
allow_into_future : Option < Lrc < [ Symbol ] > > ,
131
128
}
132
129
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
-
146
130
trait ResolverAstLoweringExt {
147
131
fn legacy_const_generic_args ( & self , expr : & Expr ) -> Option < Vec < usize > > ;
148
132
fn get_partial_res ( & self , id : NodeId ) -> Option < PartialRes > ;
@@ -1361,28 +1345,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1361
1345
1362
1346
self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
1363
1347
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
-
1373
1348
let lifetimes_in_bounds =
1374
1349
lifetime_collector:: lifetimes_in_bounds ( & lctx. resolver , bounds) ;
1375
1350
debug ! ( ?lifetimes_in_bounds) ;
1376
1351
1377
- lctx. create_and_capture_lifetime_defs (
1352
+ collected_lifetimes = lctx. create_and_capture_lifetime_defs (
1378
1353
opaque_ty_def_id,
1379
1354
& lifetimes_in_bounds,
1380
1355
& mut new_remapping,
1381
1356
) ;
1382
-
1383
- let ctxt = std:: mem:: replace ( & mut lctx. captured_lifetimes , lifetime_stash) . unwrap ( ) ;
1384
-
1385
- collected_lifetimes = ctxt. captures ;
1386
1357
} ;
1387
1358
debug ! ( ?new_remapping) ;
1388
1359
debug ! ( ?collected_lifetimes) ;
@@ -1481,58 +1452,58 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1481
1452
parent_def_id : LocalDefId ,
1482
1453
lifetimes_in_bounds : & [ Lifetime ] ,
1483
1454
remapping : & mut FxHashMap < LocalDefId , LocalDefId > ,
1484
- ) {
1455
+ ) -> Vec < ( Lifetime , LifetimeRes ) > {
1456
+ let mut result = Vec :: new ( ) ;
1457
+
1485
1458
for lifetime in lifetimes_in_bounds {
1486
1459
let res = self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ;
1487
1460
debug ! ( ?res) ;
1488
1461
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 ( ) ;
1506
1466
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) ) ;
1523
1476
}
1477
+ }
1524
1478
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 ( ) ;
1526
1484
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
+ }
1531
1495
}
1532
1496
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
+ ) ,
1534
1503
}
1535
1504
}
1505
+
1506
+ result
1536
1507
}
1537
1508
1538
1509
fn lower_fn_params_to_names ( & mut self , decl : & FnDecl ) -> & ' hir [ Ident ] {
@@ -1768,24 +1739,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1768
1739
debug ! ( ?captures) ;
1769
1740
1770
1741
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
-
1776
1742
let lifetimes_in_bounds =
1777
1743
lifetime_collector:: lifetimes_in_ret_ty ( & this. resolver , output) ;
1778
1744
debug ! ( ?lifetimes_in_bounds) ;
1779
1745
1780
- this. create_and_capture_lifetime_defs (
1746
+ captures . extend ( this. create_and_capture_lifetime_defs (
1781
1747
opaque_ty_def_id,
1782
1748
& lifetimes_in_bounds,
1783
1749
& mut new_remapping,
1784
- ) ;
1785
-
1786
- let ctxt = std:: mem:: replace ( & mut this. captured_lifetimes , lifetime_stash) . unwrap ( ) ;
1787
-
1788
- captures = ctxt. captures ;
1750
+ ) ) ;
1789
1751
1790
1752
this. with_remapping ( new_remapping, |this| {
1791
1753
// We have to be careful to get elision right here. The
0 commit comments