diff options
| author | Lzu Tao <taolzu@gmail.com> | 2024-07-07 08:11:32 +0700 |
|---|---|---|
| committer | Lzu Tao <taolzu@gmail.com> | 2024-07-07 03:34:38 +0000 |
| commit | e864519fbcaef5141e8fda7fdfac1a2c8d363cd2 (patch) | |
| tree | 3bc76524daf1e1a3f5fefb43c5a673ece4639bd3 | |
| parent | 0c9016aa1e6bd631aff4c03b86ccb17844ce71a1 (diff) | |
| download | rust-e864519fbcaef5141e8fda7fdfac1a2c8d363cd2.tar.gz rust-e864519fbcaef5141e8fda7fdfac1a2c8d363cd2.zip | |
Add test for manual_unwrap_or in issue 13018
| -rw-r--r-- | tests/ui/manual_unwrap_or.fixed | 9 | ||||
| -rw-r--r-- | tests/ui/manual_unwrap_or.rs | 13 | ||||
| -rw-r--r-- | tests/ui/manual_unwrap_or.stderr | 12 |
3 files changed, 33 insertions, 1 deletions
diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed index 74afa00e12f..2899c3518de 100644 --- a/tests/ui/manual_unwrap_or.fixed +++ b/tests/ui/manual_unwrap_or.fixed @@ -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() {} diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs index 2d01b8ceaaa..e2c04b01ed9 100644 --- a/tests/ui/manual_unwrap_or.rs +++ b/tests/ui/manual_unwrap_or.rs @@ -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() {} diff --git a/tests/ui/manual_unwrap_or.stderr b/tests/ui/manual_unwrap_or.stderr index c93a8952a08..28b59df161d 100644 --- a/tests/ui/manual_unwrap_or.stderr +++ b/tests/ui/manual_unwrap_or.stderr @@ -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 |
