Skip to content

Commit 132a140

Browse files
committed
Point at LHS on binop type err if relevant
1 parent 01fbc5a commit 132a140

14 files changed

+571
-187
lines changed

Diff for: compiler/rustc_hir_typeck/src/demand.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
189189
&self,
190190
err: &mut Diagnostic,
191191
expr: &hir::Expr<'_>,
192-
error: Option<TypeError<'_>>,
192+
error: Option<TypeError<'tcx>>,
193193
) {
194194
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
195195
match (self.tcx.hir().find(parent), error) {
@@ -286,6 +286,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286286
err.downgrade_to_delayed_bug();
287287
}
288288
}
289+
(
290+
Some(hir::Node::Expr(hir::Expr {
291+
kind: hir::ExprKind::Binary(_, lhs, rhs), ..
292+
})),
293+
Some(TypeError::Sorts(ExpectedFound { expected, .. })),
294+
) if rhs.hir_id == expr.hir_id
295+
&& self.typeck_results.borrow().expr_ty_adjusted_opt(lhs) == Some(expected) =>
296+
{
297+
err.span_label(lhs.span, &format!("expected because this is `{expected}`"));
298+
}
289299
_ => {}
290300
}
291301
}

Diff for: src/test/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/issue-79518-default_trait_method_normalization.rs:16:32
33
|
44
LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()];
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
5+
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
6+
| |
7+
| expected because this is `<Self as Foo>::Assoc`
68
|
79
= note: expected associated type `<Self as Foo>::Assoc`
810
found array `[(); _]`

Diff for: src/test/ui/inference/deref-suggestion.stderr

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ error[E0308]: mismatched types
8787
--> $DIR/deref-suggestion.rs:37:5
8888
|
8989
LL | assert_eq!(3i32, &3i32);
90-
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `&i32`
90+
| ^^^^^^^^^^^^^^^^^^^^^^^
91+
| |
92+
| expected `i32`, found `&i32`
93+
| expected because this is `i32`
9194
|
9295
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
9396

Diff for: src/test/ui/issues/issue-47486.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/issue-47486.rs:2:10
33
|
44
LL | () < std::mem::size_of::<_>();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
5+
| -- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
6+
| |
7+
| expected because this is `()`
68

79
error[E0282]: type annotations needed
810
--> $DIR/issue-47486.rs:3:11

0 commit comments

Comments
 (0)