@@ -259,6 +259,9 @@ enum LifetimeRibKind {
259
259
260
260
/// Pass responsibility to `resolve_lifetime` code for all cases.
261
261
AnonymousPassThrough ( NodeId , /* in_fn_return */ bool ) ,
262
+
263
+ /// Replace all anonymous lifetimes by provided lifetime.
264
+ Elided ( LifetimeRes ) ,
262
265
}
263
266
264
267
#[ derive( Copy , Clone , Debug ) ]
@@ -580,7 +583,9 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
580
583
fn visit_anon_const ( & mut self , constant : & ' ast AnonConst ) {
581
584
// We deal with repeat expressions explicitly in `resolve_expr`.
582
585
self . with_lifetime_rib ( LifetimeRibKind :: AnonConst , |this| {
583
- this. resolve_anon_const ( constant, IsRepeatExpr :: No ) ;
586
+ this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
587
+ this. resolve_anon_const ( constant, IsRepeatExpr :: No ) ;
588
+ } )
584
589
} )
585
590
}
586
591
fn visit_expr ( & mut self , expr : & ' ast Expr ) {
@@ -1052,6 +1057,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
1052
1057
LifetimeRibKind :: AnonymousPassThrough ( ..)
1053
1058
| LifetimeRibKind :: AnonymousCreateParameter { .. }
1054
1059
| LifetimeRibKind :: AnonymousReportError
1060
+ | LifetimeRibKind :: Elided ( _)
1055
1061
| LifetimeRibKind :: AnonConst
1056
1062
| LifetimeRibKind :: ConstGeneric => { }
1057
1063
}
@@ -1408,6 +1414,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1408
1414
| LifetimeRibKind :: AnonymousCreateParameter { .. } => {
1409
1415
Some ( LifetimeUseSet :: One { use_span : ident. span , use_ctxt } )
1410
1416
}
1417
+ // Only report if eliding the lifetime would have the same
1418
+ // semantics.
1419
+ LifetimeRibKind :: Elided ( r) => Some ( if res == r {
1420
+ LifetimeUseSet :: One { use_span : ident. span , use_ctxt }
1421
+ } else {
1422
+ LifetimeUseSet :: Many
1423
+ } ) ,
1411
1424
LifetimeRibKind :: Generics { .. }
1412
1425
| LifetimeRibKind :: ConstGeneric
1413
1426
| LifetimeRibKind :: AnonConst => None ,
@@ -1496,6 +1509,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1496
1509
) ;
1497
1510
return ;
1498
1511
}
1512
+ LifetimeRibKind :: Elided ( res) => {
1513
+ self . record_lifetime_res ( lifetime. id , res) ;
1514
+ return ;
1515
+ }
1499
1516
LifetimeRibKind :: Item => break ,
1500
1517
LifetimeRibKind :: Generics { .. }
1501
1518
| LifetimeRibKind :: ConstGeneric
@@ -1632,6 +1649,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1632
1649
break ;
1633
1650
}
1634
1651
LifetimeRibKind :: AnonymousCreateParameter { .. }
1652
+ | LifetimeRibKind :: Elided ( _)
1635
1653
| LifetimeRibKind :: Generics { .. }
1636
1654
| LifetimeRibKind :: ConstGeneric
1637
1655
| LifetimeRibKind :: AnonConst => { }
@@ -1690,6 +1708,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1690
1708
}
1691
1709
break ;
1692
1710
}
1711
+ LifetimeRibKind :: Elided ( res) => {
1712
+ for id in node_ids {
1713
+ self . record_lifetime_res ( id, res) ;
1714
+ }
1715
+ break ;
1716
+ }
1693
1717
// `LifetimeRes::Error`, which would usually be used in the case of
1694
1718
// `ReportError`, is unsuitable here, as we don't emit an error yet. Instead,
1695
1719
// we simply resolve to an implicit lifetime, which will be checked later, at
@@ -3581,7 +3605,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
3581
3605
ExprKind :: Repeat ( ref elem, ref ct) => {
3582
3606
self . visit_expr ( elem) ;
3583
3607
self . with_lifetime_rib ( LifetimeRibKind :: AnonConst , |this| {
3584
- this. resolve_anon_const ( ct, IsRepeatExpr :: Yes )
3608
+ this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
3609
+ this. resolve_anon_const ( ct, IsRepeatExpr :: Yes )
3610
+ } )
3585
3611
} ) ;
3586
3612
}
3587
3613
ExprKind :: ConstBlock ( ref ct) => {
0 commit comments