-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Uplift clippy::double_neg into rustc #82987
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
A concrete example: fn main() {
let a = 1;
let _b = --a;
} compiles without any warnings |
Clippy spots it: warning: `--x` could be misinterpreted as pre-decrement by C programmers, is usually a no-op
--> src/main.rs:3:14
|
3 | let _b = --a;
| ^^^
|
= note: `#[warn(clippy::double_neg)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_neg So you're asking to move this lint from Clippy to rustc. |
I think I can tackle this one - should I start a PR? |
This was referenced Sep 5, 2021
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Apr 3, 2022
Suggest `i += 1` when we see `i++` or `++i` Closes rust-lang#83502 (for `i++` and `++i`; `--i` should be covered by rust-lang#82987, and `i--` is tricky to handle). This is a continuation of rust-lang#83536. r? `@estebank`
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Jan 27, 2025
Rollup merge of rust-lang#126604 - kadiwa4:uplift_double_negation, r=nnethercote Uplift `clippy::double_neg` lint as `double_negations` Warns about cases like this: ```rust fn main() { let x = 1; let _b = --x; //~ WARN use of a double negation } ``` The intent is to keep people from thinking that `--x` is a prefix decrement operator. `++x`, `x++` and `x--` are invalid expressions and already have a helpful diagnostic. I didn't add a machine-applicable suggestion to the lint because it's not entirely clear what the programmer was trying to achieve with the `--x` operation. The code that triggers the lint should always be reviewed manually. Closes rust-lang#82987
bors
pushed a commit
to rust-lang-ci/rust
that referenced
this issue
Jan 28, 2025
…nnethercote Uplift `clippy::double_neg` lint as `double_negations` Warns about cases like this: ```rust fn main() { let x = 1; let _b = --x; //~ WARN use of a double negation } ``` The intent is to keep people from thinking that `--x` is a prefix decrement operator. `++x`, `x++` and `x--` are invalid expressions and already have a helpful diagnostic. I didn't add a machine-applicable suggestion to the lint because it's not entirely clear what the programmer was trying to achieve with the `--x` operation. The code that triggers the lint should always be reviewed manually. Closes rust-lang#82987
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
See this https://dtolnay.github.io/rust-quiz/17
I agree with our position on the inclusion of --/++ in Rust, however currently we just silently treat --i as -(-i), which means that users who are coming from C++ and C get absolutely no warning that their code is going to do something entirely different than they expect - and there's arguably no use case for an unbracketed - -i : its the same as a literal i.
I expected to see this happen:
A warning, or an error: "attempt to use unsupported post-increment operator. Use +=1 instead". Or something like that.
Instead, this happened: explanation
Meta
I'm not sure what rustc version the rust-quiz website is running.
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: