@@ -204,6 +204,11 @@ enum LifetimeRibKind {
204
204
/// lifetimes in const generics. See issue #74052 for discussion.
205
205
ConstGeneric ,
206
206
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
+
207
212
/// For **Modern** cases, create a new anonymous region parameter
208
213
/// and reference that.
209
214
///
@@ -532,7 +537,9 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
532
537
}
533
538
fn visit_anon_const ( & mut self , constant : & ' ast AnonConst ) {
534
539
// 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
+ } )
536
543
}
537
544
fn visit_expr ( & mut self , expr : & ' ast Expr ) {
538
545
self . resolve_expr ( expr, None ) ;
@@ -1117,7 +1124,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1117
1124
this. ribs [ TypeNS ] . push ( forward_ty_ban_rib) ;
1118
1125
this. ribs [ ValueNS ] . push ( forward_const_ban_rib) ;
1119
1126
this. with_lifetime_rib ( LifetimeRibKind :: ConstGeneric , |this| {
1120
- this. visit_anon_const ( expr)
1127
+ this. resolve_anon_const ( expr, IsRepeatExpr :: No )
1121
1128
} ) ;
1122
1129
forward_const_ban_rib = this. ribs [ ValueNS ] . pop ( ) . unwrap ( ) ;
1123
1130
forward_ty_ban_rib = this. ribs [ TypeNS ] . pop ( ) . unwrap ( ) ;
@@ -1174,6 +1181,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1174
1181
self . r . lifetimes_res_map . insert ( lifetime. id , LifetimeRes :: Error ) ;
1175
1182
return ;
1176
1183
}
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
+ }
1177
1189
_ => { }
1178
1190
}
1179
1191
}
@@ -3076,9 +3088,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
3076
3088
is_repeat,
3077
3089
constant. value . is_potential_trivial_const_param ( ) ,
3078
3090
None ,
3079
- |this| {
3080
- visit:: walk_anon_const ( this, constant) ;
3081
- } ,
3091
+ |this| visit:: walk_anon_const ( this, constant) ,
3082
3092
) ;
3083
3093
}
3084
3094
@@ -3229,7 +3239,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
3229
3239
}
3230
3240
ExprKind :: Repeat ( ref elem, ref ct) => {
3231
3241
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 ) ;
3233
3248
}
3234
3249
ExprKind :: Index ( ref elem, ref idx) => {
3235
3250
self . resolve_expr ( elem, Some ( expr) ) ;
0 commit comments