Skip to content

Misleading message when calling a method inside match arms #112656

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
meppu opened this issue Jun 15, 2023 · 3 comments
Closed

Misleading message when calling a method inside match arms #112656

meppu opened this issue Jun 15, 2023 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@meppu
Copy link

meppu commented Jun 15, 2023

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.

@meppu meppu added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 15, 2023
@meppu
Copy link
Author

meppu commented Jun 15, 2023

cc @compiler-errors

@StripedMonkey
Copy link

This is identical to #112593

@meppu
Copy link
Author

meppu commented Jun 18, 2023

Then closing it.

@meppu meppu closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants