@@ -865,7 +865,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
865865 let previous_state = replace ( & mut this. in_func_body , true ) ;
866866 // Resolve the function body, potentially inside the body of an async closure
867867 this. with_lifetime_rib (
868- LifetimeRibKind :: Elided ( LifetimeRes :: Anonymous { binder : fn_id } ) ,
868+ LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) ,
869869 |this| this. visit_block ( body) ,
870870 ) ;
871871
@@ -893,9 +893,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
893893 this. with_lifetime_rib (
894894 match binder {
895895 ClosureBinder :: NotPresent => {
896- LifetimeRibKind :: Elided ( LifetimeRes :: Anonymous {
897- binder : fn_id,
898- } )
896+ LifetimeRibKind :: Elided ( LifetimeRes :: Infer )
899897 }
900898 ClosureBinder :: For { .. } => LifetimeRibKind :: AnonymousReportError ,
901899 } ,
@@ -907,7 +905,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
907905 let previous_state = replace ( & mut this. in_func_body , true ) ;
908906 // Resolve the function body, potentially inside the body of an async closure
909907 this. with_lifetime_rib (
910- LifetimeRibKind :: Elided ( LifetimeRes :: Anonymous { binder : fn_id } ) ,
908+ LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) ,
911909 |this| this. visit_expr ( body) ,
912910 ) ;
913911
@@ -1645,35 +1643,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
16451643
16461644 if !missing {
16471645 // Do not create a parameter for patterns and expressions.
1648- for rib in self . lifetime_ribs . iter ( ) . rev ( ) {
1649- match rib. kind {
1650- LifetimeRibKind :: Elided ( res @ LifetimeRes :: Anonymous { .. } ) => {
1651- for id in node_ids {
1652- self . record_lifetime_res ( id, res, LifetimeElisionCandidate :: Named ) ;
1653- }
1654- break ;
1655- }
1656- // `LifetimeRes::Error`, which would usually be used in the case of
1657- // `ReportError`, is unsuitable here, as we don't emit an error yet. Instead,
1658- // we simply resolve to an implicit lifetime, which will be checked later, at
1659- // which point a suitable error will be emitted.
1660- LifetimeRibKind :: AnonymousReportError | LifetimeRibKind :: Item => {
1661- // FIXME(cjgillot) This resolution is wrong, but this does not matter
1662- // since these cases are erroneous anyway. Lifetime resolution should
1663- // emit a "missing lifetime specifier" diagnostic.
1664- let res = LifetimeRes :: Anonymous { binder : DUMMY_NODE_ID } ;
1665- for id in node_ids {
1666- self . record_lifetime_res ( id, res, LifetimeElisionCandidate :: Named ) ;
1667- }
1668- break ;
1669- }
1670- LifetimeRibKind :: AnonymousCreateParameter { .. }
1671- | LifetimeRibKind :: Elided ( _)
1672- | LifetimeRibKind :: ElisionFailure
1673- | LifetimeRibKind :: Generics { .. }
1674- | LifetimeRibKind :: ConstGeneric
1675- | LifetimeRibKind :: AnonConst => { }
1676- }
1646+ for id in node_ids {
1647+ self . record_lifetime_res (
1648+ id,
1649+ LifetimeRes :: Infer ,
1650+ LifetimeElisionCandidate :: Named ,
1651+ ) ;
16771652 }
16781653 continue ;
16791654 }
@@ -1814,15 +1789,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18141789 )
18151790 }
18161791 match res {
1817- LifetimeRes :: Param { .. }
1818- | LifetimeRes :: Fresh { .. }
1819- | LifetimeRes :: Anonymous { .. }
1820- | LifetimeRes :: Static => {
1792+ LifetimeRes :: Param { .. } | LifetimeRes :: Fresh { .. } | LifetimeRes :: Static => {
18211793 if let Some ( ref mut candidates) = self . lifetime_elision_candidates {
18221794 candidates. insert ( res, candidate) ;
18231795 }
18241796 }
1825- LifetimeRes :: Error | LifetimeRes :: ElidedAnchor { .. } => { }
1797+ LifetimeRes :: Infer | LifetimeRes :: Error | LifetimeRes :: ElidedAnchor { .. } => { }
18261798 }
18271799 }
18281800
@@ -2245,26 +2217,23 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
22452217 this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Static ) , |this| {
22462218 this. visit_ty ( ty) ;
22472219 } ) ;
2248- this. with_lifetime_rib (
2249- LifetimeRibKind :: Elided ( LifetimeRes :: Anonymous { binder : item. id } ) ,
2250- |this| {
2251- if let Some ( expr) = expr {
2252- let constant_item_kind = match item. kind {
2253- ItemKind :: Const ( ..) => ConstantItemKind :: Const ,
2254- ItemKind :: Static ( ..) => ConstantItemKind :: Static ,
2255- _ => unreachable ! ( ) ,
2256- } ;
2257- // We already forbid generic params because of the above item rib,
2258- // so it doesn't matter whether this is a trivial constant.
2259- this. with_constant_rib (
2260- IsRepeatExpr :: No ,
2261- HasGenericParams :: Yes ,
2262- Some ( ( item. ident , constant_item_kind) ) ,
2263- |this| this. visit_expr ( expr) ,
2264- ) ;
2265- }
2266- } ,
2267- ) ;
2220+ this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
2221+ if let Some ( expr) = expr {
2222+ let constant_item_kind = match item. kind {
2223+ ItemKind :: Const ( ..) => ConstantItemKind :: Const ,
2224+ ItemKind :: Static ( ..) => ConstantItemKind :: Static ,
2225+ _ => unreachable ! ( ) ,
2226+ } ;
2227+ // We already forbid generic params because of the above item rib,
2228+ // so it doesn't matter whether this is a trivial constant.
2229+ this. with_constant_rib (
2230+ IsRepeatExpr :: No ,
2231+ HasGenericParams :: Yes ,
2232+ Some ( ( item. ident , constant_item_kind) ) ,
2233+ |this| this. visit_expr ( expr) ,
2234+ ) ;
2235+ }
2236+ } ) ;
22682237 } ) ;
22692238 }
22702239
@@ -2521,7 +2490,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
25212490 // Type parameters can already be used and as associated consts are
25222491 // not used as part of the type system, this is far less surprising.
25232492 self . with_lifetime_rib (
2524- LifetimeRibKind :: Elided ( LifetimeRes :: Anonymous { binder : item . id } ) ,
2493+ LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) ,
25252494 |this| {
25262495 this. with_constant_rib (
25272496 IsRepeatExpr :: No ,
@@ -2694,17 +2663,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
26942663 //
26952664 // Type parameters can already be used and as associated consts are
26962665 // not used as part of the type system, this is far less surprising.
2697- self . with_lifetime_rib (
2698- LifetimeRibKind :: Elided ( LifetimeRes :: Anonymous { binder : item. id } ) ,
2699- |this| {
2700- this. with_constant_rib (
2701- IsRepeatExpr :: No ,
2702- HasGenericParams :: Yes ,
2703- None ,
2704- |this| this. visit_expr ( expr) ,
2705- )
2706- } ,
2707- ) ;
2666+ self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
2667+ this. with_constant_rib (
2668+ IsRepeatExpr :: No ,
2669+ HasGenericParams :: Yes ,
2670+ None ,
2671+ |this| this. visit_expr ( expr) ,
2672+ )
2673+ } ) ;
27082674 }
27092675 }
27102676 AssocItemKind :: Fn ( box Fn { generics, .. } ) => {
0 commit comments