Skip to content

Commit a2cc7a9

Browse files
authored
Rollup merge of #154563 - estebank:multiline-binop, r=TaKO8Ki
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), | |______________- ```
2 parents e97324a + 0740609 commit a2cc7a9

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2915,12 +2915,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
29152915
| ObligationCauseCode::CheckAssociatedTypeBounds { .. }
29162916
| ObligationCauseCode::LetElse
29172917
| ObligationCauseCode::UnOp { .. }
2918-
| ObligationCauseCode::BinOp { .. }
29192918
| ObligationCauseCode::AscribeUserTypeProvePredicate(..)
29202919
| ObligationCauseCode::AlwaysApplicableImpl
29212920
| ObligationCauseCode::ConstParam(_)
29222921
| ObligationCauseCode::ReferenceOutlivesReferent(..)
29232922
| ObligationCauseCode::ObjectTypeBound(..) => {}
2923+
ObligationCauseCode::BinOp { lhs_hir_id, rhs_hir_id, .. } => {
2924+
if let hir::Node::Expr(lhs) = tcx.hir_node(lhs_hir_id)
2925+
&& let hir::Node::Expr(rhs) = tcx.hir_node(rhs_hir_id)
2926+
&& tcx.sess.source_map().lookup_char_pos(lhs.span.lo()).line
2927+
!= tcx.sess.source_map().lookup_char_pos(rhs.span.hi()).line
2928+
{
2929+
err.span_label(lhs.span, "");
2930+
err.span_label(rhs.span, "");
2931+
}
2932+
}
29242933
ObligationCauseCode::RustCall => {
29252934
if let Some(pred) = predicate.as_trait_clause()
29262935
&& tcx.is_lang_item(pred.def_id(), LangItem::Sized)

tests/ui/span/multiline-span-simple.stderr

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
error[E0277]: cannot add `()` to `u32`
22
--> $DIR/multiline-span-simple.rs:13:18
33
|
4-
LL | foo(1 as u32 +
5-
| ^ no implementation for `u32 + ()`
4+
LL | foo(1 as u32 +
5+
| -------- ^ no implementation for `u32 + ()`
6+
LL |
7+
LL | / bar(x,
8+
LL | |
9+
LL | | y),
10+
| |______________-
611
|
712
= help: the trait `Add<()>` is not implemented for `u32`
813
help: the following other types implement trait `Add<Rhs>`

tests/ui/typeck/unit-type-add-error-11771.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: cannot add `()` to `{integer}`
22
--> $DIR/unit-type-add-error-11771.rs:5:7
33
|
44
LL | 1 +
5-
| ^ no implementation for `{integer} + ()`
5+
| - ^ no implementation for `{integer} + ()`
6+
LL | x
7+
| -
68
|
79
= help: the trait `Add<()>` is not implemented for `{integer}`
810
= help: the following other types implement trait `Add<Rhs>`:
@@ -20,7 +22,9 @@ error[E0277]: cannot add `()` to `{integer}`
2022
--> $DIR/unit-type-add-error-11771.rs:10:7
2123
|
2224
LL | 1 +
23-
| ^ no implementation for `{integer} + ()`
25+
| - ^ no implementation for `{integer} + ()`
26+
LL | x
27+
| -
2428
|
2529
= help: the trait `Add<()>` is not implemented for `{integer}`
2630
= help: the following other types implement trait `Add<Rhs>`:

0 commit comments

Comments
 (0)