Skip to content

Incorrect span label when non-() else-less if is tail expression in -> () function #124819

Closed
@estebank

Description

@estebank

Code

fn main() {
    if true {
        ""
    }
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:3:9
  |
1 | fn main() {
  |          - expected `()` because of default return type
2 |     if true {
3 |         ""
  |         ^^ expected `()`, found `&str`

Desired output

error[E0308]: mismatched types
 --> src/main.rs:3:9
  |
2 | /     if true {
3 | |         ""
  | |         ^^ expected `()`, found `&str`
4 | |     }
  | |_____- expected this to be `()`

Rationale and extra context

When the if is not the tail expression, we provide the right output. We might just have to change the order of operation when looking for additional context to print.

Other cases

if true { "" } else { "" } as tail expression has the same problem.

Rust Version

All checked, current version 1.78.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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