Skip to content

Confusing type inference error span #85586

Closed
@Sejsel

Description

@Sejsel

Given the following code (playground):

fn main() {
    let a = [1, 2, 3].iter().sum();
    let b = (a + 1) as usize;
}

The current output is:

error[E0282]: type annotations needed
 --> src/main.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^^^^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

Ideally the output should look like:

error[E0282]: type annotations needed
 --> src/main.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

Happens on both stable 1.52.1 and nightly 1.54.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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