- struct_span_err!(
- tcx.sess,
- hir_ty.span,
- E0741,
- "`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the \
- type of a const parameter",
- ty,
- )
- .span_label(
- hir_ty.span,
- format!("`{}` doesn't derive both `PartialEq` and `Eq`", ty),
- )
- .emit();
+ // We use the same error code in both branches, because this is really the same
+ // issue: we just special-case the message for type parameters to make it
+ // clearer.
+ if let ty::Param(_) = ty.peel_refs().kind {
+ // Const parameters may not have type parameters as their types,
+ // because we cannot be sure that the type parameter derives `PartialEq`
+ // and `Eq` (just implementing them is not enough for `structural_match`).
+ struct_span_err!(
+ tcx.sess,
+ hir_ty.span,
+ E0741,
+ "`{}` is not guaranteed to `#[derive(PartialEq, Eq)]`, so may not be \
+ used as the type of a const parameter",
+ ty,
+ )
+ .span_label(
+ hir_ty.span,
+ format!("`{}` may not derive both `PartialEq` and `Eq`", ty),
+ )
+ .note(
+ "it is not currently possible to use a type parameter as the type of a \
+ const parameter",
+ )
+ .emit();
+ } else {
+ struct_span_err!(
+ tcx.sess,
+ hir_ty.span,
+ E0741,
+ "`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as \
+ the type of a const parameter",
+ ty,
+ )
+ .span_label(
+ hir_ty.span,
+ format!("`{}` doesn't derive both `PartialEq` and `Eq`", ty),
+ )
+ .emit();
+ }