diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-03-01 14:03:12 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2024-03-01 14:03:12 +0100 |
| commit | aabaa47bfb6ccf775f4adaec61b3baea16dcb452 (patch) | |
| tree | 2d995523ce786dd465a82ff0ef136c5de8deecf5 | |
| parent | 9efa23c4dacee88b93540632eb3d88c5dfebfe17 (diff) | |
| download | rust-aabaa47bfb6ccf775f4adaec61b3baea16dcb452.tar.gz rust-aabaa47bfb6ccf775f4adaec61b3baea16dcb452.zip | |
fix: Don't highlight related assoc items of super traits
| -rw-r--r-- | crates/ide/src/highlight_related.rs | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index dd285e9b327..e20e0b67f4b 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -166,7 +166,7 @@ fn highlight_references( match parent { ast::UseTree(it) => it.syntax().ancestors().find(|it| { ast::SourceFile::can_cast(it.kind()) || ast::Module::can_cast(it.kind()) - }), + }).zip(Some(true)), ast::PathType(it) => it .syntax() .ancestors() @@ -178,14 +178,14 @@ fn highlight_references( .ancestors() .find(|it| { ast::Item::can_cast(it.kind()) - }), + }).zip(Some(false)), _ => None, } } })(); - if let Some(trait_item_use_scope) = trait_item_use_scope { + if let Some((trait_item_use_scope, use_tree)) = trait_item_use_scope { res.extend( - t.items_with_supertraits(sema.db) + if use_tree { t.items(sema.db) } else { t.items_with_supertraits(sema.db) } .into_iter() .filter_map(|item| { Definition::from(item) @@ -1598,7 +1598,10 @@ fn f() { fn test_trait_highlights_assoc_item_uses() { check( r#" -trait Foo { +trait Super { + type SuperT; +} +trait Foo: Super { //^^^ type T; const C: usize; @@ -1614,6 +1617,8 @@ impl Foo for i32 { } fn f<T: Foo$0>(t: T) { //^^^ + let _: T::SuperT; + //^^^^^^ let _: T::T; //^ t.m(); @@ -1636,6 +1641,49 @@ fn f2<T: Foo>(t: T) { } #[test] + fn test_trait_highlights_assoc_item_uses_use_tree() { + check( + r#" +use Foo$0; + // ^^^ import +trait Super { + type SuperT; +} +trait Foo: Super { + //^^^ + type T; + const C: usize; + fn f() {} + fn m(&self) {} +} +impl Foo for i32 { + //^^^ + type T = i32; + // ^ + const C: usize = 0; + // ^ + fn f() {} + // ^ + fn m(&self) {} + // ^ +} +fn f<T: Foo>(t: T) { + //^^^ + let _: T::SuperT; + let _: T::T; + //^ + t.m(); + //^ + T::C; + //^ + T::f(); + //^ +} +"#, + ); + } + + #[test] fn implicit_format_args() { check( r#" |
