Add test for manual_unwrap_or in issue 13018
This commit is contained in:
parent
0c9016aa1e
commit
e864519fbc
@ -234,4 +234,13 @@ fn implicit_deref_ref() {
|
||||
};
|
||||
}
|
||||
|
||||
mod issue_13018 {
|
||||
use std::collections::HashMap;
|
||||
|
||||
type RefName = i32;
|
||||
pub fn get(index: &HashMap<usize, Vec<RefName>>, id: usize) -> &[RefName] {
|
||||
index.get(&id).unwrap_or(&[])
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -284,4 +284,17 @@ fn implicit_deref_ref() {
|
||||
};
|
||||
}
|
||||
|
||||
mod issue_13018 {
|
||||
use std::collections::HashMap;
|
||||
|
||||
type RefName = i32;
|
||||
pub fn get(index: &HashMap<usize, Vec<RefName>>, id: usize) -> &[RefName] {
|
||||
if let Some(names) = index.get(&id) {
|
||||
names
|
||||
} else {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -172,5 +172,15 @@ LL | | None => 0,
|
||||
LL | | };
|
||||
| |_________^ help: replace with: `some_macro!().unwrap_or(0)`
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
error: this pattern reimplements `Option::unwrap_or`
|
||||
--> tests/ui/manual_unwrap_or.rs:292:9
|
||||
|
|
||||
LL | / if let Some(names) = index.get(&id) {
|
||||
LL | | names
|
||||
LL | | } else {
|
||||
LL | | &[]
|
||||
LL | | }
|
||||
| |_________^ help: replace with: `index.get(&id).unwrap_or(&[])`
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user