Skip to content

expected &someEnum but found an enum or structure pattern is misleading #7867

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

Closed
ozten opened this issue Jul 18, 2013 · 4 comments · Fixed by #18324
Closed

expected &someEnum but found an enum or structure pattern is misleading #7867

ozten opened this issue Jul 18, 2013 · 4 comments · Fixed by #18324
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@ozten
Copy link
Contributor

ozten commented Jul 18, 2013

I've had a hard time learning match because this error message is misleading.

Steps to reproduce:

  1. Compile a small program which uses extra::json with
match value {
    Number(n) => {
        println(fmt!("%?\n", n))
    },
    _ => {
        println(~"Doh")
    }
}
  1. Note compiler error

Actual:

json.rs:20:25: 20:34 error: mismatched types: expected `&extra::json::Json` but found an enum or structure pattern
json.rs:20                          Number(n) => {
                                    ^~~~~~~~~
error: aborting due to previous error

Expected:

error: mismatched types: expected `&extra::json::Json` but found enum extra::json::Json

or more generally
expected &someEnum but found enum T

Great work on the rest of the error message, BTW. I like the line number and arrow.

I eventually figured out that Number is an enum value of extra::json::Json and the fix is:

match value {
    & Number(n) => {
        println(fmt!("%?\n", n))
    },
    _ => {
        println(~"Doh")
    }
}
@bblum
Copy link
Contributor

bblum commented Jul 18, 2013

This particular error comes up a lot for me too. It would be cool to have rustc emit a span_note for this special case saying "you probably missed a & in your pattern" or something.

@catamorphism
Copy link
Contributor

(bug triage) I agree that the error message should be improved; not a milestone blocker IMO.

@flaper87
Copy link
Contributor

Triage bump

Here's an test case:

enum A { B, C }

fn main() {
    match (true, false) {
        B => (),
        _ => ()
    }
}
issue-7867.rs:5:9: 5:10 error: mismatched types: expected `(bool,bool)` but found an enum or structure pattern
issue-7867.rs:5         B => (),
                        ^
error: aborting due to previous error

@Valve
Copy link

Valve commented Sep 4, 2014

cc me, this error comes up a lot

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 25, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 4, 2021
Fix typo on utils/lib

Found some typo when looking through `clippy_utils/src/lib.rs` 🙂

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants