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

Noisy error messages for wrong if let #54931

Closed
leonardo-m opened this issue Oct 9, 2018 · 2 comments
Closed

Noisy error messages for wrong if let #54931

leonardo-m opened this issue Oct 9, 2018 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@leonardo-m
Copy link

This is wrong code, the programmer forgot to add a "let" after the "if":

fn foo(n: Option<u32>) -> u32 {
    if Some(b) = n {
        return b;
    }
    0
}
fn main() {}

rustc 1.31.0-nightly (423d810 2018-10-08) gives:

error[E0425]: cannot find value `b` in this scope
 --> ...\test.rs:2:13
  |
2 |     if Some(b) = n {
  |             ^ did you mean `n`?

error[E0425]: cannot find value `b` in this scope
 --> ...\test.rs:3:16
  |
3 |         return b;
  |                ^ did you mean `n`?

error[E0308]: mismatched types
 --> ...\test.rs:2:8
  |
2 |     if Some(b) = n {
  |        ^^^^^^^^^^^
  |        |
  |        expected bool, found ()
  |        help: try comparing for equality: `Some(b) == n`
  |
  = note: expected type `bool`
             found type `()`

error: aborting due to 3 previous errors

Some errors occurred: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.

Perhaps rustc could give only one smart error message in this situation?

@estebank estebank added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-diagnostics Area: Messages for errors, warnings, and lints labels Oct 9, 2018
@estebank
Copy link
Contributor

estebank commented Oct 9, 2018

CC #44990

@estebank
Copy link
Contributor

Closing in favor of the older ticket.

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.
Projects
None yet
Development

No branches or pull requests

2 participants