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

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

Closed
lukas-code opened this issue Jan 3, 2023 · 4 comments · Fixed by #115424
Closed

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

lukas-code opened this issue Jan 3, 2023 · 4 comments · Fixed by #115424
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lukas-code
Copy link
Contributor

lukas-code commented Jan 3, 2023

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

@lukas-code lukas-code added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 3, 2023
@rustbot rustbot added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Jan 3, 2023
@lyming2007
Copy link

@rustbot claim

@notJoon
Copy link
Contributor

notJoon commented Jan 5, 2023

I think it's relate with #22644 and #60146

@scottmcm
Copy link
Member

scottmcm commented Jan 6, 2023

It would be great if it could give

  |
2 -     let _ = 1 as (i32) < 2;
2 +     let _ = (1 as i32) < 2;
  |

since parenthesizing the as expression instead avoids the potential "is that a tuple?" confusion of (i32).

@kadiwa4
Copy link
Contributor

kadiwa4 commented Jan 23, 2023

Duplicate of #80636.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants