]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #85971 - FabianWolff:issue-85586, r=davidtwco
authorbors <bors@rust-lang.org>
Fri, 30 Jul 2021 14:38:00 +0000 (14:38 +0000)
committerbors <bors@rust-lang.org>
Fri, 30 Jul 2021 14:38:00 +0000 (14:38 +0000)
Use more precise span for E0282 in cast expressions

This pull request fixes #85586. The example code given there:
```rust
fn main() {
    let a = [1, 2, 3].iter().sum();
    let b = (a + 1) as usize;
}
```
currently produces
```
error[E0282]: type annotations needed
 --> issue-85586.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^^^^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

error: aborting due to previous error
```
even though the type of the entire cast expression quite clearly should be `usize`. The error is in the cast's left-hand side, which is made explicit by the changes in this PR:
```
error[E0282]: type annotations needed
 --> issue-85586.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

error: aborting due to previous error
```

1  2 
compiler/rustc_typeck/src/check/cast.rs