Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lapla-cogito committed Dec 24, 2024
1 parent 1ace535 commit 887aa26
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 1 deletion.
42 changes: 42 additions & 0 deletions tests/ui/if_not_else.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,46 @@ fn main() {
} 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");
}
}
42 changes: 42 additions & 0 deletions tests/ui/if_not_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,46 @@ fn main() {
} else {
println!("Bunny");
}

if !(foo() && bla()) {
#[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");
}
} else {
println!("both true");
}
}

fn with_comments() {
if !foo() {
/* foo is false */
println!("foo is false");
} else {
println!("foo"); /* foo */
}

if !bla() {
// bla is false
println!("bla");
} else {
println!("bla"); // bla
}
}

fn with_annotations() {
#[cfg(debug_assertions)]
if !foo() {
/* foo is false */
println!("foo is false");
} else {
println!("foo"); /* foo */
}
}
96 changes: 95 additions & 1 deletion tests/ui/if_not_else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,99 @@ LL + println!("Bugs");
LL + }
|

error: aborting due to 2 previous errors
error: unnecessary boolean `not` operation
--> tests/ui/if_not_else.rs:32:5
|
LL | / if !(foo() && bla()) {
LL | | #[cfg(not(debug_assertions))]
LL | | println!("not debug");
LL | | #[cfg(debug_assertions)]
... |
LL | | println!("both true");
LL | | }
| |_____^
|
help: try
|
LL ~ if (foo() && bla()) {
LL + println!("both true");
LL + } else {
LL + #[cfg(not(debug_assertions))]
LL + println!("not debug");
LL + #[cfg(debug_assertions)]
LL + println!("debug");
LL + if foo() {
LL + println!("foo");
LL + } else if bla() {
LL + println!("bla");
LL + } else {
LL + println!("both false");
LL + }
LL + }
|

error: unnecessary boolean `not` operation
--> tests/ui/if_not_else.rs:50:5
|
LL | / if !foo() {
LL | | /* foo is false */
LL | | println!("foo is false");
LL | | } else {
LL | | println!("foo"); /* foo */
LL | | }
| |_____^
|
help: try
|
LL ~ if foo() {
LL + println!("foo"); /* foo */
LL + } else {
LL + /* foo is false */
LL + println!("foo is false");
LL + }
|

error: unnecessary boolean `not` operation
--> tests/ui/if_not_else.rs:57:5
|
LL | / if !bla() {
LL | | // bla is false
LL | | println!("bla");
LL | | } else {
LL | | println!("bla"); // bla
LL | | }
| |_____^
|
help: try
|
LL ~ if bla() {
LL + println!("bla"); // bla
LL + } else {
LL + // bla is false
LL + println!("bla");
LL + }
|

error: unnecessary boolean `not` operation
--> tests/ui/if_not_else.rs:67:5
|
LL | / if !foo() {
LL | | /* foo is false */
LL | | println!("foo is false");
LL | | } else {
LL | | println!("foo"); /* foo */
LL | | }
| |_____^
|
help: try
|
LL ~ if foo() {
LL + println!("foo"); /* foo */
LL + } else {
LL + /* foo is false */
LL + println!("foo is false");
LL + }
|

error: aborting due to 6 previous errors

0 comments on commit 887aa26

Please sign in to comment.