Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split up match ui test #5108

Merged
merged 2 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new error count only adds up to 11, while the old one was 15. Did some errors get lost during the move?

Copy link
Member Author

@JohnTitor JohnTitor Jan 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some match_same_arms warnings are actually duplicated. For example, matches.rs:60 and matches.rs:68 are the same, later one is unnecessary. And I suppressed match_same_arms lint in match_wild_err_arm ui test since I feel they're already covered in match_same_arms ui tests.


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