mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
ddc718087f
* Ran automatic naming update * Formalized rename of `cyclomatic_complexity` to `cognitive_complexity` ** Added the rename to `lib.rs` ** Added rename test * Added warning for deprecated key `cyclomatic_complexity_threshold` and tests for it * Added deprecation status for Clippy's builtin attribute * Updated tests for new builtin attribute renaming
176 lines
3.4 KiB
Rust
176 lines
3.4 KiB
Rust
// run-rustfix
|
|
#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
|
|
|
|
#[rustfmt::skip]
|
|
#[warn(clippy::collapsible_if)]
|
|
fn main() {
|
|
let x = "hello";
|
|
let y = "world";
|
|
if x == "hello" && y == "world" {
|
|
println!("Hello world!");
|
|
}
|
|
|
|
if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
|
|
println!("Hello world!");
|
|
}
|
|
|
|
if x == "hello" && x == "world" && (y == "world" || y == "hello") {
|
|
println!("Hello world!");
|
|
}
|
|
|
|
if (x == "hello" || x == "world") && y == "world" && y == "hello" {
|
|
println!("Hello world!");
|
|
}
|
|
|
|
if x == "hello" && x == "world" && y == "world" && y == "hello" {
|
|
println!("Hello world!");
|
|
}
|
|
|
|
if 42 == 1337 && 'a' != 'A' {
|
|
println!("world!")
|
|
}
|
|
|
|
// Collapse `else { if .. }` to `else if ..`
|
|
if x == "hello" {
|
|
print!("Hello ");
|
|
} else if y == "world" {
|
|
println!("world!")
|
|
}
|
|
|
|
if x == "hello" {
|
|
print!("Hello ");
|
|
} else if let Some(42) = Some(42) {
|
|
println!("world!")
|
|
}
|
|
|
|
if x == "hello" {
|
|
print!("Hello ");
|
|
} else if y == "world" {
|
|
println!("world")
|
|
}
|
|
else {
|
|
println!("!")
|
|
}
|
|
|
|
if x == "hello" {
|
|
print!("Hello ");
|
|
} else if let Some(42) = Some(42) {
|
|
println!("world")
|
|
}
|
|
else {
|
|
println!("!")
|
|
}
|
|
|
|
if let Some(42) = Some(42) {
|
|
print!("Hello ");
|
|
} else if let Some(42) = Some(42) {
|
|
println!("world")
|
|
}
|
|
else {
|
|
println!("!")
|
|
}
|
|
|
|
if let Some(42) = Some(42) {
|
|
print!("Hello ");
|
|
} else if x == "hello" {
|
|
println!("world")
|
|
}
|
|
else {
|
|
println!("!")
|
|
}
|
|
|
|
if let Some(42) = Some(42) {
|
|
print!("Hello ");
|
|
} else if let Some(42) = Some(42) {
|
|
println!("world")
|
|
}
|
|
else {
|
|
println!("!")
|
|
}
|
|
|
|
// Works because any if with an else statement cannot be collapsed.
|
|
if x == "hello" {
|
|
if y == "world" {
|
|
println!("Hello world!");
|
|
}
|
|
} else {
|
|
println!("Not Hello world");
|
|
}
|
|
|
|
if x == "hello" {
|
|
if y == "world" {
|
|
println!("Hello world!");
|
|
} else {
|
|
println!("Hello something else");
|
|
}
|
|
}
|
|
|
|
if x == "hello" {
|
|
print!("Hello ");
|
|
if y == "world" {
|
|
println!("world!")
|
|
}
|
|
}
|
|
|
|
if true {
|
|
} else {
|
|
assert!(true); // assert! is just an `if`
|
|
}
|
|
|
|
|
|
// The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
|
|
if x == "hello" {// Not collapsible
|
|
if y == "world" {
|
|
println!("Hello world!");
|
|
}
|
|
}
|
|
|
|
if x == "hello" { // Not collapsible
|
|
if y == "world" {
|
|
println!("Hello world!");
|
|
}
|
|
}
|
|
|
|
if x == "hello" {
|
|
// Not collapsible
|
|
if y == "world" {
|
|
println!("Hello world!");
|
|
}
|
|
}
|
|
|
|
if x == "hello" && y == "world" { // Collapsible
|
|
println!("Hello world!");
|
|
}
|
|
|
|
if x == "hello" {
|
|
print!("Hello ");
|
|
} else {
|
|
// Not collapsible
|
|
if y == "world" {
|
|
println!("world!")
|
|
}
|
|
}
|
|
|
|
if x == "hello" {
|
|
print!("Hello ");
|
|
} else {
|
|
// Not collapsible
|
|
if let Some(42) = Some(42) {
|
|
println!("world!")
|
|
}
|
|
}
|
|
|
|
if x == "hello" {
|
|
/* Not collapsible */
|
|
if y == "world" {
|
|
println!("Hello world!");
|
|
}
|
|
}
|
|
|
|
if x == "hello" { /* Not collapsible */
|
|
if y == "world" {
|
|
println!("Hello world!");
|
|
}
|
|
}
|
|
}
|