forked from rust-lang/rust-clippy
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-fix
if_not_else
(rust-lang#13809)
fix rust-lang#13411 The `if_not_else` lint can be fixed automatically, but the issue above reports that there is no implementation to do so. Therefore, this PR implements it. ---- changelog: [`if_not_else`]: make suggestions for modified code
- Loading branch information
Showing
4 changed files
with
279 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#![warn(clippy::all)] | ||
#![warn(clippy::if_not_else)] | ||
|
||
fn foo() -> bool { | ||
unimplemented!() | ||
} | ||
fn bla() -> bool { | ||
unimplemented!() | ||
} | ||
|
||
fn main() { | ||
if bla() { | ||
println!("Bunny"); | ||
} else { | ||
//~^ ERROR: unnecessary boolean `not` operation | ||
println!("Bugs"); | ||
} | ||
if 4 == 5 { | ||
println!("Bunny"); | ||
} else { | ||
//~^ ERROR: unnecessary `!=` operation | ||
println!("Bugs"); | ||
} | ||
if !foo() { | ||
println!("Foo"); | ||
} else if !bla() { | ||
println!("Bugs"); | ||
} else { | ||
println!("Bunny"); | ||
} | ||
|
||
if (foo() && bla()) { | ||
println!("both true"); | ||
} else { | ||
#[cfg(not(debug_assertions))] | ||
println!("not debug"); | ||
#[cfg(debug_assertions)] | ||
println!("debug"); | ||
if foo() { | ||
println!("foo"); | ||
} else if bla() { | ||
println!("bla"); | ||
} else { | ||
println!("both false"); | ||
} | ||
} | ||
} | ||
|
||
fn with_comments() { | ||
if foo() { | ||
println!("foo"); /* foo */ | ||
} else { | ||
/* foo is false */ | ||
println!("foo is false"); | ||
} | ||
|
||
if bla() { | ||
println!("bla"); // bla | ||
} else { | ||
// bla is false | ||
println!("bla"); | ||
} | ||
} | ||
|
||
fn with_annotations() { | ||
#[cfg(debug_assertions)] | ||
if foo() { | ||
println!("foo"); /* foo */ | ||
} else { | ||
/* foo is false */ | ||
println!("foo is false"); | ||
} | ||
} |
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