Skip to content

Commit ffd759d

Browse files
committed
Fix: Move tests into a new file. stderror was too long
1 parent eb6a20d commit ffd759d

12 files changed

+311
-300
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// run-rustfix
2+
3+
// Issue #5746
4+
#![warn(clippy::redundant_pattern_matching)]
5+
#![allow(clippy::if_same_then_else)]
6+
use std::task::Poll::{Pending, Ready};
7+
8+
fn main() {
9+
let m = std::sync::Mutex::new((0, 0));
10+
11+
// Result
12+
if m.lock().is_ok() {}
13+
if Err::<(), _>(m.lock().unwrap().0).is_err() {}
14+
15+
{
16+
if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {}
17+
}
18+
if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {
19+
} else {
20+
}
21+
if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok() {}
22+
if Err::<std::sync::MutexGuard<()>, _>(()).is_err() {}
23+
24+
if Ok::<_, ()>(String::new()).is_ok() {}
25+
if Err::<(), _>((String::new(), ())).is_err() {}
26+
27+
// Option
28+
if Some(m.lock()).is_some() {}
29+
if Some(m.lock().unwrap().0).is_some() {}
30+
31+
{
32+
if None::<std::sync::MutexGuard<()>>.is_none() {}
33+
}
34+
if None::<std::sync::MutexGuard<()>>.is_none() {
35+
} else {
36+
}
37+
38+
if None::<std::sync::MutexGuard<()>>.is_none() {}
39+
40+
if Some(String::new()).is_some() {}
41+
if Some((String::new(), ())).is_some() {}
42+
43+
// Poll
44+
if Ready(m.lock()).is_ready() {}
45+
if Ready(m.lock().unwrap().0).is_ready() {}
46+
47+
{
48+
if Pending::<std::sync::MutexGuard<()>>.is_pending() {}
49+
}
50+
if Pending::<std::sync::MutexGuard<()>>.is_pending() {
51+
} else {
52+
}
53+
54+
if Pending::<std::sync::MutexGuard<()>>.is_pending() {}
55+
56+
if Ready(String::new()).is_ready() {}
57+
if Ready((String::new(), ())).is_ready() {}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// run-rustfix
2+
3+
// Issue #5746
4+
#![warn(clippy::redundant_pattern_matching)]
5+
#![allow(clippy::if_same_then_else)]
6+
use std::task::Poll::{Pending, Ready};
7+
8+
fn main() {
9+
let m = std::sync::Mutex::new((0, 0));
10+
11+
// Result
12+
if let Ok(_) = m.lock() {}
13+
if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {}
14+
15+
{
16+
if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
17+
}
18+
if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {
19+
} else {
20+
}
21+
if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
22+
if let Err(_) = Err::<std::sync::MutexGuard<()>, _>(()) {}
23+
24+
if let Ok(_) = Ok::<_, ()>(String::new()) {}
25+
if let Err(_) = Err::<(), _>((String::new(), ())) {}
26+
27+
// Option
28+
if let Some(_) = Some(m.lock()) {}
29+
if let Some(_) = Some(m.lock().unwrap().0) {}
30+
31+
{
32+
if let None = None::<std::sync::MutexGuard<()>> {}
33+
}
34+
if let None = None::<std::sync::MutexGuard<()>> {
35+
} else {
36+
}
37+
38+
if let None = None::<std::sync::MutexGuard<()>> {}
39+
40+
if let Some(_) = Some(String::new()) {}
41+
if let Some(_) = Some((String::new(), ())) {}
42+
43+
// Poll
44+
if let Ready(_) = Ready(m.lock()) {}
45+
if let Ready(_) = Ready(m.lock().unwrap().0) {}
46+
47+
{
48+
if let Pending = Pending::<std::sync::MutexGuard<()>> {}
49+
}
50+
if let Pending = Pending::<std::sync::MutexGuard<()>> {
51+
} else {
52+
}
53+
54+
if let Pending = Pending::<std::sync::MutexGuard<()>> {}
55+
56+
if let Ready(_) = Ready(String::new()) {}
57+
if let Ready(_) = Ready((String::new(), ())) {}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
error: redundant pattern matching, consider using `is_ok()`
2+
--> $DIR/redundant_pattern_matching_drop_order.rs:12:12
3+
|
4+
LL | if let Ok(_) = m.lock() {}
5+
| -------^^^^^----------- help: try this: `if m.lock().is_ok()`
6+
|
7+
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
8+
= note: this will change drop order of the result, as well as all temporaries
9+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
10+
11+
error: redundant pattern matching, consider using `is_err()`
12+
--> $DIR/redundant_pattern_matching_drop_order.rs:13:12
13+
|
14+
LL | if let Err(_) = Err::<(), _>(m.lock().unwrap().0) {}
15+
| -------^^^^^^------------------------------------ help: try this: `if Err::<(), _>(m.lock().unwrap().0).is_err()`
16+
|
17+
= note: this will change drop order of the result, as well as all temporaries
18+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
19+
20+
error: redundant pattern matching, consider using `is_ok()`
21+
--> $DIR/redundant_pattern_matching_drop_order.rs:16:16
22+
|
23+
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
24+
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
25+
|
26+
= note: this will change drop order of the result, as well as all temporaries
27+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
28+
29+
error: redundant pattern matching, consider using `is_ok()`
30+
--> $DIR/redundant_pattern_matching_drop_order.rs:18:12
31+
|
32+
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {
33+
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
34+
|
35+
= note: this will change drop order of the result, as well as all temporaries
36+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
37+
38+
error: redundant pattern matching, consider using `is_ok()`
39+
--> $DIR/redundant_pattern_matching_drop_order.rs:21:12
40+
|
41+
LL | if let Ok(_) = Ok::<_, std::sync::MutexGuard<()>>(()) {}
42+
| -------^^^^^----------------------------------------- help: try this: `if Ok::<_, std::sync::MutexGuard<()>>(()).is_ok()`
43+
44+
error: redundant pattern matching, consider using `is_err()`
45+
--> $DIR/redundant_pattern_matching_drop_order.rs:22:12
46+
|
47+
LL | if let Err(_) = Err::<std::sync::MutexGuard<()>, _>(()) {}
48+
| -------^^^^^^------------------------------------------ help: try this: `if Err::<std::sync::MutexGuard<()>, _>(()).is_err()`
49+
50+
error: redundant pattern matching, consider using `is_ok()`
51+
--> $DIR/redundant_pattern_matching_drop_order.rs:24:12
52+
|
53+
LL | if let Ok(_) = Ok::<_, ()>(String::new()) {}
54+
| -------^^^^^----------------------------- help: try this: `if Ok::<_, ()>(String::new()).is_ok()`
55+
56+
error: redundant pattern matching, consider using `is_err()`
57+
--> $DIR/redundant_pattern_matching_drop_order.rs:25:12
58+
|
59+
LL | if let Err(_) = Err::<(), _>((String::new(), ())) {}
60+
| -------^^^^^^------------------------------------ help: try this: `if Err::<(), _>((String::new(), ())).is_err()`
61+
62+
error: redundant pattern matching, consider using `is_some()`
63+
--> $DIR/redundant_pattern_matching_drop_order.rs:28:12
64+
|
65+
LL | if let Some(_) = Some(m.lock()) {}
66+
| -------^^^^^^^----------------- help: try this: `if Some(m.lock()).is_some()`
67+
|
68+
= note: this will change drop order of the result, as well as all temporaries
69+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
70+
71+
error: redundant pattern matching, consider using `is_some()`
72+
--> $DIR/redundant_pattern_matching_drop_order.rs:29:12
73+
|
74+
LL | if let Some(_) = Some(m.lock().unwrap().0) {}
75+
| -------^^^^^^^---------------------------- help: try this: `if Some(m.lock().unwrap().0).is_some()`
76+
|
77+
= note: this will change drop order of the result, as well as all temporaries
78+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
79+
80+
error: redundant pattern matching, consider using `is_none()`
81+
--> $DIR/redundant_pattern_matching_drop_order.rs:32:16
82+
|
83+
LL | if let None = None::<std::sync::MutexGuard<()>> {}
84+
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
85+
|
86+
= note: this will change drop order of the result, as well as all temporaries
87+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
88+
89+
error: redundant pattern matching, consider using `is_none()`
90+
--> $DIR/redundant_pattern_matching_drop_order.rs:34:12
91+
|
92+
LL | if let None = None::<std::sync::MutexGuard<()>> {
93+
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
94+
|
95+
= note: this will change drop order of the result, as well as all temporaries
96+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
97+
98+
error: redundant pattern matching, consider using `is_none()`
99+
--> $DIR/redundant_pattern_matching_drop_order.rs:38:12
100+
|
101+
LL | if let None = None::<std::sync::MutexGuard<()>> {}
102+
| -------^^^^------------------------------------ help: try this: `if None::<std::sync::MutexGuard<()>>.is_none()`
103+
104+
error: redundant pattern matching, consider using `is_some()`
105+
--> $DIR/redundant_pattern_matching_drop_order.rs:40:12
106+
|
107+
LL | if let Some(_) = Some(String::new()) {}
108+
| -------^^^^^^^---------------------- help: try this: `if Some(String::new()).is_some()`
109+
110+
error: redundant pattern matching, consider using `is_some()`
111+
--> $DIR/redundant_pattern_matching_drop_order.rs:41:12
112+
|
113+
LL | if let Some(_) = Some((String::new(), ())) {}
114+
| -------^^^^^^^---------------------------- help: try this: `if Some((String::new(), ())).is_some()`
115+
116+
error: redundant pattern matching, consider using `is_ready()`
117+
--> $DIR/redundant_pattern_matching_drop_order.rs:44:12
118+
|
119+
LL | if let Ready(_) = Ready(m.lock()) {}
120+
| -------^^^^^^^^------------------ help: try this: `if Ready(m.lock()).is_ready()`
121+
|
122+
= note: this will change drop order of the result, as well as all temporaries
123+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
124+
125+
error: redundant pattern matching, consider using `is_ready()`
126+
--> $DIR/redundant_pattern_matching_drop_order.rs:45:12
127+
|
128+
LL | if let Ready(_) = Ready(m.lock().unwrap().0) {}
129+
| -------^^^^^^^^----------------------------- help: try this: `if Ready(m.lock().unwrap().0).is_ready()`
130+
|
131+
= note: this will change drop order of the result, as well as all temporaries
132+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
133+
134+
error: redundant pattern matching, consider using `is_pending()`
135+
--> $DIR/redundant_pattern_matching_drop_order.rs:48:16
136+
|
137+
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {}
138+
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
139+
|
140+
= note: this will change drop order of the result, as well as all temporaries
141+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
142+
143+
error: redundant pattern matching, consider using `is_pending()`
144+
--> $DIR/redundant_pattern_matching_drop_order.rs:50:12
145+
|
146+
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {
147+
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
148+
|
149+
= note: this will change drop order of the result, as well as all temporaries
150+
= note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important
151+
152+
error: redundant pattern matching, consider using `is_pending()`
153+
--> $DIR/redundant_pattern_matching_drop_order.rs:54:12
154+
|
155+
LL | if let Pending = Pending::<std::sync::MutexGuard<()>> {}
156+
| -------^^^^^^^--------------------------------------- help: try this: `if Pending::<std::sync::MutexGuard<()>>.is_pending()`
157+
158+
error: redundant pattern matching, consider using `is_ready()`
159+
--> $DIR/redundant_pattern_matching_drop_order.rs:56:12
160+
|
161+
LL | if let Ready(_) = Ready(String::new()) {}
162+
| -------^^^^^^^^----------------------- help: try this: `if Ready(String::new()).is_ready()`
163+
164+
error: redundant pattern matching, consider using `is_ready()`
165+
--> $DIR/redundant_pattern_matching_drop_order.rs:57:12
166+
|
167+
LL | if let Ready(_) = Ready((String::new(), ())) {}
168+
| -------^^^^^^^^----------------------------- help: try this: `if Ready((String::new(), ())).is_ready()`
169+
170+
error: aborting due to 22 previous errors
171+

tests/ui/redundant_pattern_matching_option.fixed

-18
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ fn main() {
5353
} else {
5454
3
5555
};
56-
57-
// Issue #5746
58-
let m = std::sync::Mutex::new((0, 0));
59-
60-
if Some(m.lock()).is_some() {}
61-
if Some(m.lock().unwrap().0).is_some() {}
62-
63-
{
64-
if None::<std::sync::MutexGuard<()>>.is_none() {}
65-
}
66-
if None::<std::sync::MutexGuard<()>>.is_none() {
67-
} else {
68-
}
69-
70-
if None::<std::sync::MutexGuard<()>>.is_none() {}
71-
72-
if Some(String::new()).is_some() {}
73-
if Some((String::new(), ())).is_some() {}
7456
}
7557

7658
fn gen_opt() -> Option<()> {

tests/ui/redundant_pattern_matching_option.rs

-18
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,6 @@ fn main() {
6262
} else {
6363
3
6464
};
65-
66-
// Issue #5746
67-
let m = std::sync::Mutex::new((0, 0));
68-
69-
if let Some(_) = Some(m.lock()) {}
70-
if let Some(_) = Some(m.lock().unwrap().0) {}
71-
72-
{
73-
if let None = None::<std::sync::MutexGuard<()>> {}
74-
}
75-
if let None = None::<std::sync::MutexGuard<()>> {
76-
} else {
77-
}
78-
79-
if let None = None::<std::sync::MutexGuard<()>> {}
80-
81-
if let Some(_) = Some(String::new()) {}
82-
if let Some(_) = Some((String::new(), ())) {}
8365
}
8466

8567
fn gen_opt() -> Option<()> {

0 commit comments

Comments
 (0)