@@ -204,6 +204,11 @@ enum LifetimeRibKind {
204204 /// lifetimes in const generics. See issue #74052 for discussion.
205205 ConstGeneric ,
206206
207+ /// Non-static lifetimes are prohibited in anonymous constants under `min_const_generics`.
208+ /// This function will emit an error if `generic_const_exprs` is not enabled, the body identified by
209+ /// `body_id` is an anonymous constant and `lifetime_ref` is non-static.
210+ AnonConst ,
211+
207212 /// For **Modern** cases, create a new anonymous region parameter
208213 /// and reference that.
209214 ///
@@ -532,7 +537,9 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
532537 }
533538 fn visit_anon_const ( & mut self , constant : & ' ast AnonConst ) {
534539 // We deal with repeat expressions explicitly in `resolve_expr`.
535- self . resolve_anon_const ( constant, IsRepeatExpr :: No ) ;
540+ self . with_lifetime_rib ( LifetimeRibKind :: AnonConst , |this| {
541+ this. resolve_anon_const ( constant, IsRepeatExpr :: No ) ;
542+ } )
536543 }
537544 fn visit_expr ( & mut self , expr : & ' ast Expr ) {
538545 self . resolve_expr ( expr, None ) ;
@@ -1117,7 +1124,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11171124 this. ribs [ TypeNS ] . push ( forward_ty_ban_rib) ;
11181125 this. ribs [ ValueNS ] . push ( forward_const_ban_rib) ;
11191126 this. with_lifetime_rib ( LifetimeRibKind :: ConstGeneric , |this| {
1120- this. visit_anon_const ( expr)
1127+ this. resolve_anon_const ( expr, IsRepeatExpr :: No )
11211128 } ) ;
11221129 forward_const_ban_rib = this. ribs [ ValueNS ] . pop ( ) . unwrap ( ) ;
11231130 forward_ty_ban_rib = this. ribs [ TypeNS ] . pop ( ) . unwrap ( ) ;
@@ -1174,6 +1181,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11741181 self . r . lifetimes_res_map . insert ( lifetime. id , LifetimeRes :: Error ) ;
11751182 return ;
11761183 }
1184+ LifetimeRibKind :: AnonConst => {
1185+ self . maybe_emit_forbidden_non_static_lifetime_error ( lifetime) ;
1186+ self . r . lifetimes_res_map . insert ( lifetime. id , LifetimeRes :: Error ) ;
1187+ return ;
1188+ }
11771189 _ => { }
11781190 }
11791191 }
@@ -3076,9 +3088,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
30763088 is_repeat,
30773089 constant. value . is_potential_trivial_const_param ( ) ,
30783090 None ,
3079- |this| {
3080- visit:: walk_anon_const ( this, constant) ;
3081- } ,
3091+ |this| visit:: walk_anon_const ( this, constant) ,
30823092 ) ;
30833093 }
30843094
@@ -3229,7 +3239,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
32293239 }
32303240 ExprKind :: Repeat ( ref elem, ref ct) => {
32313241 self . visit_expr ( elem) ;
3232- self . resolve_anon_const ( ct, IsRepeatExpr :: Yes ) ;
3242+ self . with_lifetime_rib ( LifetimeRibKind :: AnonConst , |this| {
3243+ this. resolve_anon_const ( ct, IsRepeatExpr :: Yes )
3244+ } ) ;
3245+ }
3246+ ExprKind :: ConstBlock ( ref ct) => {
3247+ self . resolve_anon_const ( ct, IsRepeatExpr :: No ) ;
32333248 }
32343249 ExprKind :: Index ( ref elem, ref idx) => {
32353250 self . resolve_expr ( elem, Some ( expr) ) ;
0 commit comments