Split tests

This commit is contained in:
Cameron Steffen 2020-11-29 18:21:21 -06:00
parent a5d6855333
commit 0e20788839
4 changed files with 115 additions and 98 deletions

View File

@ -95,45 +95,6 @@ fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>
},
None => return,
}
// if guards on outer match
{
match res_opt {
Ok(val) if make() => match val {
Some(n) => foo(n),
_ => return,
},
_ => return,
}
match res_opt {
Ok(val) => match val {
Some(n) => foo(n),
_ => return,
},
_ if make() => return,
_ => return,
}
}
// macro
{
macro_rules! mac {
($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => {
match $outer {
$pat => match $e {
$inner_pat => $then,
_ => return,
},
_ => return,
}
};
}
// Lint this since the patterns are not defined by the macro.
// Allows the lint to work on if_chain! for example.
// Fixing the lint requires knowledge of the specific macro, but we optimistically assume that
// there is still a better way to write this.
mac!(res_opt => Ok(val), val => Some(n), foo(n));
}
}
fn negative_cases(res_opt: Result<Option<u32>, String>, res_res: Result<Result<u32, String>, String>) {

View File

@ -175,63 +175,5 @@ LL | Some(val) => match val {
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: Unnecessary nested match
--> $DIR/collapsible_match.rs:102:34
|
LL | Ok(val) if make() => match val {
| __________________________________^
LL | | Some(n) => foo(n),
LL | | _ => return,
LL | | },
| |_____________^
|
help: The outer pattern can be modified to include the inner pattern.
--> $DIR/collapsible_match.rs:102:16
|
LL | Ok(val) if make() => match val {
| ^^^ Replace this binding
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: Unnecessary nested match
--> $DIR/collapsible_match.rs:109:24
|
LL | Ok(val) => match val {
| ________________________^
LL | | Some(n) => foo(n),
LL | | _ => return,
LL | | },
| |_____________^
|
help: The outer pattern can be modified to include the inner pattern.
--> $DIR/collapsible_match.rs:109:16
|
LL | Ok(val) => match val {
| ^^^ Replace this binding
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: Unnecessary nested match
--> $DIR/collapsible_match.rs:123:29
|
LL | $pat => match $e {
| _____________________________^
LL | | $inner_pat => $then,
LL | | _ => return,
LL | | },
| |_____________________^
...
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
| ------------------------------------------------- in this macro invocation
|
help: The outer pattern can be modified to include the inner pattern.
--> $DIR/collapsible_match.rs:135:28
|
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
| ^^^ ^^^^^^^ with this pattern
| |
| Replace this binding
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 13 previous errors
error: aborting due to 10 previous errors

View File

@ -0,0 +1,53 @@
#![warn(clippy::collapsible_match)]
#![allow(clippy::needless_return, clippy::no_effect, clippy::single_match)]
fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>) {
// if guards on outer match
{
match res_opt {
Ok(val) if make() => match val {
Some(n) => foo(n),
_ => return,
},
_ => return,
}
match res_opt {
Ok(val) => match val {
Some(n) => foo(n),
_ => return,
},
_ if make() => return,
_ => return,
}
}
// macro
{
macro_rules! mac {
($outer:expr => $pat:pat, $e:expr => $inner_pat:pat, $then:expr) => {
match $outer {
$pat => match $e {
$inner_pat => $then,
_ => return,
},
_ => return,
}
};
}
// Lint this since the patterns are not defined by the macro.
// Allows the lint to work on if_chain! for example.
// Fixing the lint requires knowledge of the specific macro, but we optimistically assume that
// there is still a better way to write this.
mac!(res_opt => Ok(val), val => Some(n), foo(n));
}
}
fn make<T>() -> T {
unimplemented!()
}
fn foo<T, U>(t: T) -> U {
unimplemented!()
}
fn main() {}

View File

@ -0,0 +1,61 @@
error: Unnecessary nested match
--> $DIR/collapsible_match2.rs:8:34
|
LL | Ok(val) if make() => match val {
| __________________________________^
LL | | Some(n) => foo(n),
LL | | _ => return,
LL | | },
| |_____________^
|
= note: `-D clippy::collapsible-match` implied by `-D warnings`
help: The outer pattern can be modified to include the inner pattern.
--> $DIR/collapsible_match2.rs:8:16
|
LL | Ok(val) if make() => match val {
| ^^^ Replace this binding
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: Unnecessary nested match
--> $DIR/collapsible_match2.rs:15:24
|
LL | Ok(val) => match val {
| ________________________^
LL | | Some(n) => foo(n),
LL | | _ => return,
LL | | },
| |_____________^
|
help: The outer pattern can be modified to include the inner pattern.
--> $DIR/collapsible_match2.rs:15:16
|
LL | Ok(val) => match val {
| ^^^ Replace this binding
LL | Some(n) => foo(n),
| ^^^^^^^ with this pattern
error: Unnecessary nested match
--> $DIR/collapsible_match2.rs:29:29
|
LL | $pat => match $e {
| _____________________________^
LL | | $inner_pat => $then,
LL | | _ => return,
LL | | },
| |_____________________^
...
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
| ------------------------------------------------- in this macro invocation
|
help: The outer pattern can be modified to include the inner pattern.
--> $DIR/collapsible_match2.rs:41:28
|
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
| ^^^ ^^^^^^^ with this pattern
| |
| Replace this binding
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors