@@ -376,23 +376,23 @@ pub trait GenericArgsLowerer<'a, 'tcx> {
376376 ) -> ty:: GenericArg < ' tcx > ;
377377}
378378
379- /// Context in which `ForbidMCGParamUsesFolder ` is being used, to emit appropriate diagnostics.
379+ /// Context in which `ForbidParamUsesFolder ` is being used, to emit appropriate diagnostics.
380380enum ForbidParamContext {
381- /// Anon const in a min- const-generics (MCG) position, e.g. a const argument .
382- MinConstGenerics ,
381+ /// Anon const in a const argument position.
382+ ConstArgument ,
383383 /// Enum discriminant expression.
384384 EnumDiscriminant ,
385385}
386386
387- struct ForbidMCGParamUsesFolder < ' tcx > {
387+ struct ForbidParamUsesFolder < ' tcx > {
388388 tcx : TyCtxt < ' tcx > ,
389389 anon_const_def_id : LocalDefId ,
390390 span : Span ,
391391 is_self_alias : bool ,
392392 context : ForbidParamContext ,
393393}
394394
395- impl < ' tcx > ForbidMCGParamUsesFolder < ' tcx > {
395+ impl < ' tcx > ForbidParamUsesFolder < ' tcx > {
396396 fn error ( & self ) -> ErrorGuaranteed {
397397 let msg = match self . context {
398398 ForbidParamContext :: EnumDiscriminant if self . is_self_alias => {
@@ -401,10 +401,10 @@ impl<'tcx> ForbidMCGParamUsesFolder<'tcx> {
401401 ForbidParamContext :: EnumDiscriminant => {
402402 "generic parameters may not be used in enum discriminant values"
403403 }
404- ForbidParamContext :: MinConstGenerics if self . is_self_alias => {
404+ ForbidParamContext :: ConstArgument if self . is_self_alias => {
405405 "generic `Self` types are currently not permitted in anonymous constants"
406406 }
407- ForbidParamContext :: MinConstGenerics => {
407+ ForbidParamContext :: ConstArgument => {
408408 if self . tcx . features ( ) . opaque_generic_const_args ( ) {
409409 "generic parameters in const blocks are only allowed as the direct value of a `type const`"
410410 } else {
@@ -413,7 +413,7 @@ impl<'tcx> ForbidMCGParamUsesFolder<'tcx> {
413413 }
414414 } ;
415415 let mut diag = self . tcx . dcx ( ) . struct_span_err ( self . span , msg) ;
416- if self . is_self_alias && matches ! ( self . context, ForbidParamContext :: MinConstGenerics ) {
416+ if self . is_self_alias && matches ! ( self . context, ForbidParamContext :: ConstArgument ) {
417417 let anon_const_hir_id: HirId = HirId :: make_owner ( self . anon_const_def_id ) ;
418418 let parent_impl = self . tcx . hir_parent_owner_iter ( anon_const_hir_id) . find_map (
419419 |( _, node) | match node {
@@ -427,7 +427,7 @@ impl<'tcx> ForbidMCGParamUsesFolder<'tcx> {
427427 diag. span_note ( impl_. self_ty . span , "not a concrete type" ) ;
428428 }
429429 }
430- if matches ! ( self . context, ForbidParamContext :: MinConstGenerics )
430+ if matches ! ( self . context, ForbidParamContext :: ConstArgument )
431431 && self . tcx . features ( ) . min_generic_const_args ( )
432432 {
433433 if !self . tcx . features ( ) . opaque_generic_const_args ( ) {
@@ -440,7 +440,7 @@ impl<'tcx> ForbidMCGParamUsesFolder<'tcx> {
440440 }
441441}
442442
443- impl < ' tcx > ty:: TypeFolder < TyCtxt < ' tcx > > for ForbidMCGParamUsesFolder < ' tcx > {
443+ impl < ' tcx > ty:: TypeFolder < TyCtxt < ' tcx > > for ForbidParamUsesFolder < ' tcx > {
444444 fn cx ( & self ) -> TyCtxt < ' tcx > {
445445 self . tcx
446446 }
@@ -482,21 +482,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
482482 && tcx. def_kind ( parent_def_id) == DefKind :: AnonConst
483483 && let ty:: AnonConstKind :: MCG = tcx. anon_const_kind ( parent_def_id)
484484 {
485- let folder = ForbidMCGParamUsesFolder {
485+ let folder = ForbidParamUsesFolder {
486486 tcx,
487487 anon_const_def_id : parent_def_id,
488488 span,
489489 is_self_alias : false ,
490- context : ForbidParamContext :: MinConstGenerics ,
490+ context : ForbidParamContext :: ConstArgument ,
491491 } ;
492492 return Err ( folder. error ( ) ) ;
493493 }
494494 Ok ( ( ) )
495495 }
496496
497497 /// Returns the `ForbidParamContext` for the current anon const if it is a context that
498- /// forbids uses of generic parameters that escape through type-dependent paths (e.g. `Self`
499- /// aliasing a generic type), or `None` if the current item is not such a context.
498+ /// forbids uses of generic parameters. `None` if the current item is not such a context.
500499 ///
501500 /// Name resolution handles most invalid generic parameter uses in these contexts, but it
502501 /// cannot reject `Self` that aliases a generic type, nor generic parameters introduced by
@@ -509,13 +508,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
509508 return None ;
510509 }
511510 match tcx. anon_const_kind ( parent_def_id) {
512- ty:: AnonConstKind :: MCG => Some ( ForbidParamContext :: MinConstGenerics ) ,
511+ ty:: AnonConstKind :: MCG => Some ( ForbidParamContext :: ConstArgument ) ,
513512 ty:: AnonConstKind :: NonTypeSystem => {
514513 let hir_id = tcx. local_def_id_to_hir_id ( parent_def_id) ;
515514 matches ! ( tcx. parent_hir_node( hir_id) , hir:: Node :: Variant ( _) )
516515 . then_some ( ForbidParamContext :: EnumDiscriminant )
517516 }
518- _ => None ,
517+ ty :: AnonConstKind :: GCE | ty :: AnonConstKind :: OGCA | ty :: AnonConstKind :: RepeatExprCount => None ,
519518 }
520519 }
521520
@@ -530,13 +529,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
530529 T : ty:: TypeFoldable < TyCtxt < ' tcx > > ,
531530 {
532531 let tcx = self . tcx ( ) ;
533- let anon_const_def_id = self . item_def_id ( ) ;
534532 if let Some ( context) = self . anon_const_forbids_generic_params ( )
535533 // Fast path if contains no params/escaping bound vars.
536534 && ( term. has_param ( ) || term. has_escaping_bound_vars ( ) )
537535 {
536+ let anon_const_def_id = self . item_def_id ( ) ;
538537 let mut folder =
539- ForbidMCGParamUsesFolder { tcx, anon_const_def_id, span, is_self_alias, context } ;
538+ ForbidParamUsesFolder { tcx, anon_const_def_id, span, is_self_alias, context } ;
540539 term. fold_with ( & mut folder)
541540 } else {
542541 term
0 commit comments