Skip to content

Commit 83a87fb

Browse files
committed
UI test cleanup: Extract match_same_arms tests
1 parent 5725726 commit 83a87fb

File tree

4 files changed

+499
-479
lines changed

4 files changed

+499
-479
lines changed

tests/ui/copies.rs

Lines changed: 1 addition & 245 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
clippy::eq_op,
66
clippy::needless_continue,
77
clippy::needless_return,
8-
clippy::never_loop,
98
clippy::no_effect,
109
clippy::zero_divided_by_zero,
1110
clippy::unused_unit
@@ -16,64 +15,15 @@ fn foo() -> bool {
1615
unimplemented!()
1716
}
1817

19-
struct Foo {
20-
bar: u8,
21-
}
22-
2318
pub enum Abc {
2419
A,
2520
B,
2621
C,
2722
}
2823

29-
#[warn(clippy::if_same_then_else)]
3024
#[warn(clippy::match_same_arms)]
3125
#[allow(clippy::unused_unit)]
32-
fn if_same_then_else() -> Result<&'static str, ()> {
33-
if true {
34-
Foo { bar: 42 };
35-
0..10;
36-
..;
37-
0..;
38-
..10;
39-
0..=10;
40-
foo();
41-
} else {
42-
//~ ERROR same body as `if` block
43-
Foo { bar: 42 };
44-
0..10;
45-
..;
46-
0..;
47-
..10;
48-
0..=10;
49-
foo();
50-
}
51-
52-
if true {
53-
Foo { bar: 42 };
54-
} else {
55-
Foo { bar: 43 };
56-
}
57-
58-
if true {
59-
();
60-
} else {
61-
()
62-
}
63-
64-
if true {
65-
0..10;
66-
} else {
67-
0..=10;
68-
}
69-
70-
if true {
71-
foo();
72-
foo();
73-
} else {
74-
foo();
75-
}
76-
26+
fn match_same_arms() {
7727
let _ = match 42 {
7828
42 => {
7929
foo();
@@ -102,129 +52,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
10252
_ => 0, //~ ERROR match arms have same body
10353
};
10454

105-
if true {
106-
foo();
107-
}
108-
109-
let _ = if true {
110-
42
111-
} else {
112-
//~ ERROR same body as `if` block
113-
42
114-
};
115-
116-
if true {
117-
for _ in &[42] {
118-
let foo: &Option<_> = &Some::<u8>(42);
119-
if true {
120-
break;
121-
} else {
122-
continue;
123-
}
124-
}
125-
} else {
126-
//~ ERROR same body as `if` block
127-
for _ in &[42] {
128-
let foo: &Option<_> = &Some::<u8>(42);
129-
if true {
130-
break;
131-
} else {
132-
continue;
133-
}
134-
}
135-
}
136-
137-
if true {
138-
let bar = if true { 42 } else { 43 };
139-
140-
while foo() {
141-
break;
142-
}
143-
bar + 1;
144-
} else {
145-
//~ ERROR same body as `if` block
146-
let bar = if true { 42 } else { 43 };
147-
148-
while foo() {
149-
break;
150-
}
151-
bar + 1;
152-
}
153-
154-
if true {
155-
let _ = match 42 {
156-
42 => 1,
157-
a if a > 0 => 2,
158-
10..=15 => 3,
159-
_ => 4,
160-
};
161-
} else if false {
162-
foo();
163-
} else if foo() {
164-
let _ = match 42 {
165-
42 => 1,
166-
a if a > 0 => 2,
167-
10..=15 => 3,
168-
_ => 4,
169-
};
170-
}
171-
172-
if true {
173-
if let Some(a) = Some(42) {}
174-
} else {
175-
//~ ERROR same body as `if` block
176-
if let Some(a) = Some(42) {}
177-
}
178-
179-
if true {
180-
if let (1, .., 3) = (1, 2, 3) {}
181-
} else {
182-
//~ ERROR same body as `if` block
183-
if let (1, .., 3) = (1, 2, 3) {}
184-
}
185-
186-
if true {
187-
if let (1, .., 3) = (1, 2, 3) {}
188-
} else {
189-
if let (.., 3) = (1, 2, 3) {}
190-
}
191-
192-
if true {
193-
if let (1, .., 3) = (1, 2, 3) {}
194-
} else {
195-
if let (.., 4) = (1, 2, 3) {}
196-
}
197-
198-
if true {
199-
if let (1, .., 3) = (1, 2, 3) {}
200-
} else {
201-
if let (.., 1, 3) = (1, 2, 3) {}
202-
}
203-
204-
if true {
205-
if let Some(42) = None {}
206-
} else {
207-
if let Option::Some(42) = None {}
208-
}
209-
210-
if true {
211-
if let Some(42) = None::<u8> {}
212-
} else {
213-
if let Some(42) = None {}
214-
}
215-
216-
if true {
217-
if let Some(42) = None::<u8> {}
218-
} else {
219-
if let Some(42) = None::<u32> {}
220-
}
221-
222-
if true {
223-
if let Some(a) = Some(42) {}
224-
} else {
225-
if let Some(a) = Some(43) {}
226-
}
227-
22855
let _ = match 42 {
22956
42 => foo(),
23057
51 => foo(), //~ ERROR match arms have same body
@@ -271,33 +98,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
27198
_ => 0,
27299
};
273100

274-
let _ = if true {
275-
0.0
276-
} else {
277-
//~ ERROR same body as `if` block
278-
0.0
279-
};
280-
281-
let _ = if true {
282-
-0.0
283-
} else {
284-
//~ ERROR same body as `if` block
285-
-0.0
286-
};
287-
288-
let _ = if true { 0.0 } else { -0.0 };
289-
290-
// Different NaNs
291-
let _ = if true { 0.0 / 0.0 } else { std::f32::NAN };
292-
293-
// Same NaNs
294-
let _ = if true {
295-
std::f32::NAN
296-
} else {
297-
//~ ERROR same body as `if` block
298-
std::f32::NAN
299-
};
300-
301101
let _ = match Some(()) {
302102
Some(()) => 0.0,
303103
None => -0.0,
@@ -308,50 +108,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
308108
(None, Some(a)) => bar(a), // bindings have different types
309109
_ => (),
310110
}
311-
312-
if true {
313-
try!(Ok("foo"));
314-
} else {
315-
//~ ERROR same body as `if` block
316-
try!(Ok("foo"));
317-
}
318-
319-
if true {
320-
let foo = "";
321-
return Ok(&foo[0..]);
322-
} else if false {
323-
let foo = "bar";
324-
return Ok(&foo[0..]);
325-
} else {
326-
let foo = "";
327-
return Ok(&foo[0..]);
328-
}
329-
330-
// false positive if_same_then_else, let(x,y) vs let(y,x), see #3559
331-
if true {
332-
let foo = "";
333-
let (x, y) = (1, 2);
334-
return Ok(&foo[x..y]);
335-
} else {
336-
let foo = "";
337-
let (y, x) = (1, 2);
338-
return Ok(&foo[x..y]);
339-
}
340111
}
341112

342113
fn main() {}
343-
344-
// Issue #2423. This was causing an ICE
345-
fn func() {
346-
if true {
347-
f(&[0; 62]);
348-
f(&[0; 4]);
349-
f(&[0; 3]);
350-
} else {
351-
f(&[0; 62]);
352-
f(&[0; 6]);
353-
f(&[0; 6]);
354-
}
355-
}
356-
357-
fn f(val: &[u8]) {}

0 commit comments

Comments
 (0)