@@ -824,50 +824,62 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
824
824
}
825
825
826
826
if let Some ( non_structural_match_ty) =
827
- traits:: search_for_structural_match_violation ( param. span , tcx, ty)
827
+ traits:: search_for_structural_match_violation ( param. span , tcx, ty, false )
828
828
{
829
829
// We use the same error code in both branches, because this is really the same
830
830
// issue: we just special-case the message for type parameters to make it
831
831
// clearer.
832
- if let ty:: Param ( _) = ty. peel_refs ( ) . kind ( ) {
833
- // Const parameters may not have type parameters as their types,
834
- // because we cannot be sure that the type parameter derives `PartialEq`
835
- // and `Eq` (just implementing them is not enough for `structural_match`).
836
- struct_span_err ! (
837
- tcx. sess,
838
- hir_ty. span,
839
- E0741 ,
840
- "`{}` is not guaranteed to `#[derive(PartialEq, Eq)]`, so may not be \
841
- used as the type of a const parameter",
842
- ty,
843
- )
844
- . span_label (
845
- hir_ty. span ,
846
- format ! ( "`{}` may not derive both `PartialEq` and `Eq`" , ty) ,
847
- )
848
- . note (
849
- "it is not currently possible to use a type parameter as the type of a \
850
- const parameter",
851
- )
852
- . emit ( ) ;
853
- } else {
854
- let mut diag = struct_span_err ! (
855
- tcx. sess,
856
- hir_ty. span,
857
- E0741 ,
858
- "`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as \
859
- the type of a const parameter",
860
- non_structural_match_ty. ty,
861
- ) ;
862
-
863
- if ty == non_structural_match_ty. ty {
864
- diag. span_label (
832
+ match ty. peel_refs ( ) . kind ( ) {
833
+ ty:: Param ( _) => {
834
+ // Const parameters may not have type parameters as their types,
835
+ // because we cannot be sure that the type parameter derives `PartialEq`
836
+ // and `Eq` (just implementing them is not enough for `structural_match`).
837
+ struct_span_err ! (
838
+ tcx. sess,
865
839
hir_ty. span,
866
- format ! ( "`{ty}` doesn't derive both `PartialEq` and `Eq`" ) ,
867
- ) ;
840
+ E0741 ,
841
+ "`{ty}` is not guaranteed to `#[derive(PartialEq, Eq)]`, so may not be \
842
+ used as the type of a const parameter",
843
+ )
844
+ . span_label (
845
+ hir_ty. span ,
846
+ format ! ( "`{ty}` may not derive both `PartialEq` and `Eq`" ) ,
847
+ )
848
+ . note (
849
+ "it is not currently possible to use a type parameter as the type of a \
850
+ const parameter",
851
+ )
852
+ . emit ( ) ;
853
+ }
854
+ ty:: Float ( _) => {
855
+ struct_span_err ! (
856
+ tcx. sess,
857
+ hir_ty. span,
858
+ E0741 ,
859
+ "`{ty}` is forbidden as the type of a const generic parameter" ,
860
+ )
861
+ . note ( "floats do not derive `Eq` or `Ord`, which are required for const parameters" )
862
+ . emit ( ) ;
868
863
}
864
+ _ => {
865
+ let mut diag = struct_span_err ! (
866
+ tcx. sess,
867
+ hir_ty. span,
868
+ E0741 ,
869
+ "`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as \
870
+ the type of a const parameter",
871
+ non_structural_match_ty. ty,
872
+ ) ;
869
873
870
- diag. emit ( ) ;
874
+ if ty == non_structural_match_ty. ty {
875
+ diag. span_label (
876
+ hir_ty. span ,
877
+ format ! ( "`{ty}` doesn't derive both `PartialEq` and `Eq`" ) ,
878
+ ) ;
879
+ }
880
+
881
+ diag. emit ( ) ;
882
+ }
871
883
}
872
884
}
873
885
} else {
0 commit comments