Skip to content

Commit 111d079

Browse files
bors[bot]Veykril
andauthored
Merge #9597
9597: Use Type::walk for goto_type_definition r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents 9bd6836 + 12fe48c commit 111d079

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

crates/ide/src/goto_type_definition.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use ide_db::{base_db::Upcast, helpers::pick_best_token, RootDatabase};
2-
use rustc_hash::FxHashSet;
32
use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, T};
43

54
use crate::{display::TryToNav, FilePosition, NavigationTarget, RangeInfo};
@@ -55,19 +54,29 @@ pub(crate) fn goto_type_definition(
5554
Some((ty, node))
5655
})?;
5756

58-
let mut res = FxHashSet::default();
59-
let mut workload = vec![ty.strip_references()];
60-
while let Some(ty) = workload.pop() {
61-
if let Some(adt) = ty.as_adt() {
62-
res.insert(adt);
57+
let mut res = Vec::new();
58+
let mut push = |def: hir::ModuleDef| {
59+
if let Some(nav) = def.try_to_nav(db) {
60+
if !res.contains(&nav) {
61+
res.push(nav);
62+
}
6363
}
64-
workload.extend(ty.strip_references().type_arguments());
65-
}
64+
};
65+
66+
let ty = ty.strip_references();
67+
ty.walk(db, |t| {
68+
if let Some(adt) = t.as_adt() {
69+
push(adt.into());
70+
} else if let Some(trait_) = t.as_dyn_trait() {
71+
push(trait_.into());
72+
} else if let Some(traits) = t.as_impl_traits(db) {
73+
traits.into_iter().for_each(|it| push(it.into()));
74+
} else if let Some(trait_) = t.as_associated_type_parent_trait(db) {
75+
push(trait_.into());
76+
}
77+
});
6678

67-
Some(RangeInfo::new(
68-
node.text_range(),
69-
res.into_iter().flat_map(|adt| adt.try_to_nav(db)).collect(),
70-
))
79+
Some(RangeInfo::new(node.text_range(), res))
7180
}
7281

7382
#[cfg(test)]

0 commit comments

Comments
 (0)