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

Mismatched types error involving if/else expressions should point at #61281

Closed
estebank opened this issue May 28, 2019 · 1 comment · Fixed by #64083
Closed

Mismatched types error involving if/else expressions should point at #61281

estebank opened this issue May 28, 2019 · 1 comment · Fixed by #64083
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority

Comments

@estebank
Copy link
Contributor

fn baz() -> impl std::fmt::Display {
    if false {

        return 0i32;
    } else {
        1u32
    }
}

currently points at the entire if/else

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 |   fn baz() -> impl std::fmt::Display {
  |               ---------------------- expected because this return type...
2 | /     if false {
3 | |
4 | |         return 0i32;
  | |                ---- ...is found to be `i32` here
5 | |     } else {
6 | |         1u32
7 | |     }
  | |_____^ expected i32, found u32
  |
  = note: expected type `i32`
             found type `u32`

It should probably point at the else expression

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
1 | fn baz() -> impl std::fmt::Display {
  |             ---------------------- expected because this return type...
2 |     if false {
3 |
4 |         return 0i32;
  |                ---- ...is found to be `i32` here
5 |     } else {
6 |         1u32
  |         ^^^^ expected i32, found u32
7 |     }
  |
  = note: expected type `i32`
             found type `u32`
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority labels May 28, 2019
@estebank
Copy link
Contributor Author

Centril added a commit to Centril/rust that referenced this issue Sep 5, 2019
Point at appropriate arm on type error on if/else/match with one non-! arm

Fix rust-lang#61281.
@bors bors closed this as completed in 59237ec Sep 5, 2019
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 P-low Low priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant