@@ -850,9 +850,10 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
850850 // Const parameters are well formed if their type is structural match.
851851 hir:: GenericParamKind :: Const { ty : hir_ty, default : _ } => {
852852 let ty = tcx. type_of ( param. def_id ) . instantiate_identity ( ) ;
853+ enter_wf_checking_ctxt ( tcx, hir_ty. span , param. def_id , |wfcx| {
854+ let ty = wfcx. normalize ( hir_ty. span , Some ( WellFormedLoc :: Ty ( param. def_id ) ) , ty) ;
853855
854- if tcx. features ( ) . adt_const_params {
855- enter_wf_checking_ctxt ( tcx, hir_ty. span , param. def_id , |wfcx| {
856+ if tcx. features ( ) . adt_const_params {
856857 let trait_def_id =
857858 tcx. require_lang_item ( LangItem :: ConstParamTy , Some ( hir_ty. span ) ) ;
858859 wfcx. register_bound (
@@ -865,47 +866,47 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
865866 ty,
866867 trait_def_id,
867868 ) ;
868- } ) ;
869- } else {
870- let err_ty_str;
871- let mut is_ptr = true ;
872-
873- let err = match ty. kind ( ) {
874- ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Error ( _) => None ,
875- ty:: FnPtr ( _) => Some ( "function pointers" ) ,
876- ty:: RawPtr ( _) => Some ( "raw pointers" ) ,
877- _ => {
878- is_ptr = false ;
879- err_ty_str = format ! ( "`{ty}`" ) ;
880- Some ( err_ty_str. as_str ( ) )
881- }
882- } ;
883-
884- if let Some ( unsupported_type) = err {
885- if is_ptr {
886- tcx. sess . span_err (
887- hir_ty. span ,
888- format ! (
889- "using {unsupported_type} as const generic parameters is forbidden" ,
890- ) ,
891- ) ;
892- } else {
893- let mut err = tcx. sess . struct_span_err (
894- hir_ty. span ,
895- format ! (
896- "{unsupported_type} is forbidden as the type of a const generic parameter" ,
897- ) ,
898- ) ;
899- err. note ( "the only supported types are integers, `bool` and `char`" ) ;
900- if tcx. sess . is_nightly_build ( ) {
901- err. help (
902- "more complex types are supported with `#![feature(adt_const_params)]`" ,
903- ) ;
869+ } else {
870+ let err_ty_str;
871+ let mut is_ptr = true ;
872+
873+ let err = match ty. kind ( ) {
874+ ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) | ty:: Error ( _) => None ,
875+ ty:: FnPtr ( _) => Some ( "function pointers" ) ,
876+ ty:: RawPtr ( _) => Some ( "raw pointers" ) ,
877+ _ => {
878+ is_ptr = false ;
879+ err_ty_str = format ! ( "`{ty}`" ) ;
880+ Some ( err_ty_str. as_str ( ) )
881+ }
882+ } ;
883+
884+ if let Some ( unsupported_type) = err {
885+ if is_ptr {
886+ tcx. sess . span_err (
887+ hir_ty. span ,
888+ format ! (
889+ "using {unsupported_type} as const generic parameters is forbidden" ,
890+ ) ,
891+ ) ;
892+ } else {
893+ let mut err = tcx. sess . struct_span_err (
894+ hir_ty. span ,
895+ format ! (
896+ "{unsupported_type} is forbidden as the type of a const generic parameter" ,
897+ ) ,
898+ ) ;
899+ err. note ( "the only supported types are integers, `bool` and `char`" ) ;
900+ if tcx. sess . is_nightly_build ( ) {
901+ err. help (
902+ "more complex types are supported with `#![feature(adt_const_params)]`" ,
903+ ) ;
904+ }
905+ err. emit ( ) ;
904906 }
905- err. emit ( ) ;
906907 }
907908 }
908- }
909+ } ) ;
909910 }
910911 }
911912}
0 commit comments