Skip to content

Commit eac5fb8

Browse files
authored
Rollup merge of rust-lang#67189 - LeSeulArtichaut:binop-wording, r=estebank
Unify binop wording Closes rust-lang#60497 r? @estebank
2 parents c605199 + e4abcfb commit eac5fb8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+153
-112
lines changed

src/librustc_typeck/check/op.rs

+63-22
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,70 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
334334
err.emit();
335335
}
336336
IsAssign::No => {
337+
let (message, missing_trait) = match op.node {
338+
hir::BinOpKind::Add => {
339+
(format!("cannot add `{}` to `{}`", rhs_ty, lhs_ty),
340+
Some("std::ops::Add"))
341+
},
342+
hir::BinOpKind::Sub => {
343+
(format!("cannot substract `{}` from `{}`", rhs_ty, lhs_ty),
344+
Some("std::ops::Sub"))
345+
},
346+
hir::BinOpKind::Mul => {
347+
(format!("cannot multiply `{}` to `{}`", rhs_ty, lhs_ty),
348+
Some("std::ops::Mul"))
349+
},
350+
hir::BinOpKind::Div => {
351+
(format!("cannot divide `{}` by `{}`", lhs_ty, rhs_ty),
352+
Some("std::ops::Div"))
353+
},
354+
hir::BinOpKind::Rem => {
355+
(format!("cannot mod `{}` by `{}`", lhs_ty, rhs_ty),
356+
Some("std::ops::Rem"))
357+
},
358+
hir::BinOpKind::BitAnd => {
359+
(format!("no implementation for `{} & {}`", lhs_ty, rhs_ty),
360+
Some("std::ops::BitAnd"))
361+
},
362+
hir::BinOpKind::BitXor => {
363+
(format!("no implementation for `{} ^ {}`", lhs_ty, rhs_ty),
364+
Some("std::ops::BitXor"))
365+
},
366+
hir::BinOpKind::BitOr => {
367+
(format!("no implementation for `{} | {}`", lhs_ty, rhs_ty),
368+
Some("std::ops::BitOr"))
369+
},
370+
hir::BinOpKind::Shl => {
371+
(format!("no implementation for `{} << {}`", lhs_ty, rhs_ty),
372+
Some("std::ops::Shl"))
373+
},
374+
hir::BinOpKind::Shr => {
375+
(format!("no implementation for `{} >> {}`", lhs_ty, rhs_ty),
376+
Some("std::ops::Shr"))
377+
},
378+
hir::BinOpKind::Eq |
379+
hir::BinOpKind::Ne => {
380+
(format!(
381+
"binary operation `{}` cannot be applied to type `{}`",
382+
op.node.as_str(), lhs_ty),
383+
Some("std::cmp::PartialEq"))
384+
},
385+
hir::BinOpKind::Lt |
386+
hir::BinOpKind::Le |
387+
hir::BinOpKind::Gt |
388+
hir::BinOpKind::Ge => {
389+
(format!(
390+
"binary operation `{}` cannot be applied to type `{}`",
391+
op.node.as_str(), lhs_ty),
392+
Some("std::cmp::PartialOrd"))
393+
}
394+
_ => (format!(
395+
"binary operation `{}` cannot be applied to type `{}`",
396+
op.node.as_str(), lhs_ty),
397+
None)
398+
};
337399
let mut err = struct_span_err!(self.tcx.sess, op.span, E0369,
338-
"binary operation `{}` cannot be applied to type `{}`",
339-
op.node.as_str(),
340-
lhs_ty);
400+
"{}", message.as_str());
341401

342402
let mut involves_fn = false;
343403
if !lhs_expr.span.eq(&rhs_expr.span) {
@@ -382,25 +442,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
382442
}
383443
}
384444
}
385-
let missing_trait = match op.node {
386-
hir::BinOpKind::Add => Some("std::ops::Add"),
387-
hir::BinOpKind::Sub => Some("std::ops::Sub"),
388-
hir::BinOpKind::Mul => Some("std::ops::Mul"),
389-
hir::BinOpKind::Div => Some("std::ops::Div"),
390-
hir::BinOpKind::Rem => Some("std::ops::Rem"),
391-
hir::BinOpKind::BitAnd => Some("std::ops::BitAnd"),
392-
hir::BinOpKind::BitXor => Some("std::ops::BitXor"),
393-
hir::BinOpKind::BitOr => Some("std::ops::BitOr"),
394-
hir::BinOpKind::Shl => Some("std::ops::Shl"),
395-
hir::BinOpKind::Shr => Some("std::ops::Shr"),
396-
hir::BinOpKind::Eq |
397-
hir::BinOpKind::Ne => Some("std::cmp::PartialEq"),
398-
hir::BinOpKind::Lt |
399-
hir::BinOpKind::Le |
400-
hir::BinOpKind::Gt |
401-
hir::BinOpKind::Ge => Some("std::cmp::PartialOrd"),
402-
_ => None
403-
};
404445
if let Some(missing_trait) = missing_trait {
405446
if op.node == hir::BinOpKind::Add &&
406447
self.check_str_addition(

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ fn main() {
1313
let a: Clam = Clam{x: box 1, y: box 2};
1414
let b: Clam = Clam{x: box 10, y: box 20};
1515
let z: isize = a.x + b.y;
16-
//~^ ERROR binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
16+
//~^ ERROR cannot add `std::boxed::Box<isize>` to `std::boxed::Box<isize>`
1717
println!("{}", z);
1818
assert_eq!(z, 21);
1919
let forty: Fish = Fish{a: box 40};
2020
let two: Fish = Fish{a: box 2};
2121
let answer: isize = forty.a + two.a;
22-
//~^ ERROR binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
22+
//~^ ERROR cannot add `std::boxed::Box<isize>` to `std::boxed::Box<isize>`
2323
println!("{}", answer);
2424
assert_eq!(answer, 42);
2525
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
1+
error[E0369]: cannot add `std::boxed::Box<isize>` to `std::boxed::Box<isize>`
22
--> $DIR/autoderef-full-lval.rs:15:24
33
|
44
LL | let z: isize = a.x + b.y;
@@ -8,7 +8,7 @@ LL | let z: isize = a.x + b.y;
88
|
99
= note: an implementation of `std::ops::Add` might be missing for `std::boxed::Box<isize>`
1010

11-
error[E0369]: binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
11+
error[E0369]: cannot add `std::boxed::Box<isize>` to `std::boxed::Box<isize>`
1212
--> $DIR/autoderef-full-lval.rs:21:33
1313
|
1414
LL | let answer: isize = forty.a + two.a;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ fn main() {
22
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
33
let vr = v.iter().filter(|x| {
44
x % 2 == 0
5-
//~^ ERROR binary operation `%` cannot be applied to type `&&{integer}`
5+
//~^ ERROR cannot mod `&&{integer}` by `{integer}`
66
});
77
println!("{:?}", vr);
88
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `%` cannot be applied to type `&&{integer}`
1+
error[E0369]: cannot mod `&&{integer}` by `{integer}`
22
--> $DIR/binary-op-on-double-ref.rs:4:11
33
|
44
LL | x % 2 == 0

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// error-pattern:`^` cannot be applied to type `std::string::String`
1+
// error-pattern:no implementation for `std::string::String ^ std::string::String`
22

33
fn main() { let x = "a".to_string() ^ "b".to_string(); }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `^` cannot be applied to type `std::string::String`
1+
error[E0369]: no implementation for `std::string::String ^ std::string::String`
22
--> $DIR/binop-bitxor-str.rs:3:37
33
|
44
LL | fn main() { let x = "a".to_string() ^ "b".to_string(); }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// error-pattern:`*` cannot be applied to type `bool`
1+
// error-pattern:cannot multiply `bool` to `bool`
22

33
fn main() { let x = true * false; }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `*` cannot be applied to type `bool`
1+
error[E0369]: cannot multiply `bool` to `bool`
22
--> $DIR/binop-mul-bool.rs:3:26
33
|
44
LL | fn main() { let x = true * false; }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ fn main() {
44
let x = true;
55
let y = 1;
66
let z = x + y;
7-
//~^ ERROR binary operation `+` cannot be applied to type `bool`
7+
//~^ ERROR cannot add `{integer}` to `bool`
88
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `+` cannot be applied to type `bool`
1+
error[E0369]: cannot add `{integer}` to `bool`
22
--> $DIR/binop-typeck.rs:6:15
33
|
44
LL | let z = x + y;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub fn main() {
2-
let x = () + (); //~ ERROR binary operation
2+
let x = () + (); //~ ERROR cannot add `()` to `()`
33

44
// this shouldn't have a flow-on error:
55
for _ in x {}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `+` cannot be applied to type `()`
1+
error[E0369]: cannot add `()` to `()`
22
--> $DIR/for-loop-type-error.rs:2:16
33
|
44
LL | let x = () + ();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ fn main() {
44
let x: Box<isize> = box 0;
55

66
println!("{}", x + 1);
7-
//~^ ERROR binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
7+
//~^ ERROR cannot add `{integer}` to `std::boxed::Box<isize>`
88
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `+` cannot be applied to type `std::boxed::Box<isize>`
1+
error[E0369]: cannot add `{integer}` to `std::boxed::Box<isize>`
22
--> $DIR/issue-14915.rs:6:22
33
|
44
LL | println!("{}", x + 1);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn main() {
22
1.create_a_type_error[ //~ `{integer}` is a primitive type and therefore doesn't have fields
3-
()+() //~ ERROR binary operation `+` cannot be applied
3+
()+() //~ ERROR cannot add
44
// ^ ensure that we typeck the inner expression ^
55
];
66
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
44
LL | 1.create_a_type_error[
55
| ^^^^^^^^^^^^^^^^^^^
66

7-
error[E0369]: binary operation `+` cannot be applied to type `()`
7+
error[E0369]: cannot add `()` to `()`
88
--> $DIR/issue-24363.rs:3:11
99
|
1010
LL | ()+()

src/test/ui/issues/issue-28837.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ struct A;
33
fn main() {
44
let a = A;
55

6-
a + a; //~ ERROR binary operation `+` cannot be applied to type `A`
6+
a + a; //~ ERROR cannot add `A` to `A`
77

8-
a - a; //~ ERROR binary operation `-` cannot be applied to type `A`
8+
a - a; //~ ERROR cannot substract `A` from `A`
99

10-
a * a; //~ ERROR binary operation `*` cannot be applied to type `A`
10+
a * a; //~ ERROR cannot multiply `A` to `A`
1111

12-
a / a; //~ ERROR binary operation `/` cannot be applied to type `A`
12+
a / a; //~ ERROR cannot divide `A` by `A`
1313

14-
a % a; //~ ERROR binary operation `%` cannot be applied to type `A`
14+
a % a; //~ ERROR cannot mod `A` by `A`
1515

16-
a & a; //~ ERROR binary operation `&` cannot be applied to type `A`
16+
a & a; //~ ERROR no implementation for `A & A`
1717

18-
a | a; //~ ERROR binary operation `|` cannot be applied to type `A`
18+
a | a; //~ ERROR no implementation for `A | A`
1919

20-
a << a; //~ ERROR binary operation `<<` cannot be applied to type `A`
20+
a << a; //~ ERROR no implementation for `A << A`
2121

22-
a >> a; //~ ERROR binary operation `>>` cannot be applied to type `A`
22+
a >> a; //~ ERROR no implementation for `A >> A`
2323

2424
a == a; //~ ERROR binary operation `==` cannot be applied to type `A`
2525

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `+` cannot be applied to type `A`
1+
error[E0369]: cannot add `A` to `A`
22
--> $DIR/issue-28837.rs:6:7
33
|
44
LL | a + a;
@@ -8,7 +8,7 @@ LL | a + a;
88
|
99
= note: an implementation of `std::ops::Add` might be missing for `A`
1010

11-
error[E0369]: binary operation `-` cannot be applied to type `A`
11+
error[E0369]: cannot substract `A` from `A`
1212
--> $DIR/issue-28837.rs:8:7
1313
|
1414
LL | a - a;
@@ -18,7 +18,7 @@ LL | a - a;
1818
|
1919
= note: an implementation of `std::ops::Sub` might be missing for `A`
2020

21-
error[E0369]: binary operation `*` cannot be applied to type `A`
21+
error[E0369]: cannot multiply `A` to `A`
2222
--> $DIR/issue-28837.rs:10:7
2323
|
2424
LL | a * a;
@@ -28,7 +28,7 @@ LL | a * a;
2828
|
2929
= note: an implementation of `std::ops::Mul` might be missing for `A`
3030

31-
error[E0369]: binary operation `/` cannot be applied to type `A`
31+
error[E0369]: cannot divide `A` by `A`
3232
--> $DIR/issue-28837.rs:12:7
3333
|
3434
LL | a / a;
@@ -38,7 +38,7 @@ LL | a / a;
3838
|
3939
= note: an implementation of `std::ops::Div` might be missing for `A`
4040

41-
error[E0369]: binary operation `%` cannot be applied to type `A`
41+
error[E0369]: cannot mod `A` by `A`
4242
--> $DIR/issue-28837.rs:14:7
4343
|
4444
LL | a % a;
@@ -48,7 +48,7 @@ LL | a % a;
4848
|
4949
= note: an implementation of `std::ops::Rem` might be missing for `A`
5050

51-
error[E0369]: binary operation `&` cannot be applied to type `A`
51+
error[E0369]: no implementation for `A & A`
5252
--> $DIR/issue-28837.rs:16:7
5353
|
5454
LL | a & a;
@@ -58,7 +58,7 @@ LL | a & a;
5858
|
5959
= note: an implementation of `std::ops::BitAnd` might be missing for `A`
6060

61-
error[E0369]: binary operation `|` cannot be applied to type `A`
61+
error[E0369]: no implementation for `A | A`
6262
--> $DIR/issue-28837.rs:18:7
6363
|
6464
LL | a | a;
@@ -68,7 +68,7 @@ LL | a | a;
6868
|
6969
= note: an implementation of `std::ops::BitOr` might be missing for `A`
7070

71-
error[E0369]: binary operation `<<` cannot be applied to type `A`
71+
error[E0369]: no implementation for `A << A`
7272
--> $DIR/issue-28837.rs:20:7
7373
|
7474
LL | a << a;
@@ -78,7 +78,7 @@ LL | a << a;
7878
|
7979
= note: an implementation of `std::ops::Shl` might be missing for `A`
8080

81-
error[E0369]: binary operation `>>` cannot be applied to type `A`
81+
error[E0369]: no implementation for `A >> A`
8282
--> $DIR/issue-28837.rs:22:7
8383
|
8484
LL | a >> a;

src/test/ui/issues/issue-31076.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Add<i32> for i32 {}
1111

1212
fn main() {
1313
let x = 5 + 6;
14-
//~^ ERROR binary operation `+` cannot be applied to type `{integer}`
14+
//~^ ERROR cannot add `{integer}` to `{integer}`
1515
let y = 5i32 + 6i32;
16-
//~^ ERROR binary operation `+` cannot be applied to type `i32`
16+
//~^ ERROR cannot add `i32` to `i32`
1717
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `+` cannot be applied to type `{integer}`
1+
error[E0369]: cannot add `{integer}` to `{integer}`
22
--> $DIR/issue-31076.rs:13:15
33
|
44
LL | let x = 5 + 6;
@@ -8,7 +8,7 @@ LL | let x = 5 + 6;
88
|
99
= note: an implementation of `std::ops::Add` might be missing for `{integer}`
1010

11-
error[E0369]: binary operation `+` cannot be applied to type `i32`
11+
error[E0369]: cannot add `i32` to `i32`
1212
--> $DIR/issue-31076.rs:15:18
1313
|
1414
LL | let y = 5i32 + 6i32;

src/test/ui/issues/issue-35668.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn func<'a, T>(a: &'a [T]) -> impl Iterator<Item=&'a T> {
22
a.iter().map(|a| a*a)
3-
//~^ ERROR binary operation `*` cannot be applied to type `&T`
3+
//~^ ERROR cannot multiply `&T` to `&T`
44
}
55

66
fn main() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `*` cannot be applied to type `&T`
1+
error[E0369]: cannot multiply `&T` to `&T`
22
--> $DIR/issue-35668.rs:2:23
33
|
44
LL | a.iter().map(|a| a*a)

src/test/ui/issues/issue-3820.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ impl Thing {
1111
fn main() {
1212
let u = Thing {x: 2};
1313
let _v = u.mul(&3); // This is ok
14-
let w = u * 3; //~ ERROR binary operation `*` cannot be applied to type `Thing`
14+
let w = u * 3; //~ ERROR cannot multiply `{integer}` to `Thing`
1515
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `*` cannot be applied to type `Thing`
1+
error[E0369]: cannot multiply `{integer}` to `Thing`
22
--> $DIR/issue-3820.rs:14:15
33
|
44
LL | let w = u * 3;

src/test/ui/issues/issue-40610.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ fn f(_: &[f32]) {}
22

33
fn main() {
44
() + f(&[1.0]);
5-
//~^ ERROR binary operation `+` cannot be applied to type `()`
5+
//~^ ERROR cannot add `()` to `()`
66
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0369]: binary operation `+` cannot be applied to type `()`
1+
error[E0369]: cannot add `()` to `()`
22
--> $DIR/issue-40610.rs:4:8
33
|
44
LL | () + f(&[1.0]);

0 commit comments

Comments
 (0)