Closed
Description
Code
fn main() {
let a: i32 = 1;
let b: i64 = 1;
if b - a as (i64) < 0 {
println!(":D");
}
}
Current output
warning: unnecessary parentheses around type
--> src/main.rs:4:17
|
4 | if b - a as (i64) < 0 {
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
4 - if b - a as (i64) < 0 {
4 + if b - a as i64 < 0 {
|
warning: `playground` (bin "playground") generated 1 warning (run `cargo fix --bin "playground"` to apply 1 suggestion)
Desired output
--no output--
Rationale and extra context
The code uses a cast followed by a less-than operator. When parens are removed, the compiler errors:
error: `<` is interpreted as a start of generic arguments for `i64`, not a comparison
--> src/main.rs:4:21
|
4 | if b - a as i64 < 0 {
| ^ --- interpreted as generic arguments
| |
| not interpreted as comparison
|
help: try comparing the cast value
|
4 | if b - (a as i64) < 0 {
| + +
This is not a particularly problematic issue as the suggestion given in this output does not produce any wrong diagnostics, but the help given in the problematic output does cause a compiler error which was not present previously, so I think it's an incorrect warning.
Using parens like in the example does feel like bad style, but it should not generate this particular warning.
Other cases
No response
Anything else?
No response