Add new ui test for match_option_and_default
This commit is contained in:
parent
1abf4418f8
commit
fadb254073
19
tests/ui/match_option_and_default.fixed
Normal file
19
tests/ui/match_option_and_default.fixed
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#![warn(clippy::match_option_and_default)]
|
||||||
|
#![allow(clippy::unnecessary_literal_unwrap)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
x.unwrap_or_default();
|
||||||
|
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
x.unwrap_or_default();
|
||||||
|
|
||||||
|
let x: Option<String> = None;
|
||||||
|
x.unwrap_or_default();
|
||||||
|
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
x.unwrap_or_default();
|
||||||
|
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
x.unwrap_or_default();
|
||||||
|
}
|
40
tests/ui/match_option_and_default.rs
Normal file
40
tests/ui/match_option_and_default.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#![warn(clippy::match_option_and_default)]
|
||||||
|
#![allow(clippy::unnecessary_literal_unwrap)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
match x {
|
||||||
|
//~^ ERROR: match can be simplified with `.unwrap_or_default()`
|
||||||
|
Some(v) => v,
|
||||||
|
None => Vec::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
match x {
|
||||||
|
//~^ ERROR: match can be simplified with `.unwrap_or_default()`
|
||||||
|
Some(v) => v,
|
||||||
|
_ => Vec::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let x: Option<String> = None;
|
||||||
|
match x {
|
||||||
|
//~^ ERROR: match can be simplified with `.unwrap_or_default()`
|
||||||
|
Some(v) => v,
|
||||||
|
None => String::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
match x {
|
||||||
|
//~^ ERROR: match can be simplified with `.unwrap_or_default()`
|
||||||
|
None => Vec::default(),
|
||||||
|
Some(v) => v,
|
||||||
|
};
|
||||||
|
|
||||||
|
let x: Option<Vec<String>> = None;
|
||||||
|
if let Some(v) = x {
|
||||||
|
//~^ ERROR: if let can be simplified with `.unwrap_or_default()`
|
||||||
|
v
|
||||||
|
} else {
|
||||||
|
Vec::default()
|
||||||
|
};
|
||||||
|
}
|
56
tests/ui/match_option_and_default.stderr
Normal file
56
tests/ui/match_option_and_default.stderr
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
error: match can be simplified with `.unwrap_or_default()`
|
||||||
|
--> tests/ui/match_option_and_default.rs:6:5
|
||||||
|
|
|
||||||
|
LL | / match x {
|
||||||
|
LL | |
|
||||||
|
LL | | Some(v) => v,
|
||||||
|
LL | | None => Vec::default(),
|
||||||
|
LL | | };
|
||||||
|
| |_____^ help: replace it with: `x.unwrap_or_default()`
|
||||||
|
|
|
||||||
|
= note: `-D clippy::match-option-and-default` implied by `-D warnings`
|
||||||
|
= help: to override `-D warnings` add `#[allow(clippy::match_option_and_default)]`
|
||||||
|
|
||||||
|
error: match can be simplified with `.unwrap_or_default()`
|
||||||
|
--> tests/ui/match_option_and_default.rs:13:5
|
||||||
|
|
|
||||||
|
LL | / match x {
|
||||||
|
LL | |
|
||||||
|
LL | | Some(v) => v,
|
||||||
|
LL | | _ => Vec::default(),
|
||||||
|
LL | | };
|
||||||
|
| |_____^ help: replace it with: `x.unwrap_or_default()`
|
||||||
|
|
||||||
|
error: match can be simplified with `.unwrap_or_default()`
|
||||||
|
--> tests/ui/match_option_and_default.rs:20:5
|
||||||
|
|
|
||||||
|
LL | / match x {
|
||||||
|
LL | |
|
||||||
|
LL | | Some(v) => v,
|
||||||
|
LL | | None => String::new(),
|
||||||
|
LL | | };
|
||||||
|
| |_____^ help: replace it with: `x.unwrap_or_default()`
|
||||||
|
|
||||||
|
error: match can be simplified with `.unwrap_or_default()`
|
||||||
|
--> tests/ui/match_option_and_default.rs:27:5
|
||||||
|
|
|
||||||
|
LL | / match x {
|
||||||
|
LL | |
|
||||||
|
LL | | None => Vec::default(),
|
||||||
|
LL | | Some(v) => v,
|
||||||
|
LL | | };
|
||||||
|
| |_____^ help: replace it with: `x.unwrap_or_default()`
|
||||||
|
|
||||||
|
error: if let can be simplified with `.unwrap_or_default()`
|
||||||
|
--> tests/ui/match_option_and_default.rs:34:5
|
||||||
|
|
|
||||||
|
LL | / if let Some(v) = x {
|
||||||
|
LL | |
|
||||||
|
LL | | v
|
||||||
|
LL | | } else {
|
||||||
|
LL | | Vec::default()
|
||||||
|
LL | | };
|
||||||
|
| |_____^ help: replace it with: `x.unwrap_or_default()`
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user