@@ -829,83 +829,20 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
829
829
let ty = tcx. type_of ( param. def_id ) . subst_identity ( ) ;
830
830
831
831
if tcx. features ( ) . adt_const_params {
832
- if let Some ( non_structural_match_ty) =
833
- traits:: search_for_adt_const_param_violation ( param. span , tcx, ty)
834
- {
835
- // We use the same error code in both branches, because this is really the same
836
- // issue: we just special-case the message for type parameters to make it
837
- // clearer.
838
- match non_structural_match_ty. kind ( ) {
839
- ty:: Param ( _) => {
840
- // Const parameters may not have type parameters as their types,
841
- // because we cannot be sure that the type parameter derives `PartialEq`
842
- // and `Eq` (just implementing them is not enough for `structural_match`).
843
- struct_span_err ! (
844
- tcx. sess,
845
- hir_ty. span,
846
- E0741 ,
847
- "`{ty}` is not guaranteed to `#[derive(PartialEq, Eq)]`, so may not be \
848
- used as the type of a const parameter",
849
- )
850
- . span_label (
851
- hir_ty. span ,
852
- format ! ( "`{ty}` may not derive both `PartialEq` and `Eq`" ) ,
853
- )
854
- . note (
855
- "it is not currently possible to use a type parameter as the type of a \
856
- const parameter",
857
- )
858
- . emit ( ) ;
859
- }
860
- ty:: Float ( _) => {
861
- struct_span_err ! (
862
- tcx. sess,
863
- hir_ty. span,
864
- E0741 ,
865
- "`{ty}` is forbidden as the type of a const generic parameter" ,
866
- )
867
- . note ( "floats do not derive `Eq` or `Ord`, which are required for const parameters" )
868
- . emit ( ) ;
869
- }
870
- ty:: FnPtr ( _) => {
871
- struct_span_err ! (
872
- tcx. sess,
873
- hir_ty. span,
874
- E0741 ,
875
- "using function pointers as const generic parameters is forbidden" ,
876
- )
877
- . emit ( ) ;
878
- }
879
- ty:: RawPtr ( _) => {
880
- struct_span_err ! (
881
- tcx. sess,
882
- hir_ty. span,
883
- E0741 ,
884
- "using raw pointers as const generic parameters is forbidden" ,
885
- )
886
- . emit ( ) ;
887
- }
888
- _ => {
889
- let mut diag = struct_span_err ! (
890
- tcx. sess,
891
- hir_ty. span,
892
- E0741 ,
893
- "`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as \
894
- the type of a const parameter",
895
- non_structural_match_ty,
896
- ) ;
897
-
898
- if ty == non_structural_match_ty {
899
- diag. span_label (
900
- hir_ty. span ,
901
- format ! ( "`{ty}` doesn't derive both `PartialEq` and `Eq`" ) ,
902
- ) ;
903
- }
904
-
905
- diag. emit ( ) ;
906
- }
907
- }
908
- }
832
+ enter_wf_checking_ctxt ( tcx, hir_ty. span , param. def_id , |wfcx| {
833
+ let trait_def_id =
834
+ tcx. require_lang_item ( LangItem :: ConstParamTy , Some ( hir_ty. span ) ) ;
835
+ wfcx. register_bound (
836
+ ObligationCause :: new (
837
+ hir_ty. span ,
838
+ param. def_id ,
839
+ ObligationCauseCode :: WellFormed ( Some ( hir_ty. span ) ) ,
840
+ ) ,
841
+ wfcx. param_env ,
842
+ ty,
843
+ trait_def_id,
844
+ ) ;
845
+ } ) ;
909
846
} else {
910
847
let err_ty_str;
911
848
let mut is_ptr = true ;
0 commit comments