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

Improve wording of "cannot multiply" type error #78063

Merged
merged 1 commit into from
Oct 21, 2020

Commits on Oct 18, 2020

  1. 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`
    camelid committed Oct 18, 2020
    Configuration menu
    Copy the full SHA
    7b33ae6 View commit details
    Browse the repository at this point in the history