Skip to content

Commit eac5fb8

Browse files
authored
Rollup merge of #67189 - LeSeulArtichaut:binop-wording, r=estebank
Unify binop wording Closes #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

Lines changed: 63 additions & 22 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)