From bdbcfaa28b6ad75cbb8cf30d8068e4611f4a499a Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 20 Nov 2025 08:32:36 +0200 Subject: [PATCH] macros: Eliminate unwrap() in match_ignore_ascci_case() --- macros/src/ext/match_ignore_ascii_case.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/macros/src/ext/match_ignore_ascii_case.rs b/macros/src/ext/match_ignore_ascii_case.rs index ab06482e7..c8234b181 100644 --- a/macros/src/ext/match_ignore_ascii_case.rs +++ b/macros/src/ext/match_ignore_ascii_case.rs @@ -86,19 +86,12 @@ pub fn match_ignore_ascci_case(input: TokenStream) -> TokenStream { let mut current = &mut paths; for b in keyword_b { - match current.sub_entries.get(&b) { - Some(_) => { - current = current.sub_entries.get_mut(&b).unwrap(); - } - None => { - let new_entry = Box::new(PathEntry { - result: None, - sub_entries: HashMap::new(), - }); - current.sub_entries.insert(b, new_entry); - current = current.sub_entries.get_mut(&b).unwrap(); - } - } + current = current.sub_entries.entry(b).or_insert_with(|| { + Box::new(PathEntry { + result: None, + sub_entries: HashMap::new(), + }) + }); } assert!(current.result.is_none());