diff options
| author | bitgaoshu <bitgaoshu@gmail.com> | 2022-04-24 20:51:48 +0800 |
|---|---|---|
| committer | 风维 <aaa@qqqq.com> | 2022-04-24 20:51:48 +0800 |
| commit | 5d1aff3357a4dd04794ddfb0e7cf386ef8a46c1c (patch) | |
| tree | 9d6b1cc8e8effa4be5197b45a53fd79df1b8192a | |
| parent | 1894473b1973b366ee8d0cfa2c2a4459b1709b9c (diff) | |
| download | rust-5d1aff3357a4dd04794ddfb0e7cf386ef8a46c1c.tar.gz rust-5d1aff3357a4dd04794ddfb0e7cf386ef8a46c1c.zip | |
#11973 associated type is unresolved
| -rw-r--r-- | crates/hir/src/source_analyzer.rs | 8 | ||||
| -rw-r--r-- | crates/ide/src/hover/tests.rs | 43 |
2 files changed, 50 insertions, 1 deletions
diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 35aef328245..7a65fd99cfa 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -652,7 +652,13 @@ fn resolve_hir_path_( let (ty, remaining) = resolver.resolve_path_in_type_ns(db.upcast(), path.mod_path())?; match remaining { - Some(remaining) if remaining > 1 => None, + Some(remaining) if remaining > 1 => { + if remaining + 1 == path.segments().len() { + Some((ty, path.segments().last())) + } else { + None + } + } _ => Some((ty, path.segments().get(1))), } } diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs index 57e049c10dd..baab746d743 100644 --- a/crates/ide/src/hover/tests.rs +++ b/crates/ide/src/hover/tests.rs @@ -3765,6 +3765,49 @@ pub fn gimme() -> theitem::TheItem { } #[test] +fn test_hover_trait_assoc_typealias() { + check( + r#" + fn main() {} + +trait T1 { + type Bar; + type Baz; +} + +struct Foo; + +mod t2 { + pub trait T2 { + type Bar; + } +} + +use t2::T2; + +impl T2 for Foo { + type Bar = String; +} + +impl T1 for Foo { + type Bar = <Foo as t2::T2>::Ba$0r; + // ^^^ unresolvedReference +} + "#, + expect![[r#" +*Bar* + +```rust +test::t2 +``` + +```rust +pub type Bar +``` +"#]], + ); +} +#[test] fn hover_generic_assoc() { check( r#" |
