Skip to content

Commit 6993a60

Browse files
committed
Simplify
1 parent 99f1e66 commit 6993a60

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

crates/hir/src/semantics.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,12 @@ impl<'db> SemanticsImpl<'db> {
465465
};
466466
let sa = self.analyze(&parent);
467467
let mut queue = vec![InFile::new(sa.file_id, token)];
468+
let mut cache = self.expansion_info_cache.borrow_mut();
468469
let mut res = smallvec![];
469470
while let Some(token) = queue.pop() {
470471
self.db.unwind_if_cancelled();
471472

472-
let mapped = (|| {
473+
let was_not_remapped = (|| {
473474
for node in token.value.ancestors() {
474475
match_ast! {
475476
match node {
@@ -487,7 +488,6 @@ impl<'db> SemanticsImpl<'db> {
487488
return None;
488489
}
489490
let file_id = sa.expand(self.db, token.with_value(&macro_call))?;
490-
let mut cache = self.expansion_info_cache.borrow_mut();
491491
let tokens = cache
492492
.entry(file_id)
493493
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
@@ -503,36 +503,31 @@ impl<'db> SemanticsImpl<'db> {
503503
return (queue.len() != len).then(|| ());
504504
},
505505
ast::Item(item) => {
506-
match self.with_ctx(|ctx| ctx.item_to_macro_call(token.with_value(item))) {
507-
Some(call_id) => {
508-
let file_id = call_id.as_file();
509-
let mut cache = self.expansion_info_cache.borrow_mut();
510-
let tokens = cache
511-
.entry(file_id)
512-
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
513-
.as_ref()?
514-
.map_token_down(self.db.upcast(), None, token.as_ref())?;
515-
516-
let len = queue.len();
517-
queue.extend(tokens.inspect(|token| {
518-
if let Some(parent) = token.value.parent() {
519-
self.cache(find_root(&parent), token.file_id);
520-
}
521-
}));
522-
return (queue.len() != len).then(|| ());
523-
}
524-
None => {}
506+
if let Some(call_id) = self.with_ctx(|ctx| ctx.item_to_macro_call(token.with_value(item.clone()))) {
507+
let file_id = call_id.as_file();
508+
let tokens = cache
509+
.entry(file_id)
510+
.or_insert_with(|| file_id.expansion_info(self.db.upcast()))
511+
.as_ref()?
512+
.map_token_down(self.db.upcast(), Some(item), token.as_ref())?;
513+
514+
let len = queue.len();
515+
queue.extend(tokens.inspect(|token| {
516+
if let Some(parent) = token.value.parent() {
517+
self.cache(find_root(&parent), token.file_id);
518+
}
519+
}));
520+
return (queue.len() != len).then(|| ());
525521
}
526522
},
527523
_ => {}
528524
}
529525
}
530526
}
531527
None
532-
})();
533-
match mapped {
534-
Some(()) => (),
535-
None => res.push(token.value),
528+
})().is_none();
529+
if was_not_remapped {
530+
res.push(token.value)
536531
}
537532
}
538533
res

0 commit comments

Comments
 (0)