Skip to content

Error message when using non-derived constants from another crate in pattern matching is confusing #42753

Open
@seanmonstar

Description

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 => (),`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-patternsRelating to patterns and pattern matchingC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions