Skip to content

Commit

Permalink
Make the structural_match error diagnostic for const generics clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Apr 20, 2020
1 parent 8d67f57 commit 3eea7b3
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/librustc_typeck/collect/type_of.rs
Expand Up @@ -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,
Expand Down
@@ -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() {}
Expand Up @@ -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]>);
Expand Down
Expand Up @@ -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() {}
Expand Up @@ -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]);
Expand Down
Expand Up @@ -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() {}
Expand Up @@ -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>;
Expand Down

0 comments on commit 3eea7b3

Please sign in to comment.