Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing confusion between mod and remainder #107389

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ 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 calculate the remainder of `{lhs_ty}` divided by `{rhs_ty}`"
)
}
hir::BinOpKind::BitAnd => {
format!("no implementation for `{lhs_ty} & {rhs_ty}`")
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/ops/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 calculate the remainder of `{Self}` divided by `{Rhs}`",
label = "no implementation for `{Self} % {Rhs}`"
)]
#[doc(alias = "%")]
Expand Down Expand Up @@ -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 calculate and assign the remainder of `{Self}` divided by `{Rhs}`",
label = "no implementation for `{Self} %= {Rhs}`"
)]
#[doc(alias = "%")]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/binop/binary-op-on-double-ref.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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 calculate the remainder of `&&{integer}` divided by `{integer}`
});
println!("{:?}", vr);
}
2 changes: 1 addition & 1 deletion tests/ui/binop/binary-op-on-double-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 calculate the remainder of `&&{integer}` divided by `{integer}`
});
println!("{:?}", vr);
}
2 changes: 1 addition & 1 deletion tests/ui/binop/binary-op-on-double-ref.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0369]: cannot mod `&&{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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/binop/issue-28837.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 calculate the remainder of `A` divided by `A`

a & a; //~ ERROR no implementation for `A & A`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/binop/issue-28837.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 calculate the remainder of `A` divided by `A`
--> $DIR/issue-28837.rs:14:7
|
LL | a % a;
Expand Down