Skip to content

Commit

Permalink
Use more precise span for E0282 in cast expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianWolff committed Jun 10, 2021
1 parent c5fbcd3 commit 74d1bd2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ impl<'a, 'tcx> CastCheck<'tcx> {
}

pub fn check(mut self, fcx: &FnCtxt<'a, 'tcx>) {
self.expr_ty = fcx.structurally_resolved_type(self.span, self.expr_ty);
self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty);
self.expr_ty = fcx.structurally_resolved_type(self.expr.span, self.expr_ty);
self.cast_ty = fcx.structurally_resolved_type(self.cast_span, self.cast_ty);

debug!("check_cast({}, {:?} as {:?})", self.expr.hir_id, self.expr_ty, self.cast_ty);

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/cast/issue-85586.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Check that errors for unresolved types in cast expressions are reported
// for the offending subexpression, not the whole cast expression.

#![allow(unused_variables)]

fn main() {
let a = [1, 2, 3].iter().sum();
let b = (a + 1) as usize;
//~^ ERROR: type annotations needed [E0282]
}
11 changes: 11 additions & 0 deletions src/test/ui/cast/issue-85586.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0282]: type annotations needed
--> $DIR/issue-85586.rs:8:13
|
LL | let b = (a + 1) as usize;
| ^^^^^^^ cannot infer type
|
= note: type must be known at this point

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.

0 comments on commit 74d1bd2

Please sign in to comment.