@@ -450,14 +450,20 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
450450 self . lower_ty_ext ( type_ref) . 0
451451 }
452452
453- pub ( crate ) fn lower_const ( & mut self , const_ref : ConstRef , const_type : Ty < ' db > ) -> Const < ' db > {
454- self . lower_expr_as_const ( const_ref. expr , const_type)
453+ pub ( crate ) fn lower_const (
454+ & mut self ,
455+ const_ref : ConstRef ,
456+ const_type : Ty < ' db > ,
457+ allow_anon_const_using_generic_params : bool ,
458+ ) -> Const < ' db > {
459+ self . lower_expr_as_const ( const_ref. expr , const_type, allow_anon_const_using_generic_params)
455460 }
456461
457462 pub ( crate ) fn lower_expr_as_const (
458463 & mut self ,
459464 expr_id : ExprId ,
460465 const_type : Ty < ' db > ,
466+ allow_anon_const_using_generic_params : bool ,
461467 ) -> Const < ' db > {
462468 #[ expect( clippy:: manual_map, reason = "a `map()` here generates a borrowck error" ) ]
463469 let create_var = match & mut self . infer_vars {
@@ -477,6 +483,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
477483 create_var,
478484 self . interning_mode ,
479485 self . forbid_params_after ,
486+ allow_anon_const_using_generic_params,
480487 ) ;
481488
482489 if let Ok ( konst) = konst
@@ -603,7 +610,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
603610 }
604611 TypeRef :: Array ( array) => {
605612 let inner_ty = self . lower_ty ( array. ty ) ;
606- let const_len = self . lower_const ( array. len , self . types . types . usize ) ;
613+ let const_len = self . lower_const ( array. len , self . types . types . usize , false ) ;
607614 Ty :: new_array_with_const_len ( interner, inner_ty, const_len)
608615 }
609616 & TypeRef :: Slice ( inner) => {
@@ -729,9 +736,12 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> {
729736 fn lower_pattern_type ( & mut self , pat : PatId , ty : Ty < ' db > ) -> Option < Pattern < ' db > > {
730737 let pat_kind = match self . store [ pat] {
731738 hir_def:: hir:: Pat :: Range { start : Some ( start) , end : Some ( end) , range_type : _ } => {
739+ // rustc allows using generic params in pattern types.
740+ // In practice this does not matter since this feature is internal and I didn't find a way to actually use generic params,
741+ // but it doesn't matter so...
732742 rustc_type_ir:: PatternKind :: Range {
733- start : self . lower_expr_as_const ( start, ty) ,
734- end : self . lower_expr_as_const ( end, ty) ,
743+ start : self . lower_expr_as_const ( start, ty, true ) ,
744+ end : self . lower_expr_as_const ( end, ty, true ) ,
735745 }
736746 }
737747 hir_def:: hir:: Pat :: NotNull => rustc_type_ir:: PatternKind :: NotNull ,
@@ -1975,7 +1985,7 @@ pub(crate) fn field_types_with_diagnostics<'db>(
19751985 ) ;
19761986 for ( field_id, field_data) in var_data. fields ( ) . iter ( ) {
19771987 let ty = ctx. lower_ty ( field_data. type_ref ) ;
1978- let default = field_data. default_value . map ( |default| ctx. lower_const ( default, ty) ) ;
1988+ let default = field_data. default_value . map ( |default| ctx. lower_const ( default, ty, true ) ) ;
19791989 res. insert (
19801990 field_id,
19811991 FieldType {
@@ -3012,7 +3022,7 @@ pub(crate) fn generic_defaults_with_diagnostics<'db>(
30123022 GenericParamDataRef :: ConstParamData ( p) => {
30133023 let val = p. default . map ( |c| {
30143024 let param_ty = ctx. lower_ty ( p. ty ) ;
3015- let c = ctx. lower_const ( c, param_ty) ;
3025+ let c = ctx. lower_const ( c, param_ty, false ) ;
30163026 GenericArg :: from ( c) . store ( )
30173027 } ) ;
30183028 val. map ( StoredEarlyBinder :: bind)
0 commit comments