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

+5-1
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

+8-4
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

+4-2
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

+4-2
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

+4-2
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

+4-2
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

+6
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

+6
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

+6
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

+6
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/deriving-no-inner-impl-error-message.stderr

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

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

src/test/ui/fn/fn-compare-mismatch.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0369]: binary operation `==` cannot be applied to type `fn() {main::f}`
2-
--> $DIR/fn-compare-mismatch.rs:4:13
2+
--> $DIR/fn-compare-mismatch.rs:4:15
33
|
44
LL | let x = f == g;
5-
| ^^^^^^
5+
| - ^^ - fn() {main::g}
6+
| |
7+
| fn() {main::f}
68
|
79
= note: an implementation of `std::cmp::PartialEq` might be missing for `fn() {main::f}`
810

src/test/ui/for/for-loop-type-error.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0369]: binary operation `+` cannot be applied to type `()`
2-
--> $DIR/for-loop-type-error.rs:2:13
2+
--> $DIR/for-loop-type-error.rs:2:16
33
|
44
LL | let x = () + ();
5-
| ^^^^^^^
5+
| -- ^ -- ()
6+
| |
7+
| ()
68
|
79
= note: an implementation of `std::ops::Add` might be missing for `()`
810

src/test/ui/issues/issue-14915.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[E0369]: binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
2-
--> $DIR/issue-14915.rs:6:20
2+
--> $DIR/issue-14915.rs:6:22
33
|
44
LL | println!("{}", x + 1);
5-
| ^^^^^
5+
| - ^ - {integer}
6+
| |
7+
| std::boxed::Box<isize>
68
|
79
= note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box<isize>`
810

src/test/ui/issues/issue-24363.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ LL | 1.create_a_type_error[
55
| ^^^^^^^^^^^^^^^^^^^
66

77
error[E0369]: binary operation `+` cannot be applied to type `()`
8-
--> $DIR/issue-24363.rs:3:9
8+
--> $DIR/issue-24363.rs:3:11
99
|
1010
LL | ()+()
11-
| ^^^^^
11+
| --^-- ()
12+
| |
13+
| ()
1214
|
1315
= note: an implementation of `std::ops::Add` might be missing for `()`
1416

0 commit comments

Comments
 (0)