-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new ui test for
match_option_and_default
- Loading branch information
1 parent
1abf441
commit fadb254
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|