Skip to content

Misleading message when calling a method inside match arms  #112656

Closed as not planned
@meppu

Description

@meppu

Code

enum Example {
    First(String),
    Other(String)
}


fn main() {
    let a = Example::First("wow".into());
    
    match a {
        Example::First("wow".into()) => unreachable!(),
        _ => {
            println!(":)");
        }
    }
}

Current output

Compiling playground v0.0.1 (/playground)
error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found `.`
  --> src/main.rs:11:29
   |
11 |         Example::First("wow".into()) => unreachable!(),
   |                             ^
   |                             |
   |                             expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
   |                             help: missing `,`

error[E0531]: cannot find tuple struct or tuple variant `into` in this scope
  --> src/main.rs:11:30
   |
11 |         Example::First("wow".into()) => unreachable!(),
   |                              ^^^^ not found in this scope

error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field
  --> src/main.rs:11:24
   |
2  |     First(String),
   |           ------ tuple variant has 1 field
...
11 |         Example::First("wow".into()) => unreachable!(),
   |                        ^^^^^ ^^^^^^ expected 1 field, found 2

Some errors have detailed explanations: E0023, E0531.
For more information about an error, try `rustc --explain E0023`.
error: could not compile `playground` (bin "playground") due to 3 previous errors

Desired output

error[EXXXX]: expected tuple struct or tuple variant, found method call `into`
  --> src/main.rs:11:24
   |
11 |         Example::First("wow".into()) => unreachable!(),
   |                        ^^^^^^^^^^^^ `fn` calls are not allowed in patterns
   |
   = help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html

Rationale and extra context

Playground link

(updated playground link)

Other cases

No response

Anything else?

I gave an example desired output, but i think it can be better.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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