forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
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 rust-lang#10350 - J-ZhengLi:issue_10272, r=xFrednet
enhance [`ifs_same_cond`] to warn same immutable method calls as well fixes: rust-lang#10272 --- changelog: Enhancement: [`ifs_same_cond`]: Now also detects immutable method calls. [rust-lang#10350](rust-lang/rust-clippy#10350) <!-- changelog_checked -->
- Loading branch information
Showing
11 changed files
with
196 additions
and
58 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
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 @@ | ||
ignore-interior-mutability = ["std::cell::Cell"] |
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,18 @@ | ||
#![warn(clippy::ifs_same_cond)] | ||
#![allow(clippy::if_same_then_else, clippy::comparison_chain)] | ||
|
||
fn main() {} | ||
|
||
fn issue10272() { | ||
use std::cell::Cell; | ||
|
||
// Because the `ignore-interior-mutability` configuration | ||
// is set to ignore for `std::cell::Cell`, the following `get()` calls | ||
// should trigger warning | ||
let x = Cell::new(true); | ||
if x.get() { | ||
} else if !x.take() { | ||
} else if x.get() { | ||
} else { | ||
} | ||
} |
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,15 @@ | ||
error: this `if` has the same condition as a previous `if` | ||
--> $DIR/ifs_same_cond.rs:15:15 | ||
| | ||
LL | } else if x.get() { | ||
| ^^^^^^^ | ||
| | ||
note: same as this | ||
--> $DIR/ifs_same_cond.rs:13:8 | ||
| | ||
LL | if x.get() { | ||
| ^^^^^^^ | ||
= note: `-D clippy::ifs-same-cond` implied by `-D warnings` | ||
|
||
error: aborting due to previous error | ||
|
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