mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Auto merge of #5108 - JohnTitor:split-up-0130, r=flip1995
Split up `match` ui test Part of #2038 Also, this decreases the line length limit to 220. changelog: none
This commit is contained in:
commit
bbef531518
7 changed files with 178 additions and 347 deletions
|
@ -7,7 +7,7 @@ use std::io::prelude::*;
|
|||
// The maximum length allowed for stderr files.
|
||||
//
|
||||
// We limit this because small files are easier to deal with than bigger files.
|
||||
const LIMIT: usize = 245;
|
||||
const LIMIT: usize = 220;
|
||||
|
||||
pub fn check() {
|
||||
let stderr_files = stderr_files();
|
||||
|
|
|
@ -79,6 +79,46 @@ fn match_same_arms() {
|
|||
(None, Some(a)) => bar(a), // bindings have different types
|
||||
_ => (),
|
||||
}
|
||||
|
||||
let x: Result<i32, &str> = Ok(3);
|
||||
|
||||
// No warning because of the guard.
|
||||
match x {
|
||||
Ok(x) if x * x == 64 => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => println!("err"),
|
||||
}
|
||||
|
||||
// This used to be a false positive; see issue #1996.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(x) if x * x == 64 => println!("ok 64"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => println!("err"),
|
||||
}
|
||||
|
||||
match (x, Some(1i32)) {
|
||||
(Ok(x), Some(_)) => println!("ok {}", x),
|
||||
(Ok(_), Some(x)) => println!("ok {}", x),
|
||||
_ => println!("err"),
|
||||
}
|
||||
|
||||
// No warning; different types for `x`.
|
||||
match (x, Some(1.0f64)) {
|
||||
(Ok(x), Some(_)) => println!("ok {}", x),
|
||||
(Ok(_), Some(x)) => println!("ok {}", x),
|
||||
_ => println!("err"),
|
||||
}
|
||||
|
||||
// False negative #2251.
|
||||
match x {
|
||||
Ok(_tmp) => println!("ok"),
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
unreachable!();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -105,5 +105,41 @@ help: consider refactoring into `(Some(a), ..) | (.., Some(a))`
|
|||
LL | (Some(a), ..) => bar(a),
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms2.rs:102:29
|
||||
|
|
||||
LL | (Ok(_), Some(x)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms2.rs:101:29
|
||||
|
|
||||
LL | (Ok(x), Some(_)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
|
||||
--> $DIR/match_same_arms2.rs:101:9
|
||||
|
|
||||
LL | (Ok(x), Some(_)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/match_same_arms2.rs:117:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/match_same_arms2.rs:116:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/match_same_arms2.rs:116:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
65
tests/ui/match_wild_err_arm.rs
Normal file
65
tests/ui/match_wild_err_arm.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
#![feature(exclusive_range_pattern)]
|
||||
#![allow(clippy::match_same_arms)]
|
||||
#![warn(clippy::match_wild_err_arm)]
|
||||
|
||||
fn match_wild_err_arm() {
|
||||
let x: Result<i32, &str> = Ok(3);
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => panic!("err"),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
panic!();
|
||||
},
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_e) => panic!(),
|
||||
}
|
||||
|
||||
// Allowed when used in `panic!`.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_e) => panic!("{}", _e),
|
||||
}
|
||||
|
||||
// Allowed when not with `panic!` block.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => println!("err"),
|
||||
}
|
||||
|
||||
// Allowed when used with `unreachable!`.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => unreachable!(),
|
||||
}
|
||||
|
||||
// Allowed when used with `unreachable!`.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
unreachable!();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
35
tests/ui/match_wild_err_arm.stderr
Normal file
35
tests/ui/match_wild_err_arm.stderr
Normal file
|
@ -0,0 +1,35 @@
|
|||
error: `Err(_)` matches all errors
|
||||
--> $DIR/match_wild_err_arm.rs:11:9
|
||||
|
|
||||
LL | Err(_) => panic!("err"),
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: `Err(_)` matches all errors
|
||||
--> $DIR/match_wild_err_arm.rs:17:9
|
||||
|
|
||||
LL | Err(_) => panic!(),
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: `Err(_)` matches all errors
|
||||
--> $DIR/match_wild_err_arm.rs:23:9
|
||||
|
|
||||
LL | Err(_) => {
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: `Err(_e)` matches all errors
|
||||
--> $DIR/match_wild_err_arm.rs:31:9
|
||||
|
|
||||
LL | Err(_e) => panic!(),
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
|
@ -1,111 +0,0 @@
|
|||
#![feature(exclusive_range_pattern)]
|
||||
#![warn(clippy::all)]
|
||||
#![allow(unused, clippy::redundant_pattern_matching, clippy::too_many_lines)]
|
||||
#![warn(clippy::match_same_arms)]
|
||||
|
||||
fn dummy() {}
|
||||
|
||||
fn match_wild_err_arm() {
|
||||
let x: Result<i32, &str> = Ok(3);
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => panic!("err"),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
panic!();
|
||||
},
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_e) => panic!(),
|
||||
}
|
||||
|
||||
// Allowed when used in `panic!`.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_e) => panic!("{}", _e),
|
||||
}
|
||||
|
||||
// Allowed when not with `panic!` block.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => println!("err"),
|
||||
}
|
||||
|
||||
// Allowed when used with `unreachable!`.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => unreachable!(),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => unreachable!(),
|
||||
}
|
||||
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
unreachable!();
|
||||
},
|
||||
}
|
||||
|
||||
// No warning because of the guard.
|
||||
match x {
|
||||
Ok(x) if x * x == 64 => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => println!("err"),
|
||||
}
|
||||
|
||||
// This used to be a false positive; see issue #1996.
|
||||
match x {
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(x) if x * x == 64 => println!("ok 64"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => println!("err"),
|
||||
}
|
||||
|
||||
match (x, Some(1i32)) {
|
||||
(Ok(x), Some(_)) => println!("ok {}", x),
|
||||
(Ok(_), Some(x)) => println!("ok {}", x),
|
||||
_ => println!("err"),
|
||||
}
|
||||
|
||||
// No warning; different types for `x`.
|
||||
match (x, Some(1.0f64)) {
|
||||
(Ok(x), Some(_)) => println!("ok {}", x),
|
||||
(Ok(_), Some(x)) => println!("ok {}", x),
|
||||
_ => println!("err"),
|
||||
}
|
||||
|
||||
// Because of a bug, no warning was generated for this case before #2251.
|
||||
match x {
|
||||
Ok(_tmp) => println!("ok"),
|
||||
Ok(3) => println!("ok"),
|
||||
Ok(_) => println!("ok"),
|
||||
Err(_) => {
|
||||
unreachable!();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,234 +0,0 @@
|
|||
error: `Err(_)` matches all errors
|
||||
--> $DIR/matches.rs:14:9
|
||||
|
|
||||
LL | Err(_) => panic!("err"),
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: `-D clippy::match-wild-err-arm` implied by `-D warnings`
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:13:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::match-same-arms` implied by `-D warnings`
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:12:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:12:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: `Err(_)` matches all errors
|
||||
--> $DIR/matches.rs:20:9
|
||||
|
|
||||
LL | Err(_) => panic!(),
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:19:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:18:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:18:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: `Err(_)` matches all errors
|
||||
--> $DIR/matches.rs:26:9
|
||||
|
|
||||
LL | Err(_) => {
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:25:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:24:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:24:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: `Err(_e)` matches all errors
|
||||
--> $DIR/matches.rs:34:9
|
||||
|
|
||||
LL | Err(_e) => panic!(),
|
||||
| ^^^^^^^
|
||||
|
|
||||
= note: match each error separately or use the error output
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:33:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:32:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:32:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:40:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:39:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:39:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:47:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:46:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:46:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:54:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:53:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:53:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:60:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:59:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:59:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:66:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:65:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:65:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:89:29
|
||||
|
|
||||
LL | (Ok(_), Some(x)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:88:29
|
||||
|
|
||||
LL | (Ok(x), Some(_)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
|
||||
--> $DIR/matches.rs:88:9
|
||||
|
|
||||
LL | (Ok(x), Some(_)) => println!("ok {}", x),
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: this `match` has identical arm bodies
|
||||
--> $DIR/matches.rs:104:18
|
||||
|
|
||||
LL | Ok(_) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/matches.rs:103:18
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: consider refactoring into `Ok(3) | Ok(_)`
|
||||
--> $DIR/matches.rs:103:9
|
||||
|
|
||||
LL | Ok(3) => println!("ok"),
|
||||
| ^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
|
Loading…
Reference in a new issue