Skip to content

Commit

Permalink
Auto merge of #5108 - JohnTitor:split-up-0130, r=flip1995
Browse files Browse the repository at this point in the history
Split up `match` ui test

Part of #2038

Also, this decreases the line length limit to 220.

changelog: none
  • Loading branch information
bors committed Jan 30, 2020
2 parents 668bc48 + 411317b commit bbef531
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 347 deletions.
2 changes: 1 addition & 1 deletion clippy_dev/src/stderr_length_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
40 changes: 40 additions & 0 deletions tests/ui/match_same_arms2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
38 changes: 37 additions & 1 deletion tests/ui/match_same_arms2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 65 additions & 0 deletions tests/ui/match_wild_err_arm.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 35 additions & 0 deletions tests/ui/match_wild_err_arm.stderr
Original file line number Diff line number Diff line change
@@ -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

111 changes: 0 additions & 111 deletions tests/ui/matches.rs

This file was deleted.

Loading

0 comments on commit bbef531

Please sign in to comment.