Skip to content

Commit 3eea7b3

Browse files
committed
Make the structural_match error diagnostic for const generics clearer
1 parent 8d67f57 commit 3eea7b3

7 files changed

+9
-7
lines changed

src/librustc_typeck/collect/type_of.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
346346
tcx.sess,
347347
hir_ty.span,
348348
E0741,
349-
"the types of const generic parameters must derive `PartialEq` and `Eq`",
349+
"`{}` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the \
350+
type of a const parameter",
351+
ty,
350352
)
351353
.span_label(
352354
hir_ty.span,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::marker::PhantomData;
22

33
struct B<T, const N: T>(PhantomData<[T; N]>); //~ ERROR const generics are unstable
4-
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq`
4+
//~^ ERROR `T` must be annotated with `#[derive(PartialEq, Eq)]`
55

66
fn main() {}

src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | struct B<T, const N: T>(PhantomData<[T; N]>);
77
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
88
= help: add `#![feature(const_generics)]` to the crate attributes to enable
99

10-
error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq`
10+
error[E0741]: `T` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
1111
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22
1212
|
1313
LL | struct B<T, const N: T>(PhantomData<[T; N]>);

src/test/ui/const-generics/const-param-type-depends-on-type-param.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
// details.
88

99
pub struct Dependent<T, const X: T>([(); X]);
10-
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq`
10+
//~^ ERROR `T` must be annotated with `#[derive(PartialEq, Eq)]`
1111

1212
fn main() {}

src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9-
error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq`
9+
error[E0741]: `T` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
1010
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
1111
|
1212
LL | pub struct Dependent<T, const X: T>([(); X]);

src/test/ui/const-generics/forbid-non-structural_match-types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ struct B<const X: A>; // ok
88

99
struct C;
1010

11-
struct D<const X: C>; //~ ERROR the types of const generic parameters must derive
11+
struct D<const X: C>; //~ ERROR `C` must be annotated with `#[derive(PartialEq, Eq)]`
1212

1313
fn main() {}

src/test/ui/const-generics/forbid-non-structural_match-types.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9-
error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq`
9+
error[E0741]: `C` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
1010
--> $DIR/forbid-non-structural_match-types.rs:11:19
1111
|
1212
LL | struct D<const X: C>;

0 commit comments

Comments
 (0)