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

"not all control paths return a value" should indicate which control paths don't return a value #18390

Closed
emberian opened this issue Oct 28, 2014 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@emberian
Copy link
Member

It's very mysterious when this error occurs in a big function and it's not one of the obvious extra-semicolon errors.

@emberian emberian added I-papercut A-diagnostics Area: Messages for errors, warnings, and lints labels Oct 28, 2014
@steveklabnik
Copy link
Member

Triage: no change. As an attempt to reproduce this, here's a big function:

fn main() {
    let _ = foo();
}

fn foo() -> i32 {
    let x = 5;
    match x {
        1 => {
            1
        },
        2 => {
            2
        },
        3 => {
            3
        },
        4 => {
            4
        },
        5 => {
            5
        },
        _ => {
            0
        },
    };
    match x {
        1 => {
            1
        },
        2 => {
            2
        },
        3 => {
            3
        },
        4 => {
            4
        },
        5 => {
            5
        },
        _ => {
            0
        },
    }; // <- here is the culprit!
}

Here's the error:

hello.rs:5:1: 47:2 error: not all control paths return a value [E0269]
hello.rs: 5 fn foo() -> i32 {
hello.rs: 6     let x = 5;
hello.rs: 7     match x {
hello.rs: 8         1 => {
hello.rs: 9             1
hello.rs:10         },
            ...
hello.rs:5:1: 47:2 help: run `rustc --explain E0269` to see a detailed explanation
error: aborting due to previous error

Doesn't point out the second match at all.

@cyplo
Copy link
Contributor

cyplo commented Oct 7, 2016

Hi ! Maybe worth bumping and linking to the recent big push for better error messages ? (Not sure/haven't found yet which issue to link specifically)

@zackmdavis
Copy link
Member

Triage: now fixed? Playground says:

error[E0269]: not all control paths return a value
  --> <anon>:5:1
   |
5  | fn foo() -> i32 {
   | ^
   |
help: consider removing this semicolon:
  --> <anon>:46:6
   |
46 |     }; // <- here is the culprit!
   |      ^

error: aborting due to previous error

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@eddyb
Copy link
Member

eddyb commented Apr 25, 2017

It's now:

error[E0308]: mismatched types
  --> <anon>:5:17
   |
5  | fn foo() -> i32 {
   |                 ^ expected i32, found ()
   |
   = note: expected type `i32`
              found type `()`
help: consider removing this semicolon:
  --> <anon>:46:6
   |
46 |     }; // <- here is the culprit!
   |      ^

error: aborting due to previous error

@Mark-Simulacrum
Copy link
Member

#39968 is a clear case where this goes wrong. I'm tempted to close this (not sure how helpful it is)...

@Mark-Simulacrum Mark-Simulacrum added C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed I-papercut labels Jul 22, 2017
@estebank
Copy link
Contributor

"Not all control paths" error is no longer being displayed, but rather we're catching type errors and extraneous semicolons and providing help for them:

error[E0308]: mismatched types
 --> src/main.rs:1:27
  |
1 |   fn add_one(x: i32) -> i32 {
  |  ___________________________^
2 | |     x + 1;
  | |          - help: consider removing this semicolon
3 | | }
  | |_^ expected i32, found ()
  |
  = note: expected type `i32`
             found type `()`

@nikomatsakis
Copy link
Contributor

I think we can close this... I think the interesting case is now covered by #39968. That is, I modified the original example to something like this:

fn main() {
    let _ = foo();
}

fn foo() -> i32 {
    let x = 5;
    match x {
        1 => {
            1
        },
        2 => {
            2
        },
        3 => {
            3
        },
        4 => {
            4
        },
        5 => {
            5
        },
        _ => {
            0
        },
    };
    match x {
        1 => {
            return 1
        },
        2 => {
            return 2
        },
        3 => {
            return 3
        },
        4 => {
            return 4
        },
        5 => {
            return 5
        },
        _ => { }
    }
}

But now you get:

error[E0308]: mismatched types
  --> src/main.rs:43:14
   |
43 |         _ => { }
   |              ^^^ expected i32, found ()
   |
   = note: expected type `i32`
              found type `()`

which is not the original example here.

@nikomatsakis
Copy link
Contributor

Going to close.

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

8 participants