Skip to content

Commit ffb62b0

Browse files
authored
Rollup merge of rust-lang#78063 - camelid:improve-cannot-multiply-error, r=estebank
Improve wording of "cannot multiply" type error For example, if you had this code: fn foo(x: i32, y: f32) -> f32 { x * y } You would get this error: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` However, that's not usually how people describe multiplication. People usually describe multiplication like how the division error words it: error[E0277]: cannot divide `i32` by `f32` --> src/lib.rs:2:7 | 2 | x / y | ^ no implementation for `i32 / f32` | = help: the trait `Div<f32>` is not implemented for `i32` So that's what this change does. It changes this: error[E0277]: cannot multiply `f32` to `i32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32` To this: error[E0277]: cannot multiply `i32` by `f32` --> src/lib.rs:2:7 | 2 | x * y | ^ no implementation for `i32 * f32` | = help: the trait `Mul<f32>` is not implemented for `i32`
2 parents 6ef6a54 + 12aeee0 commit ffb62b0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

core/src/ops/arith.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
302302
#[lang = "mul"]
303303
#[stable(feature = "rust1", since = "1.0.0")]
304304
#[rustc_on_unimplemented(
305-
message = "cannot multiply `{Rhs}` to `{Self}`",
305+
message = "cannot multiply `{Self}` by `{Rhs}`",
306306
label = "no implementation for `{Self} * {Rhs}`"
307307
)]
308308
#[doc(alias = "*")]
@@ -826,7 +826,7 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }
826826
#[lang = "mul_assign"]
827827
#[stable(feature = "op_assign_traits", since = "1.8.0")]
828828
#[rustc_on_unimplemented(
829-
message = "cannot multiply-assign `{Rhs}` to `{Self}`",
829+
message = "cannot multiply-assign `{Self}` by `{Rhs}`",
830830
label = "no implementation for `{Self} *= {Rhs}`"
831831
)]
832832
#[doc(alias = "*")]

0 commit comments

Comments
 (0)