-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New lint: suspicious_unary_op_formatting
Lints when, on the RHS of a BinOp, there is a UnOp without a space before the operator but with a space after (e.g. foo >- 1). Signed-off-by: Nikos Filippakis <[email protected]>
- Loading branch information
Showing
7 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![warn(clippy::suspicious_unary_op_formatting)] | ||
|
||
#[rustfmt::skip] | ||
fn main() { | ||
// weird binary operator formatting: | ||
let a = 42; | ||
|
||
if a >- 30 { | ||
} else if a >=- 30 { | ||
} | ||
|
||
let b = true; | ||
let c = false; | ||
|
||
if b &&! c { | ||
} | ||
|
||
// those are ok: | ||
if a >-30 { | ||
} else if a < -30 { | ||
} else if b && !c { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: by not having a space between `>` and `-` it looks like `>-` is a single operator | ||
--> $DIR/suspicious_unary_op_formatting.rs:8:9 | ||
| | ||
LL | if a >- 30 { | ||
| ^^^^ | ||
| | ||
= note: `-D clippy::suspicious-unary-op-formatting` implied by `-D warnings` | ||
= help: put a space between `>` and `-` or remove the space after `-` | ||
|
||
error: by not having a space between `>=` and `-` it looks like `>=-` is a single operator | ||
--> $DIR/suspicious_unary_op_formatting.rs:9:16 | ||
| | ||
LL | } else if a >=- 30 { | ||
| ^^^^^ | ||
| | ||
= help: put a space between `>=` and `-` or remove the space after `-` | ||
|
||
error: by not having a space between `&&` and `!` it looks like `&&!` is a single operator | ||
--> $DIR/suspicious_unary_op_formatting.rs:15:9 | ||
| | ||
LL | if b &&! c { | ||
| ^^^^^ | ||
| | ||
= help: put a space between `&&` and `!` or remove the space after `!` | ||
|
||
error: aborting due to 3 previous errors | ||
|