Skip to content

Commit 1ceea5b

Browse files
committed
Early exit in search properly
1 parent a12c80d commit 1ceea5b

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/tools/rust-analyzer/crates/hir/src/semantics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ impl<'db> SemanticsImpl<'db> {
17561756
let file_id = self.lookup(&root_node).unwrap_or_else(|| {
17571757
panic!(
17581758
"\n\nFailed to lookup {:?} in this Semantics.\n\
1759-
Make sure to use only query nodes, derived from this instance of Semantics.\n\
1759+
Make sure to only query nodes derived from this instance of Semantics.\n\
17601760
root node: {:?}\n\
17611761
known nodes: {}\n\n",
17621762
node,

src/tools/rust-analyzer/crates/ide-db/src/search.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,14 +953,19 @@ impl<'a> FindUsages<'a> {
953953

954954
// Search for occurrences of the items name
955955
for offset in Self::match_indices(&text, finder, search_range) {
956-
tree.token_at_offset(offset).for_each(|token| {
957-
let Some(str_token) = ast::String::cast(token.clone()) else { return };
956+
let ret = tree.token_at_offset(offset).any(|token| {
957+
let Some(str_token) = ast::String::cast(token.clone()) else { return false };
958958
if let Some((range, Some(nameres))) =
959959
sema.check_for_format_args_template(token, offset)
960960
{
961-
if self.found_format_args_ref(file_id, range, str_token, nameres, sink) {}
961+
return self
962+
.found_format_args_ref(file_id, range, str_token, nameres, sink);
962963
}
964+
false
963965
});
966+
if ret {
967+
return;
968+
}
964969

965970
for name in
966971
Self::find_nodes(sema, name, &tree, offset).filter_map(ast::NameLike::cast)

0 commit comments

Comments
 (0)