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

Wrong type from match result with return statement #1599

Closed
jrmuizel opened this issue Aug 9, 2017 · 1 comment
Closed

Wrong type from match result with return statement #1599

jrmuizel opened this issue Aug 9, 2017 · 1 comment

Comments

@jrmuizel
Copy link

jrmuizel commented Aug 9, 2017

Intellij thinks the type 'full' is () when it should be u32

enum Buck {
    Full(u32),
    Empty,
}

fn peek() -> Buck {
    Buck::Empty
}

fn stuff() -> u32 {
    let full = match peek() {
        Buck::Empty => {
            return 0;
        }
        Buck::Full(bucket) => bucket,
    };
    full
}
@matklad matklad mentioned this issue Aug 11, 2017
11 tasks
bors bot added a commit that referenced this issue Aug 15, 2017
1629: TY: implemented `!` type r=matklad

`!` type (TyNever) is result of `return`, `break` & `continue` exprs, and also `panic!()`, `unimplemented!()` and so on. Rust handles `!` in a special way, e.g. allow it to become any type, or ignore match arm that return it.

It isn't fixing #1599 completely, but if remove semicolon after `return 0` in that example,  it will work.
matklad added a commit that referenced this issue Nov 9, 2017
@vlad20012
Copy link
Member

Closed with #2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants