@@ -259,6 +259,9 @@ enum LifetimeRibKind {
259259
260260 /// Pass responsibility to `resolve_lifetime` code for all cases.
261261 AnonymousPassThrough ( NodeId , /* in_fn_return */ bool ) ,
262+
263+ /// Replace all anonymous lifetimes by provided lifetime.
264+ Elided ( LifetimeRes ) ,
262265}
263266
264267#[ derive( Copy , Clone , Debug ) ]
@@ -580,7 +583,9 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
580583 fn visit_anon_const ( & mut self , constant : & ' ast AnonConst ) {
581584 // We deal with repeat expressions explicitly in `resolve_expr`.
582585 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+ } )
584589 } )
585590 }
586591 fn visit_expr ( & mut self , expr : & ' ast Expr ) {
@@ -1052,6 +1057,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
10521057 LifetimeRibKind :: AnonymousPassThrough ( ..)
10531058 | LifetimeRibKind :: AnonymousCreateParameter { .. }
10541059 | LifetimeRibKind :: AnonymousReportError
1060+ | LifetimeRibKind :: Elided ( _)
10551061 | LifetimeRibKind :: AnonConst
10561062 | LifetimeRibKind :: ConstGeneric => { }
10571063 }
@@ -1408,6 +1414,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14081414 | LifetimeRibKind :: AnonymousCreateParameter { .. } => {
14091415 Some ( LifetimeUseSet :: One { use_span : ident. span , use_ctxt } )
14101416 }
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+ } ) ,
14111424 LifetimeRibKind :: Generics { .. }
14121425 | LifetimeRibKind :: ConstGeneric
14131426 | LifetimeRibKind :: AnonConst => None ,
@@ -1496,6 +1509,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14961509 ) ;
14971510 return ;
14981511 }
1512+ LifetimeRibKind :: Elided ( res) => {
1513+ self . record_lifetime_res ( lifetime. id , res) ;
1514+ return ;
1515+ }
14991516 LifetimeRibKind :: Item => break ,
15001517 LifetimeRibKind :: Generics { .. }
15011518 | LifetimeRibKind :: ConstGeneric
@@ -1632,6 +1649,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16321649 break ;
16331650 }
16341651 LifetimeRibKind :: AnonymousCreateParameter { .. }
1652+ | LifetimeRibKind :: Elided ( _)
16351653 | LifetimeRibKind :: Generics { .. }
16361654 | LifetimeRibKind :: ConstGeneric
16371655 | LifetimeRibKind :: AnonConst => { }
@@ -1690,6 +1708,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16901708 }
16911709 break ;
16921710 }
1711+ LifetimeRibKind :: Elided ( res) => {
1712+ for id in node_ids {
1713+ self . record_lifetime_res ( id, res) ;
1714+ }
1715+ break ;
1716+ }
16931717 // `LifetimeRes::Error`, which would usually be used in the case of
16941718 // `ReportError`, is unsuitable here, as we don't emit an error yet. Instead,
16951719 // 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> {
35813605 ExprKind :: Repeat ( ref elem, ref ct) => {
35823606 self . visit_expr ( elem) ;
35833607 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+ } )
35853611 } ) ;
35863612 }
35873613 ExprKind :: ConstBlock ( ref ct) => {
0 commit comments