]> git.lizzy.rs Git - rust.git/commit
Provide suggestion to convert numeric op LHS rather than unwrapping RHS
authorAyaz Hafiz <ayaz.hafiz.1@gmail.com>
Tue, 9 Jun 2020 18:45:40 +0000 (11:45 -0700)
committerAyaz Hafiz <ayaz.hafiz.1@gmail.com>
Thu, 11 Jun 2020 16:04:24 +0000 (09:04 -0700)
commite243f623174e661e7e2392eb234a0af9ce9129cd
treea1b5c451a08651cda180c8d4f94d505293b3f671
parent50c0192c64241d723066add22c53d472e2b9cba9
Provide suggestion to convert numeric op LHS rather than unwrapping RHS

Given a code

```rust
fn foo(x: u8, y: u32) -> bool {
    x > y
}
fn main() {}
```

it could be more helpful to provide a suggestion to do "u32::from(x)"
rather than "y.try_into().unwrap()", since the latter may panic.

We do this by passing the LHS of a binary expression up the stack into
the coercion checker.

Closes #73145
src/librustc_typeck/check/coercion.rs
src/librustc_typeck/check/demand.rs
src/librustc_typeck/check/expr.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/op.rs
src/test/ui/numeric/numeric-cast-binop.rs [new file with mode: 0644]
src/test/ui/numeric/numeric-cast-binop.stderr [new file with mode: 0644]