Skip to content

Commit e864519

Browse files
committed
Add test for manual_unwrap_or in issue 13018
1 parent 0c9016a commit e864519

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

tests/ui/manual_unwrap_or.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,13 @@ fn implicit_deref_ref() {
234234
};
235235
}
236236

237+
mod issue_13018 {
238+
use std::collections::HashMap;
239+
240+
type RefName = i32;
241+
pub fn get(index: &HashMap<usize, Vec<RefName>>, id: usize) -> &[RefName] {
242+
index.get(&id).unwrap_or(&[])
243+
}
244+
}
245+
237246
fn main() {}

tests/ui/manual_unwrap_or.rs

+13
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,17 @@ fn implicit_deref_ref() {
284284
};
285285
}
286286

287+
mod issue_13018 {
288+
use std::collections::HashMap;
289+
290+
type RefName = i32;
291+
pub fn get(index: &HashMap<usize, Vec<RefName>>, id: usize) -> &[RefName] {
292+
if let Some(names) = index.get(&id) {
293+
names
294+
} else {
295+
&[]
296+
}
297+
}
298+
}
299+
287300
fn main() {}

tests/ui/manual_unwrap_or.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,15 @@ LL | | None => 0,
172172
LL | | };
173173
| |_________^ help: replace with: `some_macro!().unwrap_or(0)`
174174

175-
error: aborting due to 16 previous errors
175+
error: this pattern reimplements `Option::unwrap_or`
176+
--> tests/ui/manual_unwrap_or.rs:292:9
177+
|
178+
LL | / if let Some(names) = index.get(&id) {
179+
LL | | names
180+
LL | | } else {
181+
LL | | &[]
182+
LL | | }
183+
| |_________^ help: replace with: `index.get(&id).unwrap_or(&[])`
184+
185+
error: aborting due to 17 previous errors
176186

0 commit comments

Comments
 (0)