diff options
| author | varkor <github@varkor.com> | 2020-04-06 15:12:52 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2020-04-20 12:46:27 +0100 |
| commit | 3eea7b31ee0f1afdfcbb2ece8a5445655706cd9b (patch) | |
| tree | acf9e21d2021bc876ccfd25cf9bea4127d3e12e0 | |
| parent | 8d67f576b56e8fc98a31123e5963f8d00e40611c (diff) | |
| download | rust-3eea7b31ee0f1afdfcbb2ece8a5445655706cd9b.tar.gz rust-3eea7b31ee0f1afdfcbb2ece8a5445655706cd9b.zip | |
Make the `structural_match` error diagnostic for const generics clearer
7 files changed, 9 insertions, 7 deletions
diff --git a/src/librustc_typeck/collect/type_of.rs b/src/librustc_typeck/collect/type_of.rs index e17b736058f..ddf0b247ae3 100644 --- a/src/librustc_typeck/collect/type_of.rs +++ b/src/librustc_typeck/collect/type_of.rs @@ -346,7 +346,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { tcx.sess, hir_ty.span, E0741, - "the types of const generic parameters must derive `PartialEq` and `Eq`", + "`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the \ + type of a const parameter", + ty, ) .span_label( hir_ty.span, diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs index 78bd549ba79..59bb06690a1 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; struct B<T, const N: T>(PhantomData<[T; N]>); //~ ERROR const generics are unstable -//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq` +//~^ ERROR `T` must be annotated with `#[derive(PartialEq, Eq)]` fn main() {} diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr index 14ade3f33fd..70f9fc4184c 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr @@ -7,7 +7,7 @@ LL | struct B<T, const N: T>(PhantomData<[T; N]>); = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information = help: add `#![feature(const_generics)]` to the crate attributes to enable -error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq` +error[E0741]: `T` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter --> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22 | LL | struct B<T, const N: T>(PhantomData<[T; N]>); diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs index 684ccf71082..4dcda3b87a8 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs @@ -7,6 +7,6 @@ // details. pub struct Dependent<T, const X: T>([(); X]); -//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq` +//~^ ERROR `T` must be annotated with `#[derive(PartialEq, Eq)]` fn main() {} diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr index 724e3909e45..290d53c4e19 100644 --- a/src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr @@ -6,7 +6,7 @@ LL | #![feature(const_generics)] | = note: `#[warn(incomplete_features)]` on by default -error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq` +error[E0741]: `T` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter --> $DIR/const-param-type-depends-on-type-param.rs:9:34 | LL | pub struct Dependent<T, const X: T>([(); X]); diff --git a/src/test/ui/const-generics/forbid-non-structural_match-types.rs b/src/test/ui/const-generics/forbid-non-structural_match-types.rs index 7bc4f3986eb..a30cdc3efdf 100644 --- a/src/test/ui/const-generics/forbid-non-structural_match-types.rs +++ b/src/test/ui/const-generics/forbid-non-structural_match-types.rs @@ -8,6 +8,6 @@ struct B<const X: A>; // ok struct C; -struct D<const X: C>; //~ ERROR the types of const generic parameters must derive +struct D<const X: C>; //~ ERROR `C` must be annotated with `#[derive(PartialEq, Eq)]` fn main() {} diff --git a/src/test/ui/const-generics/forbid-non-structural_match-types.stderr b/src/test/ui/const-generics/forbid-non-structural_match-types.stderr index d2469ca766e..4f343146263 100644 --- a/src/test/ui/const-generics/forbid-non-structural_match-types.stderr +++ b/src/test/ui/const-generics/forbid-non-structural_match-types.stderr @@ -6,7 +6,7 @@ LL | #![feature(const_generics)] | = note: `#[warn(incomplete_features)]` on by default -error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq` +error[E0741]: `C` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter --> $DIR/forbid-non-structural_match-types.rs:11:19 | LL | struct D<const X: C>; |
