Skip to content

False positive for unused_parens in x as (T) < y #106413

Closed
@lukas-code

Description

@lukas-code

Given the following code: Playground

fn main() {
    let _ = 1 as (i32) < 2;
}

The current output is:

warning: unnecessary parentheses around type
 --> src/main.rs:2:18
  |
2 |     let _ = 1 as (i32) < 2;
  |                  ^   ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 -     let _ = 1 as (i32) < 2;
2 +     let _ = 1 as i32 < 2;
  |

But with the suggestion applied the compiler displays an error with a different suggestion:

error: `<` is interpreted as a start of generic arguments for `i32`, not a comparison
 --> src/main.rs:2:22
  |
2 |     let _ = 1 as i32 < 2;
  |                      ^ -- interpreted as generic arguments
  |                      |
  |                      not interpreted as comparison
  |
help: try comparing the cast value
  |
2 |     let _ = (1 as i32) < 2;
  | 

Ideally the compiler should not output a warning and treat x as (T) < y and (x as T) < y as identical.

@rustbot label D-incorrect A-suggestion-diagnostics

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions