Point at binop lhs and rhs when expression is multiline

```
error[E0277]: cannot add `()` to `u32`
  --> $DIR/multiline-span-simple.rs:13:18
   |
LL |       foo(1 as u32 +
   |           -------- ^ no implementation for `u32 + ()`
LL |
LL | /         bar(x,
LL | |
LL | |             y),
   | |______________-
```
This commit is contained in:
Esteban Küber
2026-03-29 21:07:47 +00:00
parent fda6d37bb8
commit 0740609ea3
3 changed files with 23 additions and 5 deletions
@@ -2916,12 +2916,21 @@ pub(super) fn note_obligation_cause_code<G: EmissionGuarantee, T>(
| ObligationCauseCode::CheckAssociatedTypeBounds { .. }
| ObligationCauseCode::LetElse
| ObligationCauseCode::UnOp { .. }
| ObligationCauseCode::BinOp { .. }
| ObligationCauseCode::AscribeUserTypeProvePredicate(..)
| ObligationCauseCode::AlwaysApplicableImpl
| ObligationCauseCode::ConstParam(_)
| ObligationCauseCode::ReferenceOutlivesReferent(..)
| ObligationCauseCode::ObjectTypeBound(..) => {}
ObligationCauseCode::BinOp { lhs_hir_id, rhs_hir_id, .. } => {
if let hir::Node::Expr(lhs) = tcx.hir_node(lhs_hir_id)
&& let hir::Node::Expr(rhs) = tcx.hir_node(rhs_hir_id)
&& tcx.sess.source_map().lookup_char_pos(lhs.span.lo()).line
!= tcx.sess.source_map().lookup_char_pos(rhs.span.hi()).line
{
err.span_label(lhs.span, "");
err.span_label(rhs.span, "");
}
}
ObligationCauseCode::RustCall => {
if let Some(pred) = predicate.as_trait_clause()
&& tcx.is_lang_item(pred.def_id(), LangItem::Sized)
+7 -2
View File
@@ -1,8 +1,13 @@
error[E0277]: cannot add `()` to `u32`
--> $DIR/multiline-span-simple.rs:13:18
|
LL | foo(1 as u32 +
| ^ no implementation for `u32 + ()`
LL | foo(1 as u32 +
| -------- ^ no implementation for `u32 + ()`
LL |
LL | / bar(x,
LL | |
LL | | y),
| |______________-
|
= help: the trait `Add<()>` is not implemented for `u32`
help: the following other types implement trait `Add<Rhs>`
@@ -2,7 +2,9 @@ error[E0277]: cannot add `()` to `{integer}`
--> $DIR/unit-type-add-error-11771.rs:5:7
|
LL | 1 +
| ^ no implementation for `{integer} + ()`
| - ^ no implementation for `{integer} + ()`
LL | x
| -
|
= help: the trait `Add<()>` is not implemented for `{integer}`
= help: the following other types implement trait `Add<Rhs>`:
@@ -20,7 +22,9 @@ error[E0277]: cannot add `()` to `{integer}`
--> $DIR/unit-type-add-error-11771.rs:10:7
|
LL | 1 +
| ^ no implementation for `{integer} + ()`
| - ^ no implementation for `{integer} + ()`
LL | x
| -
|
= help: the trait `Add<()>` is not implemented for `{integer}`
= help: the following other types implement trait `Add<Rhs>`: