Skip to content
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

Bad error message on returning match with incompatible match arms #24568

Closed
Binero opened this issue Apr 18, 2015 · 1 comment
Closed

Bad error message on returning match with incompatible match arms #24568

Binero opened this issue Apr 18, 2015 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@Binero
Copy link
Contributor

Binero commented Apr 18, 2015

When returning the result of a match expression with incompatible arms, rust gives a rather obscure error message:

fn main() {
    is_one(1)
}

fn is_one(a: u8) {
    match a {
        1 => true,
        _ => panic!("It's not one!"),
    }
}
<anon>:6:5: 9:6 error: match arms have incompatible types:
 expected `bool`,
    found `()`
(expected bool,
    found ()) [E0308]
<anon>:6     match a {
<anon>:7         1 => true,
<anon>:8         _ => panic!("It's not one!"),
<anon>:9     }
<anon>:8:14: 8:38 note: match arm with an incompatible type
<anon>:8         _ => panic!("It's not one!"),
                      ^~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
Program ended.

http://is.gd/J3qEpq

This is likely to be because panic! takes on the return type of the function, which is (), and than complains that it doesn't match the first arm's return type. This error message makes sense, but left me quite puzzled figuring out what was wrong.

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Apr 18, 2015
@ghost
Copy link

ghost commented Apr 19, 2015

Thanks for reporting this issue! This is essentially #24157 so I'm going to close it as such. The test case is sufficiently different, though, that I'll include it in the other issue too.

This issue was closed.
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
Projects
None yet
Development

No branches or pull requests

2 participants