Skip to content

Commit f728bcd

Browse files
committed
Auto merge of #5066 - JohnTitor:split-up-1447, r=llogiq
Split up `if_same_then_else` ui test Part of #2038 changelog: none
2 parents 0a7003e + dfab83f commit f728bcd

File tree

4 files changed

+279
-280
lines changed

4 files changed

+279
-280
lines changed

tests/ui/if_same_then_else.rs

+3-134
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
#![warn(clippy::if_same_then_else)]
22
#![allow(
33
clippy::blacklisted_name,
4-
clippy::collapsible_if,
5-
clippy::cognitive_complexity,
64
clippy::eq_op,
7-
clippy::needless_return,
85
clippy::never_loop,
96
clippy::no_effect,
10-
clippy::zero_divided_by_zero,
11-
clippy::unused_unit
7+
clippy::unused_unit,
8+
clippy::zero_divided_by_zero
129
)]
1310

1411
struct Foo {
@@ -19,7 +16,7 @@ fn foo() -> bool {
1916
unimplemented!()
2017
}
2118

22-
fn if_same_then_else() -> Result<&'static str, ()> {
19+
fn if_same_then_else() {
2320
if true {
2421
Foo { bar: 42 };
2522
0..10;
@@ -94,27 +91,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
9491
42
9592
};
9693

97-
if true {
98-
for _ in &[42] {
99-
let foo: &Option<_> = &Some::<u8>(42);
100-
if true {
101-
break;
102-
} else {
103-
continue;
104-
}
105-
}
106-
} else {
107-
//~ ERROR same body as `if` block
108-
for _ in &[42] {
109-
let foo: &Option<_> = &Some::<u8>(42);
110-
if true {
111-
break;
112-
} else {
113-
continue;
114-
}
115-
}
116-
}
117-
11894
if true {
11995
let bar = if true { 42 } else { 43 };
12096

@@ -149,113 +125,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
149125
_ => 4,
150126
};
151127
}
152-
153-
if true {
154-
if let Some(a) = Some(42) {}
155-
} else {
156-
//~ ERROR same body as `if` block
157-
if let Some(a) = Some(42) {}
158-
}
159-
160-
if true {
161-
if let (1, .., 3) = (1, 2, 3) {}
162-
} else {
163-
//~ ERROR same body as `if` block
164-
if let (1, .., 3) = (1, 2, 3) {}
165-
}
166-
167-
if true {
168-
if let (1, .., 3) = (1, 2, 3) {}
169-
} else {
170-
if let (.., 3) = (1, 2, 3) {}
171-
}
172-
173-
if true {
174-
if let (1, .., 3) = (1, 2, 3) {}
175-
} else {
176-
if let (.., 4) = (1, 2, 3) {}
177-
}
178-
179-
if true {
180-
if let (1, .., 3) = (1, 2, 3) {}
181-
} else {
182-
if let (.., 1, 3) = (1, 2, 3) {}
183-
}
184-
185-
if true {
186-
if let Some(42) = None {}
187-
} else {
188-
if let Option::Some(42) = None {}
189-
}
190-
191-
if true {
192-
if let Some(42) = None::<u8> {}
193-
} else {
194-
if let Some(42) = None {}
195-
}
196-
197-
if true {
198-
if let Some(42) = None::<u8> {}
199-
} else {
200-
if let Some(42) = None::<u32> {}
201-
}
202-
203-
if true {
204-
if let Some(a) = Some(42) {}
205-
} else {
206-
if let Some(a) = Some(43) {}
207-
}
208-
209-
// Same NaNs
210-
let _ = if true {
211-
std::f32::NAN
212-
} else {
213-
//~ ERROR same body as `if` block
214-
std::f32::NAN
215-
};
216-
217-
if true {
218-
Ok("foo")?;
219-
} else {
220-
//~ ERROR same body as `if` block
221-
Ok("foo")?;
222-
}
223-
224-
if true {
225-
let foo = "";
226-
return Ok(&foo[0..]);
227-
} else if false {
228-
let foo = "bar";
229-
return Ok(&foo[0..]);
230-
} else {
231-
let foo = "";
232-
return Ok(&foo[0..]);
233-
}
234-
235-
if true {
236-
let foo = "";
237-
return Ok(&foo[0..]);
238-
} else if false {
239-
let foo = "bar";
240-
return Ok(&foo[0..]);
241-
} else if true {
242-
let foo = "";
243-
return Ok(&foo[0..]);
244-
} else {
245-
let foo = "";
246-
return Ok(&foo[0..]);
247-
}
248-
249-
// False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559.
250-
if true {
251-
let foo = "";
252-
let (x, y) = (1, 2);
253-
return Ok(&foo[x..y]);
254-
} else {
255-
let foo = "";
256-
let (y, x) = (1, 2);
257-
return Ok(&foo[x..y]);
258-
}
259128
}
260129

261130
// Issue #2423. This was causing an ICE.

tests/ui/if_same_then_else.stderr

+11-146
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this `if` has identical blocks
2-
--> $DIR/if_same_then_else.rs:31:12
2+
--> $DIR/if_same_then_else.rs:28:12
33
|
44
LL | } else {
55
| ____________^
@@ -13,7 +13,7 @@ LL | | }
1313
|
1414
= note: `-D clippy::if-same-then-else` implied by `-D warnings`
1515
note: same as this
16-
--> $DIR/if_same_then_else.rs:23:13
16+
--> $DIR/if_same_then_else.rs:20:13
1717
|
1818
LL | if true {
1919
| _____________^
@@ -26,7 +26,7 @@ LL | | } else {
2626
| |_____^
2727

2828
error: this `if` has identical blocks
29-
--> $DIR/if_same_then_else.rs:69:12
29+
--> $DIR/if_same_then_else.rs:66:12
3030
|
3131
LL | } else {
3232
| ____________^
@@ -36,7 +36,7 @@ LL | | };
3636
| |_____^
3737
|
3838
note: same as this
39-
--> $DIR/if_same_then_else.rs:67:21
39+
--> $DIR/if_same_then_else.rs:64:21
4040
|
4141
LL | let _ = if true {
4242
| _____________________^
@@ -45,7 +45,7 @@ LL | | } else {
4545
| |_____^
4646

4747
error: this `if` has identical blocks
48-
--> $DIR/if_same_then_else.rs:76:12
48+
--> $DIR/if_same_then_else.rs:73:12
4949
|
5050
LL | } else {
5151
| ____________^
@@ -55,7 +55,7 @@ LL | | };
5555
| |_____^
5656
|
5757
note: same as this
58-
--> $DIR/if_same_then_else.rs:74:21
58+
--> $DIR/if_same_then_else.rs:71:21
5959
|
6060
LL | let _ = if true {
6161
| _____________________^
@@ -64,7 +64,7 @@ LL | | } else {
6464
| |_____^
6565

6666
error: this `if` has identical blocks
67-
--> $DIR/if_same_then_else.rs:92:12
67+
--> $DIR/if_same_then_else.rs:89:12
6868
|
6969
LL | } else {
7070
| ____________^
@@ -74,7 +74,7 @@ LL | | };
7474
| |_____^
7575
|
7676
note: same as this
77-
--> $DIR/if_same_then_else.rs:90:21
77+
--> $DIR/if_same_then_else.rs:87:21
7878
|
7979
LL | let _ = if true {
8080
| _____________________^
@@ -83,33 +83,7 @@ LL | | } else {
8383
| |_____^
8484

8585
error: this `if` has identical blocks
86-
--> $DIR/if_same_then_else.rs:106:12
87-
|
88-
LL | } else {
89-
| ____________^
90-
LL | | //~ ERROR same body as `if` block
91-
LL | | for _ in &[42] {
92-
LL | | let foo: &Option<_> = &Some::<u8>(42);
93-
... |
94-
LL | | }
95-
LL | | }
96-
| |_____^
97-
|
98-
note: same as this
99-
--> $DIR/if_same_then_else.rs:97:13
100-
|
101-
LL | if true {
102-
| _____________^
103-
LL | | for _ in &[42] {
104-
LL | | let foo: &Option<_> = &Some::<u8>(42);
105-
LL | | if true {
106-
... |
107-
LL | | }
108-
LL | | } else {
109-
| |_____^
110-
111-
error: this `if` has identical blocks
112-
--> $DIR/if_same_then_else.rs:125:12
86+
--> $DIR/if_same_then_else.rs:101:12
11387
|
11488
LL | } else {
11589
| ____________^
@@ -122,7 +96,7 @@ LL | | }
12296
| |_____^
12397
|
12498
note: same as this
125-
--> $DIR/if_same_then_else.rs:118:13
99+
--> $DIR/if_same_then_else.rs:94:13
126100
|
127101
LL | if true {
128102
| _____________^
@@ -134,114 +108,5 @@ LL | | bar + 1;
134108
LL | | } else {
135109
| |_____^
136110

137-
error: this `if` has identical blocks
138-
--> $DIR/if_same_then_else.rs:155:12
139-
|
140-
LL | } else {
141-
| ____________^
142-
LL | | //~ ERROR same body as `if` block
143-
LL | | if let Some(a) = Some(42) {}
144-
LL | | }
145-
| |_____^
146-
|
147-
note: same as this
148-
--> $DIR/if_same_then_else.rs:153:13
149-
|
150-
LL | if true {
151-
| _____________^
152-
LL | | if let Some(a) = Some(42) {}
153-
LL | | } else {
154-
| |_____^
155-
156-
error: this `if` has identical blocks
157-
--> $DIR/if_same_then_else.rs:162:12
158-
|
159-
LL | } else {
160-
| ____________^
161-
LL | | //~ ERROR same body as `if` block
162-
LL | | if let (1, .., 3) = (1, 2, 3) {}
163-
LL | | }
164-
| |_____^
165-
|
166-
note: same as this
167-
--> $DIR/if_same_then_else.rs:160:13
168-
|
169-
LL | if true {
170-
| _____________^
171-
LL | | if let (1, .., 3) = (1, 2, 3) {}
172-
LL | | } else {
173-
| |_____^
174-
175-
error: this `if` has identical blocks
176-
--> $DIR/if_same_then_else.rs:212:12
177-
|
178-
LL | } else {
179-
| ____________^
180-
LL | | //~ ERROR same body as `if` block
181-
LL | | std::f32::NAN
182-
LL | | };
183-
| |_____^
184-
|
185-
note: same as this
186-
--> $DIR/if_same_then_else.rs:210:21
187-
|
188-
LL | let _ = if true {
189-
| _____________________^
190-
LL | | std::f32::NAN
191-
LL | | } else {
192-
| |_____^
193-
194-
error: this `if` has identical blocks
195-
--> $DIR/if_same_then_else.rs:219:12
196-
|
197-
LL | } else {
198-
| ____________^
199-
LL | | //~ ERROR same body as `if` block
200-
LL | | Ok("foo")?;
201-
LL | | }
202-
| |_____^
203-
|
204-
note: same as this
205-
--> $DIR/if_same_then_else.rs:217:13
206-
|
207-
LL | if true {
208-
| _____________^
209-
LL | | Ok("foo")?;
210-
LL | | } else {
211-
| |_____^
212-
213-
error: this `if` has identical blocks
214-
--> $DIR/if_same_then_else.rs:244:12
215-
|
216-
LL | } else {
217-
| ____________^
218-
LL | | let foo = "";
219-
LL | | return Ok(&foo[0..]);
220-
LL | | }
221-
| |_____^
222-
|
223-
note: same as this
224-
--> $DIR/if_same_then_else.rs:241:20
225-
|
226-
LL | } else if true {
227-
| ____________________^
228-
LL | | let foo = "";
229-
LL | | return Ok(&foo[0..]);
230-
LL | | } else {
231-
| |_____^
232-
233-
error: this `if` has the same condition as a previous `if`
234-
--> $DIR/if_same_then_else.rs:241:15
235-
|
236-
LL | } else if true {
237-
| ^^^^
238-
|
239-
= note: `#[deny(clippy::ifs_same_cond)]` on by default
240-
note: same as this
241-
--> $DIR/if_same_then_else.rs:235:8
242-
|
243-
LL | if true {
244-
| ^^^^
245-
246-
error: aborting due to 12 previous errors
111+
error: aborting due to 5 previous errors
247112

0 commit comments

Comments
 (0)