Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Point at LHS on binop type err if relevant #105192

Merged
merged 1 commit into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
err: &mut Diagnostic,
expr: &hir::Expr<'_>,
error: Option<TypeError<'_>>,
error: Option<TypeError<'tcx>>,
) {
let parent = self.tcx.hir().get_parent_node(expr.hir_id);
match (self.tcx.hir().find(parent), error) {
Expand Down Expand Up @@ -286,6 +286,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.downgrade_to_delayed_bug();
}
}
(
Some(hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Binary(_, lhs, rhs), ..
})),
Some(TypeError::Sorts(ExpectedFound { expected, .. })),
) if rhs.hir_id == expr.hir_id
&& self.typeck_results.borrow().expr_ty_adjusted_opt(lhs) == Some(expected) =>
{
err.span_label(lhs.span, &format!("expected because this is `{expected}`"));
}
_ => {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/issue-79518-default_trait_method_normalization.rs:16:32
|
LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
| |
| expected because this is `<Self as Foo>::Assoc`
|
= note: expected associated type `<Self as Foo>::Assoc`
found array `[(); _]`
Expand Down
5 changes: 4 additions & 1 deletion src/test/ui/inference/deref-suggestion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ error[E0308]: mismatched types
--> $DIR/deref-suggestion.rs:37:5
|
LL | assert_eq!(3i32, &3i32);
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `&i32`
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected `i32`, found `&i32`
| expected because this is `i32`
|
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/issues/issue-47486.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ error[E0308]: mismatched types
--> $DIR/issue-47486.rs:2:10
|
LL | () < std::mem::size_of::<_>();
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
| -- ^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `usize`
| |
| expected because this is `()`

error[E0282]: type annotations needed
--> $DIR/issue-47486.rs:3:11
Expand Down
Loading