From e02517d753bae44b2150aa23ab3bca694097ac96 Mon Sep 17 00:00:00 2001 From: Matthias Kaak Date: Fri, 27 Jan 2023 21:01:07 +0000 Subject: [PATCH 1/3] Fixed confusement between mod and remainder --- compiler/rustc_hir_typeck/src/op.rs | 2 +- library/core/src/ops/arith.rs | 4 ++-- tests/ui/binop/binary-op-on-double-ref.fixed | 2 +- tests/ui/binop/binary-op-on-double-ref.rs | 2 +- tests/ui/binop/binary-op-on-double-ref.stderr | 2 +- tests/ui/binop/issue-28837.rs | 2 +- tests/ui/binop/issue-28837.stderr | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 78cea1f4d8d3e..60c8c0f64fe24 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -335,7 +335,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("cannot divide `{lhs_ty}` by `{rhs_ty}`") } hir::BinOpKind::Rem => { - format!("cannot mod `{lhs_ty}` by `{rhs_ty}`") + format!("cannot rem `{lhs_ty}` by `{rhs_ty}`") } hir::BinOpKind::BitAnd => { format!("no implementation for `{lhs_ty} & {rhs_ty}`") diff --git a/library/core/src/ops/arith.rs b/library/core/src/ops/arith.rs index 75c52d3ecfc8b..b9803c957b16a 100644 --- a/library/core/src/ops/arith.rs +++ b/library/core/src/ops/arith.rs @@ -545,7 +545,7 @@ div_impl_float! { f32 f64 } #[lang = "rem"] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented( - message = "cannot mod `{Self}` by `{Rhs}`", + message = "cannot rem `{Self}` by `{Rhs}`", label = "no implementation for `{Self} % {Rhs}`" )] #[doc(alias = "%")] @@ -981,7 +981,7 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } #[lang = "rem_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] #[rustc_on_unimplemented( - message = "cannot mod-assign `{Self}` by `{Rhs}``", + message = "cannot rem-assign `{Self}` by `{Rhs}``", label = "no implementation for `{Self} %= {Rhs}`" )] #[doc(alias = "%")] diff --git a/tests/ui/binop/binary-op-on-double-ref.fixed b/tests/ui/binop/binary-op-on-double-ref.fixed index de9dc19af29be..89829efeaeb33 100644 --- a/tests/ui/binop/binary-op-on-double-ref.fixed +++ b/tests/ui/binop/binary-op-on-double-ref.fixed @@ -3,7 +3,7 @@ fn main() { let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; let vr = v.iter().filter(|x| { *x % 2 == 0 - //~^ ERROR cannot mod `&&{integer}` by `{integer}` + //~^ ERROR cannot rem `&&{integer}` by `{integer}` }); println!("{:?}", vr); } diff --git a/tests/ui/binop/binary-op-on-double-ref.rs b/tests/ui/binop/binary-op-on-double-ref.rs index 2616c560cbefb..57c5d8b52c8d4 100644 --- a/tests/ui/binop/binary-op-on-double-ref.rs +++ b/tests/ui/binop/binary-op-on-double-ref.rs @@ -3,7 +3,7 @@ fn main() { let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; let vr = v.iter().filter(|x| { x % 2 == 0 - //~^ ERROR cannot mod `&&{integer}` by `{integer}` + //~^ ERROR cannot rem `&&{integer}` by `{integer}` }); println!("{:?}", vr); } diff --git a/tests/ui/binop/binary-op-on-double-ref.stderr b/tests/ui/binop/binary-op-on-double-ref.stderr index 34826d2f4bf7a..e597e1b27e0c5 100644 --- a/tests/ui/binop/binary-op-on-double-ref.stderr +++ b/tests/ui/binop/binary-op-on-double-ref.stderr @@ -1,4 +1,4 @@ -error[E0369]: cannot mod `&&{integer}` by `{integer}` +error[E0369]: cannot rem `&&{integer}` by `{integer}` --> $DIR/binary-op-on-double-ref.rs:5:11 | LL | x % 2 == 0 diff --git a/tests/ui/binop/issue-28837.rs b/tests/ui/binop/issue-28837.rs index 9719c3afa68c1..002a5b94565b5 100644 --- a/tests/ui/binop/issue-28837.rs +++ b/tests/ui/binop/issue-28837.rs @@ -11,7 +11,7 @@ fn main() { a / a; //~ ERROR cannot divide `A` by `A` - a % a; //~ ERROR cannot mod `A` by `A` + a % a; //~ ERROR cannot rem `A` by `A` a & a; //~ ERROR no implementation for `A & A` diff --git a/tests/ui/binop/issue-28837.stderr b/tests/ui/binop/issue-28837.stderr index 6e236ca5296a1..2d4849ca5cb85 100644 --- a/tests/ui/binop/issue-28837.stderr +++ b/tests/ui/binop/issue-28837.stderr @@ -62,7 +62,7 @@ LL | struct A; note: the trait `Div` must be implemented --> $SRC_DIR/core/src/ops/arith.rs:LL:COL -error[E0369]: cannot mod `A` by `A` +error[E0369]: cannot rem `A` by `A` --> $DIR/issue-28837.rs:14:7 | LL | a % a; From 8d7b092a11df9b0e885f9af93b56759f8012e3ba Mon Sep 17 00:00:00 2001 From: Matthias Kaak Date: Mon, 30 Jan 2023 19:54:33 +0000 Subject: [PATCH 2/3] Improved wording of error messages of missing remainder implementations --- compiler/rustc_hir_typeck/src/op.rs | 2 +- library/core/src/ops/arith.rs | 4 ++-- tests/ui/binop/binary-op-on-double-ref.fixed | 2 +- tests/ui/binop/binary-op-on-double-ref.rs | 2 +- tests/ui/binop/binary-op-on-double-ref.stderr | 2 +- tests/ui/binop/issue-28837.rs | 2 +- tests/ui/binop/issue-28837.stderr | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 60c8c0f64fe24..278f720b62ebe 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -335,7 +335,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("cannot divide `{lhs_ty}` by `{rhs_ty}`") } hir::BinOpKind::Rem => { - format!("cannot rem `{lhs_ty}` by `{rhs_ty}`") + format!("cannot calculate the remainder of `{lhs_ty}` divided by `{rhs_ty}`") } hir::BinOpKind::BitAnd => { format!("no implementation for `{lhs_ty} & {rhs_ty}`") diff --git a/library/core/src/ops/arith.rs b/library/core/src/ops/arith.rs index b9803c957b16a..cc13db5c9565b 100644 --- a/library/core/src/ops/arith.rs +++ b/library/core/src/ops/arith.rs @@ -545,7 +545,7 @@ div_impl_float! { f32 f64 } #[lang = "rem"] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented( - message = "cannot rem `{Self}` by `{Rhs}`", + message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}`", label = "no implementation for `{Self} % {Rhs}`" )] #[doc(alias = "%")] @@ -981,7 +981,7 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } #[lang = "rem_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] #[rustc_on_unimplemented( - message = "cannot rem-assign `{Self}` by `{Rhs}``", + message = "cannot calculate and assign the remainder of `{Self}` divided by `{Rhs}`", label = "no implementation for `{Self} %= {Rhs}`" )] #[doc(alias = "%")] diff --git a/tests/ui/binop/binary-op-on-double-ref.fixed b/tests/ui/binop/binary-op-on-double-ref.fixed index 89829efeaeb33..586d2568c306f 100644 --- a/tests/ui/binop/binary-op-on-double-ref.fixed +++ b/tests/ui/binop/binary-op-on-double-ref.fixed @@ -3,7 +3,7 @@ fn main() { let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; let vr = v.iter().filter(|x| { *x % 2 == 0 - //~^ ERROR cannot rem `&&{integer}` by `{integer}` + //~^ ERROR cannot calculate the remainder of `&&{integer}` divided by `{integer}` }); println!("{:?}", vr); } diff --git a/tests/ui/binop/binary-op-on-double-ref.rs b/tests/ui/binop/binary-op-on-double-ref.rs index 57c5d8b52c8d4..48ee445466e35 100644 --- a/tests/ui/binop/binary-op-on-double-ref.rs +++ b/tests/ui/binop/binary-op-on-double-ref.rs @@ -3,7 +3,7 @@ fn main() { let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9]; let vr = v.iter().filter(|x| { x % 2 == 0 - //~^ ERROR cannot rem `&&{integer}` by `{integer}` + //~^ ERROR cannot calculate the remainder of `&&{integer}` divided by `{integer}` }); println!("{:?}", vr); } diff --git a/tests/ui/binop/binary-op-on-double-ref.stderr b/tests/ui/binop/binary-op-on-double-ref.stderr index e597e1b27e0c5..2e8aeebc681d6 100644 --- a/tests/ui/binop/binary-op-on-double-ref.stderr +++ b/tests/ui/binop/binary-op-on-double-ref.stderr @@ -1,4 +1,4 @@ -error[E0369]: cannot rem `&&{integer}` by `{integer}` +error[E0369]: cannot calculate the remainder of `&&{integer}` divided by `{integer}` --> $DIR/binary-op-on-double-ref.rs:5:11 | LL | x % 2 == 0 diff --git a/tests/ui/binop/issue-28837.rs b/tests/ui/binop/issue-28837.rs index 002a5b94565b5..54c8838e48f11 100644 --- a/tests/ui/binop/issue-28837.rs +++ b/tests/ui/binop/issue-28837.rs @@ -11,7 +11,7 @@ fn main() { a / a; //~ ERROR cannot divide `A` by `A` - a % a; //~ ERROR cannot rem `A` by `A` + a % a; //~ ERROR cannot calculate the remainder of `A` divided by `A` a & a; //~ ERROR no implementation for `A & A` diff --git a/tests/ui/binop/issue-28837.stderr b/tests/ui/binop/issue-28837.stderr index 2d4849ca5cb85..cca1da3b6ac49 100644 --- a/tests/ui/binop/issue-28837.stderr +++ b/tests/ui/binop/issue-28837.stderr @@ -62,7 +62,7 @@ LL | struct A; note: the trait `Div` must be implemented --> $SRC_DIR/core/src/ops/arith.rs:LL:COL -error[E0369]: cannot rem `A` by `A` +error[E0369]: cannot calculate the remainder of `A` divided by `A` --> $DIR/issue-28837.rs:14:7 | LL | a % a; From af9671fd28601c95c4770aa47c733f81ad6ab607 Mon Sep 17 00:00:00 2001 From: Matthias Kaak Date: Mon, 30 Jan 2023 20:04:33 +0000 Subject: [PATCH 3/3] Ran rustfmt --- compiler/rustc_hir_typeck/src/op.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 278f720b62ebe..67769fe4478a2 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -335,7 +335,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("cannot divide `{lhs_ty}` by `{rhs_ty}`") } hir::BinOpKind::Rem => { - format!("cannot calculate the remainder of `{lhs_ty}` divided by `{rhs_ty}`") + format!( + "cannot calculate the remainder of `{lhs_ty}` divided by `{rhs_ty}`" + ) } hir::BinOpKind::BitAnd => { format!("no implementation for `{lhs_ty} & {rhs_ty}`")