@@ -1392,80 +1392,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1392
1392
debug ! ( ?lifetimes_in_bounds) ;
1393
1393
debug ! ( ?binders_to_ignore) ;
1394
1394
1395
- for lifetime in & lifetimes_in_bounds {
1396
- let ident = lifetime. ident ;
1397
- let span = ident. span ;
1398
-
1399
- let res =
1400
- lctx. resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ;
1401
- debug ! ( ?res) ;
1402
-
1403
- if let Some ( mut captured_lifetimes) = lctx. captured_lifetimes . take ( ) {
1404
- match res {
1405
- LifetimeRes :: Param { param, binder } => {
1406
- if !captured_lifetimes. binders_to_ignore . contains ( & binder)
1407
- && !binders_to_ignore
1408
- . get ( & lifetime. id )
1409
- . unwrap_or ( & Vec :: new ( ) )
1410
- . contains ( & binder)
1411
- {
1412
- match captured_lifetimes. captures . entry ( param) {
1413
- Entry :: Occupied ( _) => { }
1414
- Entry :: Vacant ( v) => {
1415
- let node_id = lctx. next_node_id ( ) ;
1416
- let name = ParamName :: Plain ( ident) ;
1417
-
1418
- lctx. create_def (
1419
- captured_lifetimes. parent_def_id ,
1420
- node_id,
1421
- DefPathData :: LifetimeNs ( name. ident ( ) . name ) ,
1422
- ) ;
1423
-
1424
- v. insert ( ( span, node_id, name, res) ) ;
1425
- }
1426
- }
1427
- }
1428
- }
1429
-
1430
- LifetimeRes :: Fresh { param, binder } => {
1431
- debug_assert_eq ! ( ident. name, kw:: UnderscoreLifetime ) ;
1432
- if !captured_lifetimes. binders_to_ignore . contains ( & binder)
1433
- && !binders_to_ignore
1434
- . get ( & lifetime. id )
1435
- . unwrap_or ( & Vec :: new ( ) )
1436
- . contains ( & binder)
1437
- {
1438
- let param = lctx. local_def_id ( param) ;
1439
- match captured_lifetimes. captures . entry ( param) {
1440
- Entry :: Occupied ( _) => { }
1441
- Entry :: Vacant ( v) => {
1442
- let node_id = lctx. next_node_id ( ) ;
1443
-
1444
- let name = ParamName :: Fresh ;
1445
-
1446
- lctx. create_def (
1447
- captured_lifetimes. parent_def_id ,
1448
- node_id,
1449
- DefPathData :: LifetimeNs ( kw:: UnderscoreLifetime ) ,
1450
- ) ;
1451
-
1452
- v. insert ( ( span, node_id, name, res) ) ;
1453
- }
1454
- }
1455
- }
1456
- }
1457
-
1458
- LifetimeRes :: Infer | LifetimeRes :: Static | LifetimeRes :: Error => { }
1459
-
1460
- res => panic ! (
1461
- "Unexpected lifetime resolution {:?} for {:?} at {:?}" ,
1462
- res, lifetime. ident, lifetime. ident. span
1463
- ) ,
1464
- }
1465
-
1466
- lctx. captured_lifetimes = Some ( captured_lifetimes) ;
1467
- }
1468
- }
1395
+ lctx. create_and_capture_lifetime_defs ( & lifetimes_in_bounds, & binders_to_ignore) ;
1469
1396
1470
1397
let ret = lctx. lower_param_bounds ( bounds, itctx, false ) ;
1471
1398
@@ -1554,6 +1481,86 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1554
1481
hir:: OwnerNode :: Item ( self . arena . alloc ( opaque_ty_item) )
1555
1482
}
1556
1483
1484
+ fn create_and_capture_lifetime_defs (
1485
+ & mut self ,
1486
+ lifetimes_in_bounds : & [ & Lifetime ] ,
1487
+ binders_to_ignore : & FxHashMap < NodeId , Vec < NodeId > > ,
1488
+ ) {
1489
+ for lifetime in lifetimes_in_bounds {
1490
+ let ident = lifetime. ident ;
1491
+ let span = ident. span ;
1492
+
1493
+ let res = self . resolver . get_lifetime_res ( lifetime. id ) . unwrap_or ( LifetimeRes :: Error ) ;
1494
+ debug ! ( ?res) ;
1495
+
1496
+ if let Some ( mut captured_lifetimes) = self . captured_lifetimes . take ( ) {
1497
+ match res {
1498
+ LifetimeRes :: Param { param, binder } => {
1499
+ if !captured_lifetimes. binders_to_ignore . contains ( & binder)
1500
+ && !binders_to_ignore
1501
+ . get ( & lifetime. id )
1502
+ . unwrap_or ( & Vec :: new ( ) )
1503
+ . contains ( & binder)
1504
+ {
1505
+ match captured_lifetimes. captures . entry ( param) {
1506
+ Entry :: Occupied ( _) => { }
1507
+ Entry :: Vacant ( v) => {
1508
+ let node_id = self . next_node_id ( ) ;
1509
+ let name = ParamName :: Plain ( ident) ;
1510
+
1511
+ self . create_def (
1512
+ captured_lifetimes. parent_def_id ,
1513
+ node_id,
1514
+ DefPathData :: LifetimeNs ( name. ident ( ) . name ) ,
1515
+ ) ;
1516
+
1517
+ v. insert ( ( span, node_id, name, res) ) ;
1518
+ }
1519
+ }
1520
+ }
1521
+ }
1522
+
1523
+ LifetimeRes :: Fresh { param, binder } => {
1524
+ debug_assert_eq ! ( ident. name, kw:: UnderscoreLifetime ) ;
1525
+ if !captured_lifetimes. binders_to_ignore . contains ( & binder)
1526
+ && !binders_to_ignore
1527
+ . get ( & lifetime. id )
1528
+ . unwrap_or ( & Vec :: new ( ) )
1529
+ . contains ( & binder)
1530
+ {
1531
+ let param = self . local_def_id ( param) ;
1532
+ match captured_lifetimes. captures . entry ( param) {
1533
+ Entry :: Occupied ( _) => { }
1534
+ Entry :: Vacant ( v) => {
1535
+ let node_id = self . next_node_id ( ) ;
1536
+
1537
+ let name = ParamName :: Fresh ;
1538
+
1539
+ self . create_def (
1540
+ captured_lifetimes. parent_def_id ,
1541
+ node_id,
1542
+ DefPathData :: LifetimeNs ( kw:: UnderscoreLifetime ) ,
1543
+ ) ;
1544
+
1545
+ v. insert ( ( span, node_id, name, res) ) ;
1546
+ }
1547
+ }
1548
+ }
1549
+ }
1550
+
1551
+ LifetimeRes :: Infer | LifetimeRes :: Static | LifetimeRes :: Error => { }
1552
+
1553
+ res => panic ! (
1554
+ "Unexpected lifetime resolution {:?} for {:?} at {:?}" ,
1555
+ res, lifetime. ident, lifetime. ident. span
1556
+ ) ,
1557
+ }
1558
+
1559
+ self . captured_lifetimes = Some ( captured_lifetimes) ;
1560
+ }
1561
+ }
1562
+ }
1563
+
1557
1564
fn lower_fn_params_to_names ( & mut self , decl : & FnDecl ) -> & ' hir [ Ident ] {
1558
1565
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
1559
1566
// as they are not explicit in HIR/Ty function signatures.
0 commit comments