Skip to content

match arm without tail expression diverging type error has non-ideal spans #75418

Closed
@estebank

Description

@estebank

Given:

    let _ = match Some(42) {
        Some(x) => {
            x
        }
        None => {
            0;
        }
    };

we emit

error[E0308]: `match` arms have incompatible types
 --> src/main.rs:6:17
  |
2 |        let _ = match Some(42) {
  |   _____________-
3 |  |         Some(x) => {
4 |  |             x
  |  |             - this is found to be of type `{integer}`
5 |  |         }
6 |  |         None => {
  |  |_________________^
7 | ||             0;
8 | ||         }
  | ||_________^ expected integer, found `()`
9 |  |     };
  |  |_____- `match` arms have incompatible types

We should be

  • checking that removing the ; in the incompatible arm would solve the issue and suggest it
  • point at the last statement in the incompatible arm instead of the whole arm

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions