Skip to content

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

Closed
@estebank

Description

@estebank
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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsP-lowLow priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions