-
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.
Auto merge of #4615 - nikofil:suspicious_unary_op_formatting, r=flip1995
New lint: suspicious_unary_op_formatting fixes #4228 changelog: New lint: [`suspicious_unary_op_formatting`]
- Loading branch information
Showing
7 changed files
with
134 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 {} | ||
if a >=- 30 {} | ||
|
||
let b = true; | ||
let c = false; | ||
|
||
if b &&! c {} | ||
|
||
if a >- 30 {} | ||
|
||
// those are ok: | ||
if a >-30 {} | ||
if a < -30 {} | ||
if b && !c {} | ||
if a > - 30 {} | ||
} |
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,35 @@ | ||
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 `-` and 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:9 | ||
| | ||
LL | if a >=- 30 {} | ||
| ^^^^^ | ||
| | ||
= help: put a space between `>=` and `-` and 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:14:9 | ||
| | ||
LL | if b &&! c {} | ||
| ^^^^^ | ||
| | ||
= help: put a space between `&&` and `!` and 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:16:9 | ||
| | ||
LL | if a >- 30 {} | ||
| ^^^^^^ | ||
| | ||
= help: put a space between `>` and `-` and remove the space after `-` | ||
|
||
error: aborting due to 4 previous errors | ||
|