Skip to content

Commit bbef531

Browse files
committed
Auto merge of rust-lang#5108 - JohnTitor:split-up-0130, r=flip1995
Split up `match` ui test Part of rust-lang#2038 Also, this decreases the line length limit to 220. changelog: none
2 parents 668bc48 + 411317b commit bbef531

7 files changed

+178
-347
lines changed

clippy_dev/src/stderr_length_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::prelude::*;
77
// The maximum length allowed for stderr files.
88
//
99
// We limit this because small files are easier to deal with than bigger files.
10-
const LIMIT: usize = 245;
10+
const LIMIT: usize = 220;
1111

1212
pub fn check() {
1313
let stderr_files = stderr_files();

tests/ui/match_same_arms2.rs

+40
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,46 @@ fn match_same_arms() {
7979
(None, Some(a)) => bar(a), // bindings have different types
8080
_ => (),
8181
}
82+
83+
let x: Result<i32, &str> = Ok(3);
84+
85+
// No warning because of the guard.
86+
match x {
87+
Ok(x) if x * x == 64 => println!("ok"),
88+
Ok(_) => println!("ok"),
89+
Err(_) => println!("err"),
90+
}
91+
92+
// This used to be a false positive; see issue #1996.
93+
match x {
94+
Ok(3) => println!("ok"),
95+
Ok(x) if x * x == 64 => println!("ok 64"),
96+
Ok(_) => println!("ok"),
97+
Err(_) => println!("err"),
98+
}
99+
100+
match (x, Some(1i32)) {
101+
(Ok(x), Some(_)) => println!("ok {}", x),
102+
(Ok(_), Some(x)) => println!("ok {}", x),
103+
_ => println!("err"),
104+
}
105+
106+
// No warning; different types for `x`.
107+
match (x, Some(1.0f64)) {
108+
(Ok(x), Some(_)) => println!("ok {}", x),
109+
(Ok(_), Some(x)) => println!("ok {}", x),
110+
_ => println!("err"),
111+
}
112+
113+
// False negative #2251.
114+
match x {
115+
Ok(_tmp) => println!("ok"),
116+
Ok(3) => println!("ok"),
117+
Ok(_) => println!("ok"),
118+
Err(_) => {
119+
unreachable!();
120+
},
121+
}
82122
}
83123

84124
fn main() {}

tests/ui/match_same_arms2.stderr

+37-1
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,41 @@ help: consider refactoring into `(Some(a), ..) | (.., Some(a))`
105105
LL | (Some(a), ..) => bar(a),
106106
| ^^^^^^^^^^^^^
107107

108-
error: aborting due to 5 previous errors
108+
error: this `match` has identical arm bodies
109+
--> $DIR/match_same_arms2.rs:102:29
110+
|
111+
LL | (Ok(_), Some(x)) => println!("ok {}", x),
112+
| ^^^^^^^^^^^^^^^^^^^^
113+
|
114+
note: same as this
115+
--> $DIR/match_same_arms2.rs:101:29
116+
|
117+
LL | (Ok(x), Some(_)) => println!("ok {}", x),
118+
| ^^^^^^^^^^^^^^^^^^^^
119+
help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
120+
--> $DIR/match_same_arms2.rs:101:9
121+
|
122+
LL | (Ok(x), Some(_)) => println!("ok {}", x),
123+
| ^^^^^^^^^^^^^^^^
124+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
125+
126+
error: this `match` has identical arm bodies
127+
--> $DIR/match_same_arms2.rs:117:18
128+
|
129+
LL | Ok(_) => println!("ok"),
130+
| ^^^^^^^^^^^^^^
131+
|
132+
note: same as this
133+
--> $DIR/match_same_arms2.rs:116:18
134+
|
135+
LL | Ok(3) => println!("ok"),
136+
| ^^^^^^^^^^^^^^
137+
help: consider refactoring into `Ok(3) | Ok(_)`
138+
--> $DIR/match_same_arms2.rs:116:9
139+
|
140+
LL | Ok(3) => println!("ok"),
141+
| ^^^^^
142+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
143+
144+
error: aborting due to 7 previous errors
109145

tests/ui/match_wild_err_arm.rs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#![feature(exclusive_range_pattern)]
2+
#![allow(clippy::match_same_arms)]
3+
#![warn(clippy::match_wild_err_arm)]
4+
5+
fn match_wild_err_arm() {
6+
let x: Result<i32, &str> = Ok(3);
7+
8+
match x {
9+
Ok(3) => println!("ok"),
10+
Ok(_) => println!("ok"),
11+
Err(_) => panic!("err"),
12+
}
13+
14+
match x {
15+
Ok(3) => println!("ok"),
16+
Ok(_) => println!("ok"),
17+
Err(_) => panic!(),
18+
}
19+
20+
match x {
21+
Ok(3) => println!("ok"),
22+
Ok(_) => println!("ok"),
23+
Err(_) => {
24+
panic!();
25+
},
26+
}
27+
28+
match x {
29+
Ok(3) => println!("ok"),
30+
Ok(_) => println!("ok"),
31+
Err(_e) => panic!(),
32+
}
33+
34+
// Allowed when used in `panic!`.
35+
match x {
36+
Ok(3) => println!("ok"),
37+
Ok(_) => println!("ok"),
38+
Err(_e) => panic!("{}", _e),
39+
}
40+
41+
// Allowed when not with `panic!` block.
42+
match x {
43+
Ok(3) => println!("ok"),
44+
Ok(_) => println!("ok"),
45+
Err(_) => println!("err"),
46+
}
47+
48+
// Allowed when used with `unreachable!`.
49+
match x {
50+
Ok(3) => println!("ok"),
51+
Ok(_) => println!("ok"),
52+
Err(_) => unreachable!(),
53+
}
54+
55+
// Allowed when used with `unreachable!`.
56+
match x {
57+
Ok(3) => println!("ok"),
58+
Ok(_) => println!("ok"),
59+
Err(_) => {
60+
unreachable!();
61+
},
62+
}
63+
}
64+
65+
fn main() {}

tests/ui/match_wild_err_arm.stderr

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error: `Err(_)` matches all errors
2+
--> $DIR/match_wild_err_arm.rs:11:9
3+
|
4+
LL | Err(_) => panic!("err"),
5+
| ^^^^^^
6+
|
7+
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
8+
= note: match each error separately or use the error output
9+
10+
error: `Err(_)` matches all errors
11+
--> $DIR/match_wild_err_arm.rs:17:9
12+
|
13+
LL | Err(_) => panic!(),
14+
| ^^^^^^
15+
|
16+
= note: match each error separately or use the error output
17+
18+
error: `Err(_)` matches all errors
19+
--> $DIR/match_wild_err_arm.rs:23:9
20+
|
21+
LL | Err(_) => {
22+
| ^^^^^^
23+
|
24+
= note: match each error separately or use the error output
25+
26+
error: `Err(_e)` matches all errors
27+
--> $DIR/match_wild_err_arm.rs:31:9
28+
|
29+
LL | Err(_e) => panic!(),
30+
| ^^^^^^^
31+
|
32+
= note: match each error separately or use the error output
33+
34+
error: aborting due to 4 previous errors
35+

tests/ui/matches.rs

-111
This file was deleted.

0 commit comments

Comments
 (0)