Error message when using non-derived constants from another crate in pattern matching is confusing #42753
Open
Description
opened on Jun 19, 2017
The error message is perfectly fine when inside the crate that has the type, because changing or adding a derive(PartialEq, Eq)
is something you can control.
error: to use a constant of type `mime::Mime` in a pattern, `mime::Mime` must be annotated with `#[derive(PartialEq, Eq)]`
--> src/main.rs:187:39
|
187 | Some(&ContentType(mime::TEXT_XML)) => (),
| ^^^^^^^^^^^^^^
However, when the type isn't in your crate, the message makes the user think the other crate simply "forgot" to implement PartialEq
, and there is nothing for them to do. A suggestion would be to change the error message when the type is not a crate-local, and add a note of how to fix it.
error: a constant of type `mime::Mime` cannot be used in a pattern
--> src/main.rs:187:39
|
187 | Some(&ContentType(mime::TEXT_XML)) => (),
| ^^^^^^^^^^^^^^
|
= note: try pattern guards insteand: `Some(&ContentType(ref a)) if a == &mime::TEXT_XML => (),`
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsRelating to patterns and pattern matchingCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity