Skip to content

Commit 4117ae1

Browse files
committed
Split redundant_pattern_matching tests
This is to avoid the 200 lines stderr file limit
1 parent 6e07247 commit 4117ae1

6 files changed

+351
-299
lines changed

tests/ui/redundant_pattern_matching.fixed

+5-66
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,14 @@ fn main() {
1818

1919
if Err::<i32, i32>(42).is_err() {}
2020

21-
if None::<()>.is_none() {}
22-
23-
if Some(42).is_some() {}
24-
25-
if Some(42).is_some() {
26-
foo();
27-
} else {
28-
bar();
29-
}
30-
31-
while Some(42).is_some() {}
32-
33-
while Some(42).is_none() {}
34-
35-
while None::<()>.is_none() {}
36-
3721
while Ok::<i32, i32>(10).is_ok() {}
3822

3923
while Ok::<i32, i32>(10).is_err() {}
4024

41-
let mut v = vec![1, 2, 3];
42-
while v.pop().is_some() {
43-
foo();
44-
}
45-
4625
if Ok::<i32, i32>(42).is_ok() {}
4726

4827
if Err::<i32, i32>(42).is_err() {}
4928

50-
if None::<i32>.is_none() {}
51-
52-
if Some(42).is_some() {}
53-
5429
if let Ok(x) = Ok::<i32, i32>(42) {
5530
println!("{}", x);
5631
}
@@ -63,48 +38,24 @@ fn main() {
6338

6439
Err::<i32, i32>(42).is_ok();
6540

66-
Some(42).is_some();
67-
68-
None::<()>.is_none();
69-
70-
let _ = None::<()>.is_none();
71-
7241
let _ = if Ok::<usize, ()>(4).is_ok() { true } else { false };
7342

74-
let opt = Some(false);
75-
let x = if opt.is_some() { true } else { false };
76-
takes_bool(x);
77-
7843
issue5504();
7944
issue6067();
8045

81-
let _ = if gen_opt().is_some() {
46+
let _ = if gen_res().is_ok() {
8247
1
83-
} else if gen_opt().is_none() {
84-
2
85-
} else if gen_res().is_ok() {
86-
3
8748
} else if gen_res().is_err() {
88-
4
49+
2
8950
} else {
90-
5
51+
3
9152
};
9253
}
9354

94-
fn gen_opt() -> Option<()> {
95-
None
96-
}
97-
9855
fn gen_res() -> Result<(), ()> {
9956
Ok(())
10057
}
10158

102-
fn takes_bool(_: bool) {}
103-
104-
fn foo() {}
105-
106-
fn bar() {}
107-
10859
macro_rules! m {
10960
() => {
11061
Some(42u32)
@@ -129,30 +80,18 @@ fn issue5504() {
12980
}
13081

13182
// Methods that are unstable const should not be suggested within a const context, see issue #5697.
132-
// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result`, and `is_some` and `is_none`
133-
// of `Option` were stabilized as const, so the following should be linted.
83+
// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const,
84+
// so the following should be linted.
13485
const fn issue6067() {
13586
if Ok::<i32, i32>(42).is_ok() {}
13687

13788
if Err::<i32, i32>(42).is_err() {}
13889

139-
if Some(42).is_some() {}
140-
141-
if None::<()>.is_none() {}
142-
14390
while Ok::<i32, i32>(10).is_ok() {}
14491

14592
while Ok::<i32, i32>(10).is_err() {}
14693

147-
while Some(42).is_some() {}
148-
149-
while None::<()>.is_none() {}
150-
15194
Ok::<i32, i32>(42).is_ok();
15295

15396
Err::<i32, i32>(42).is_err();
154-
155-
Some(42).is_some();
156-
157-
None::<()>.is_none();
15897
}

tests/ui/redundant_pattern_matching.rs

+5-81
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,14 @@ fn main() {
1818

1919
if let Err(_) = Err::<i32, i32>(42) {}
2020

21-
if let None = None::<()> {}
22-
23-
if let Some(_) = Some(42) {}
24-
25-
if let Some(_) = Some(42) {
26-
foo();
27-
} else {
28-
bar();
29-
}
30-
31-
while let Some(_) = Some(42) {}
32-
33-
while let None = Some(42) {}
34-
35-
while let None = None::<()> {}
36-
3721
while let Ok(_) = Ok::<i32, i32>(10) {}
3822

3923
while let Err(_) = Ok::<i32, i32>(10) {}
4024

41-
let mut v = vec![1, 2, 3];
42-
while let Some(_) = v.pop() {
43-
foo();
44-
}
45-
4625
if Ok::<i32, i32>(42).is_ok() {}
4726

4827
if Err::<i32, i32>(42).is_err() {}
4928

50-
if None::<i32>.is_none() {}
51-
52-
if Some(42).is_some() {}
53-
5429
if let Ok(x) = Ok::<i32, i32>(42) {
5530
println!("{}", x);
5631
}
@@ -75,57 +50,24 @@ fn main() {
7550
Err(_) => false,
7651
};
7752

78-
match Some(42) {
79-
Some(_) => true,
80-
None => false,
81-
};
82-
83-
match None::<()> {
84-
Some(_) => false,
85-
None => true,
86-
};
87-
88-
let _ = match None::<()> {
89-
Some(_) => false,
90-
None => true,
91-
};
92-
9353
let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
9454

95-
let opt = Some(false);
96-
let x = if let Some(_) = opt { true } else { false };
97-
takes_bool(x);
98-
9955
issue5504();
10056
issue6067();
10157

102-
let _ = if let Some(_) = gen_opt() {
58+
let _ = if let Ok(_) = gen_res() {
10359
1
104-
} else if let None = gen_opt() {
105-
2
106-
} else if let Ok(_) = gen_res() {
107-
3
10860
} else if let Err(_) = gen_res() {
109-
4
61+
2
11062
} else {
111-
5
63+
3
11264
};
11365
}
11466

115-
fn gen_opt() -> Option<()> {
116-
None
117-
}
118-
11967
fn gen_res() -> Result<(), ()> {
12068
Ok(())
12169
}
12270

123-
fn takes_bool(_: bool) {}
124-
125-
fn foo() {}
126-
127-
fn bar() {}
128-
12971
macro_rules! m {
13072
() => {
13173
Some(42u32)
@@ -150,25 +92,17 @@ fn issue5504() {
15092
}
15193

15294
// Methods that are unstable const should not be suggested within a const context, see issue #5697.
153-
// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result`, and `is_some` and `is_none`
154-
// of `Option` were stabilized as const, so the following should be linted.
95+
// However, in Rust 1.48.0 the methods `is_ok` and `is_err` of `Result` were stabilized as const,
96+
// so the following should be linted.
15597
const fn issue6067() {
15698
if let Ok(_) = Ok::<i32, i32>(42) {}
15799

158100
if let Err(_) = Err::<i32, i32>(42) {}
159101

160-
if let Some(_) = Some(42) {}
161-
162-
if let None = None::<()> {}
163-
164102
while let Ok(_) = Ok::<i32, i32>(10) {}
165103

166104
while let Err(_) = Ok::<i32, i32>(10) {}
167105

168-
while let Some(_) = Some(42) {}
169-
170-
while let None = None::<()> {}
171-
172106
match Ok::<i32, i32>(42) {
173107
Ok(_) => true,
174108
Err(_) => false,
@@ -178,14 +112,4 @@ const fn issue6067() {
178112
Ok(_) => false,
179113
Err(_) => true,
180114
};
181-
182-
match Some(42) {
183-
Some(_) => true,
184-
None => false,
185-
};
186-
187-
match None::<()> {
188-
Some(_) => false,
189-
None => true,
190-
};
191115
}

0 commit comments

Comments
 (0)