Skip to content

Incorrect type mismatch label pointing at return type #46302

Closed
@estebank

Description

@estebank

The following code:

fn main() { //~ NOTE expected `()` because of default return type
  let s = "abc";
  let u: &str = if true { s[..2] } else { s };
}

has an incorrect label:

error[E0308]: mismatched types
 --> src/main.rs:3:27
  |
1 | fn main() { //~ NOTE expected `()` because of default return type
  |           - expected `()` because of default return type
2 |   let s = "abc";
3 |   let u: &str = if true { s[..2] } else { s };
  |                           ^^^^^^ expected &str, found str
  |
  = note: expected type `&str`
             found type `str`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions