Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the structural_match error diagnostic for const generics clearer #70845

Merged
merged 2 commits into from
Apr 24, 2020

Conversation

varkor
Copy link
Member

@varkor varkor commented Apr 6, 2020

The previous diagnostic caused confusion (#70790), so this changes the message to be closer to the message for using non-structural_match constants in patterns, explicitly mentioning #[derive(PartialEq, Eq)].

Fixes #70790.

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2020
@varkor varkor added the F-const_generics `#![feature(const_generics)]` label Apr 6, 2020
@joelpalmer joelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 14, 2020
@JohnTitor
Copy link
Member

Ping from triage: @estebank could you review this?

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this fell through the cracks of my notifications.

It looks good. Left a nitpick, but r=me if you don't wish to fix it.

Comment on lines 10 to 13
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]>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if we could detect that T is a type param and instead of suggesting the annotation we suggested binding it with PartialEq + Eq.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, actually we ought to emit a specific error for this case: we don't currently accept using generic parameters as the types of const generics yet.

@varkor varkor force-pushed the const-generics-derive-eq-diagnostic branch from 1e51940 to f8b796b Compare April 20, 2020 13:02
@varkor
Copy link
Member Author

varkor commented Apr 20, 2020

@estebank: I've added a specific message for the case you highlighted.

@estebank
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Apr 23, 2020

📌 Commit f8b796b has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 23, 2020
…gnostic, r=estebank

Make the `structural_match` error diagnostic for const generics clearer

The previous diagnostic caused confusion (rust-lang#70790), so this changes the message to be closer to the message for using non-`structural_match` constants in patterns, explicitly mentioning `#[derive(PartialEq, Eq)]`.

Fixes rust-lang#70790.

r? @estebank
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 24, 2020
Rollup of 6 pull requests

Successful merges:

 - rust-lang#70845 (Make the `structural_match` error diagnostic for const generics clearer)
 - rust-lang#71063 (Document unsafety in core::{option, hash})
 - rust-lang#71068 (Stabilize UNICODE_VERSION (feature unicode_version))
 - rust-lang#71426 (fix error code in E0751.md)
 - rust-lang#71459 (Add leading 0x to offset in Debug fmt of Pointer)
 - rust-lang#71492 (Document unsafety in core::{panicking, alloc::layout, hint, iter::adapters::zip})

Failed merges:

r? @ghost
@bors bors merged commit 45e04fe into rust-lang:master Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_generics `#![feature(const_generics)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Const generics: T doesn't derive both PartialEq and Eq
6 participants