Skip to content

Commit 887aa26

Browse files
committed
add more tests
1 parent 1ace535 commit 887aa26

File tree

3 files changed

+179
-1
lines changed

3 files changed

+179
-1
lines changed

tests/ui/if_not_else.fixed

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,46 @@ fn main() {
2828
} else {
2929
println!("Bunny");
3030
}
31+
32+
if (foo() && bla()) {
33+
println!("both true");
34+
} else {
35+
#[cfg(not(debug_assertions))]
36+
println!("not debug");
37+
#[cfg(debug_assertions)]
38+
println!("debug");
39+
if foo() {
40+
println!("foo");
41+
} else if bla() {
42+
println!("bla");
43+
} else {
44+
println!("both false");
45+
}
46+
}
47+
}
48+
49+
fn with_comments() {
50+
if foo() {
51+
println!("foo"); /* foo */
52+
} else {
53+
/* foo is false */
54+
println!("foo is false");
55+
}
56+
57+
if bla() {
58+
println!("bla"); // bla
59+
} else {
60+
// bla is false
61+
println!("bla");
62+
}
63+
}
64+
65+
fn with_annotations() {
66+
#[cfg(debug_assertions)]
67+
if foo() {
68+
println!("foo"); /* foo */
69+
} else {
70+
/* foo is false */
71+
println!("foo is false");
72+
}
3173
}

tests/ui/if_not_else.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,46 @@ fn main() {
2828
} else {
2929
println!("Bunny");
3030
}
31+
32+
if !(foo() && bla()) {
33+
#[cfg(not(debug_assertions))]
34+
println!("not debug");
35+
#[cfg(debug_assertions)]
36+
println!("debug");
37+
if foo() {
38+
println!("foo");
39+
} else if bla() {
40+
println!("bla");
41+
} else {
42+
println!("both false");
43+
}
44+
} else {
45+
println!("both true");
46+
}
47+
}
48+
49+
fn with_comments() {
50+
if !foo() {
51+
/* foo is false */
52+
println!("foo is false");
53+
} else {
54+
println!("foo"); /* foo */
55+
}
56+
57+
if !bla() {
58+
// bla is false
59+
println!("bla");
60+
} else {
61+
println!("bla"); // bla
62+
}
63+
}
64+
65+
fn with_annotations() {
66+
#[cfg(debug_assertions)]
67+
if !foo() {
68+
/* foo is false */
69+
println!("foo is false");
70+
} else {
71+
println!("foo"); /* foo */
72+
}
3173
}

tests/ui/if_not_else.stderr

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,99 @@ LL + println!("Bugs");
4242
LL + }
4343
|
4444

45-
error: aborting due to 2 previous errors
45+
error: unnecessary boolean `not` operation
46+
--> tests/ui/if_not_else.rs:32:5
47+
|
48+
LL | / if !(foo() && bla()) {
49+
LL | | #[cfg(not(debug_assertions))]
50+
LL | | println!("not debug");
51+
LL | | #[cfg(debug_assertions)]
52+
... |
53+
LL | | println!("both true");
54+
LL | | }
55+
| |_____^
56+
|
57+
help: try
58+
|
59+
LL ~ if (foo() && bla()) {
60+
LL + println!("both true");
61+
LL + } else {
62+
LL + #[cfg(not(debug_assertions))]
63+
LL + println!("not debug");
64+
LL + #[cfg(debug_assertions)]
65+
LL + println!("debug");
66+
LL + if foo() {
67+
LL + println!("foo");
68+
LL + } else if bla() {
69+
LL + println!("bla");
70+
LL + } else {
71+
LL + println!("both false");
72+
LL + }
73+
LL + }
74+
|
75+
76+
error: unnecessary boolean `not` operation
77+
--> tests/ui/if_not_else.rs:50:5
78+
|
79+
LL | / if !foo() {
80+
LL | | /* foo is false */
81+
LL | | println!("foo is false");
82+
LL | | } else {
83+
LL | | println!("foo"); /* foo */
84+
LL | | }
85+
| |_____^
86+
|
87+
help: try
88+
|
89+
LL ~ if foo() {
90+
LL + println!("foo"); /* foo */
91+
LL + } else {
92+
LL + /* foo is false */
93+
LL + println!("foo is false");
94+
LL + }
95+
|
96+
97+
error: unnecessary boolean `not` operation
98+
--> tests/ui/if_not_else.rs:57:5
99+
|
100+
LL | / if !bla() {
101+
LL | | // bla is false
102+
LL | | println!("bla");
103+
LL | | } else {
104+
LL | | println!("bla"); // bla
105+
LL | | }
106+
| |_____^
107+
|
108+
help: try
109+
|
110+
LL ~ if bla() {
111+
LL + println!("bla"); // bla
112+
LL + } else {
113+
LL + // bla is false
114+
LL + println!("bla");
115+
LL + }
116+
|
117+
118+
error: unnecessary boolean `not` operation
119+
--> tests/ui/if_not_else.rs:67:5
120+
|
121+
LL | / if !foo() {
122+
LL | | /* foo is false */
123+
LL | | println!("foo is false");
124+
LL | | } else {
125+
LL | | println!("foo"); /* foo */
126+
LL | | }
127+
| |_____^
128+
|
129+
help: try
130+
|
131+
LL ~ if foo() {
132+
LL + println!("foo"); /* foo */
133+
LL + } else {
134+
LL + /* foo is false */
135+
LL + println!("foo is false");
136+
LL + }
137+
|
138+
139+
error: aborting due to 6 previous errors
46140

0 commit comments

Comments
 (0)