Skip to content

Forbid Not operator (!) #8725

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

Open
Nugine opened this issue Apr 20, 2022 · 2 comments
Open

Forbid Not operator (!) #8725

Nugine opened this issue Apr 20, 2022 · 2 comments
Labels
A-lint Area: New lints L-restriction Lint: Belongs in the restriction lint group

Comments

@Nugine
Copy link

Nugine commented Apr 20, 2022

What it does

Forbid the usage of not operator (!) in if $expr, while $expr and assert!($expr).
Use .not() instead. (std::ops::Not)

Lint Name

not_operator_used

Category

style
restriction

Advantage

.not() is more conspicuous than ! and looks continuous.

Drawbacks

No response

Example

assert!(!expr);

if !expr {
   // ...
}

while !expr {
   // ...
}

Could be written as:

use std::ops::Not;

assert!(expr.not());

if expr.not() {
   // ...
}

while expr.not() {
   // ...
}
@Nugine Nugine added the A-lint Area: New lints label Apr 20, 2022
@Serial-ATA
Copy link
Contributor

This should definitely be in the restriction category

@llogiq llogiq added the L-restriction Lint: Belongs in the restriction lint group label Apr 20, 2022
@xFrednet
Copy link
Member

This sounds like a specialization of #6286, I would like to have one lint for all operators which is configurable. Then we could also have it in the pedantic group. But the implementation will be a bit more work 😅 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-restriction Lint: Belongs in the restriction lint group
Projects
None yet
Development

No branches or pull requests

4 participants