mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Add test for manual_unwrap_or in issue 13018
This commit is contained in:
parent
0c9016aa1e
commit
e864519fbc
3 changed files with 33 additions and 1 deletions
|
@ -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() {}
|
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() {}
|
fn main() {}
|
||||||
|
|
|
@ -172,5 +172,15 @@ LL | | None => 0,
|
||||||
LL | | };
|
LL | | };
|
||||||
| |_________^ help: replace with: `some_macro!().unwrap_or(0)`
|
| |_________^ 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…
Reference in a new issue