Skip to content

Commit 4d648ce

Browse files
Better diagnostic for binary operation on BoxedValues
1 parent c5fb4d0 commit 4d648ce

30 files changed

+211
-85
lines changed

src/librustc_typeck/check/op.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
327327
err.emit();
328328
}
329329
IsAssign::No => {
330-
let mut err = struct_span_err!(self.tcx.sess, expr.span, E0369,
330+
let mut err = struct_span_err!(self.tcx.sess, op.span, E0369,
331331
"binary operation `{}` cannot be applied to type `{}`",
332332
op.node.as_str(),
333333
lhs_ty);
334+
335+
err.span_label(lhs_expr.span, lhs_ty.to_string());
336+
err.span_label(rhs_expr.span, rhs_ty.to_string());
337+
334338
let mut suggested_deref = false;
335339
if let Ref(_, mut rty, _) = lhs_ty.sty {
336340
if {

src/test/ui/autoderef-full-lval.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
error[E0369]: binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
2-
--> $DIR/autoderef-full-lval.rs:15:20
2+
--> $DIR/autoderef-full-lval.rs:15:24
33
|
44
LL | let z: isize = a.x + b.y;
5-
| ^^^^^^^^^
5+
| --- ^ --- std::boxed::Box<isize>
6+
| |
7+
| std::boxed::Box<isize>
68
|
79
= note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box<isize>`
810

911
error[E0369]: binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
10-
--> $DIR/autoderef-full-lval.rs:21:25
12+
--> $DIR/autoderef-full-lval.rs:21:33
1113
|
1214
LL | let answer: isize = forty.a + two.a;
13-
| ^^^^^^^^^^^^^^^
15+
| ------- ^ ----- std::boxed::Box<isize>
16+
| |
17+
| std::boxed::Box<isize>
1418
|
1519
= note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box<isize>`
1620

src/test/ui/binary-op-on-double-ref.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0369]: binary operation `%` cannot be applied to type `&&{integer}`
2-
--> $DIR/binary-op-on-double-ref.rs:4:9
2+
--> $DIR/binary-op-on-double-ref.rs:4:11
33
|
44
LL | x % 2 == 0
5-
| ^^^^^
5+
| - ^ - {integer}
6+
| |
7+
| &&{integer}
68
|
79
= help: `%` can be used on '{integer}', you can dereference `x`: `*x`
810

src/test/ui/binop/binop-bitxor-str.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0369]: binary operation `^` cannot be applied to type `std::string::String`
2-
--> $DIR/binop-bitxor-str.rs:3:21
2+
--> $DIR/binop-bitxor-str.rs:3:37
33
|
44
LL | fn main() { let x = "a".to_string() ^ "b".to_string(); }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| --------------- ^ --------------- std::string::String
6+
| |
7+
| std::string::String
68
|
79
= note: an implementation of `std::ops::BitXor` might be missing for `std::string::String`
810

src/test/ui/binop/binop-mul-bool.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0369]: binary operation `*` cannot be applied to type `bool`
2-
--> $DIR/binop-mul-bool.rs:3:21
2+
--> $DIR/binop-mul-bool.rs:3:26
33
|
44
LL | fn main() { let x = true * false; }
5-
| ^^^^^^^^^^^^
5+
| ---- ^ ----- bool
6+
| |
7+
| bool
68
|
79
= note: an implementation of `std::ops::Mul` might be missing for `bool`
810

src/test/ui/binop/binop-typeck.stderr

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0369]: binary operation `+` cannot be applied to type `bool`
2-
--> $DIR/binop-typeck.rs:6:13
2+
--> $DIR/binop-typeck.rs:6:15
33
|
44
LL | let z = x + y;
5-
| ^^^^^
5+
| - ^ - {integer}
6+
| |
7+
| bool
68
|
79
= note: an implementation of `std::ops::Add` might be missing for `bool`
810

src/test/ui/derives/derives-span-PartialEq-enum-struct-variant.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error[E0369]: binary operation `==` cannot be applied to type `Error`
33
|
44
LL | x: Error
55
| ^^^^^^^^
6+
| |
7+
| Error
8+
| Error
69
|
710
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
811

@@ -11,6 +14,9 @@ error[E0369]: binary operation `!=` cannot be applied to type `Error`
1114
|
1215
LL | x: Error
1316
| ^^^^^^^^
17+
| |
18+
| Error
19+
| Error
1420
|
1521
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
1622

src/test/ui/derives/derives-span-PartialEq-enum.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error[E0369]: binary operation `==` cannot be applied to type `Error`
33
|
44
LL | Error
55
| ^^^^^
6+
| |
7+
| Error
8+
| Error
69
|
710
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
811

@@ -11,6 +14,9 @@ error[E0369]: binary operation `!=` cannot be applied to type `Error`
1114
|
1215
LL | Error
1316
| ^^^^^
17+
| |
18+
| Error
19+
| Error
1420
|
1521
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
1622

src/test/ui/derives/derives-span-PartialEq-struct.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error[E0369]: binary operation `==` cannot be applied to type `Error`
33
|
44
LL | x: Error
55
| ^^^^^^^^
6+
| |
7+
| Error
8+
| Error
69
|
710
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
811

@@ -11,6 +14,9 @@ error[E0369]: binary operation `!=` cannot be applied to type `Error`
1114
|
1215
LL | x: Error
1316
| ^^^^^^^^
17+
| |
18+
| Error
19+
| Error
1420
|
1521
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
1622

src/test/ui/derives/derives-span-PartialEq-tuple-struct.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error[E0369]: binary operation `==` cannot be applied to type `Error`
33
|
44
LL | Error
55
| ^^^^^
6+
| |
7+
| Error
8+
| Error
69
|
710
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
811

@@ -11,6 +14,9 @@ error[E0369]: binary operation `!=` cannot be applied to type `Error`
1114
|
1215
LL | Error
1316
| ^^^^^
17+
| |
18+
| Error
19+
| Error
1420
|
1521
= note: an implementation of `std::cmp::PartialEq` might be missing for `Error`
1622

0 commit comments

Comments
 (0)