Skip to content

Commit c1de78f

Browse files
committed
Auto merge of rust-lang#12072 - bitgaoshu:master, r=jonas-schievink
fix rust-lang#11973 associated type is unresolved
2 parents b5d7a71 + 5d1aff3 commit c1de78f

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

crates/hir/src/source_analyzer.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,13 @@ fn resolve_hir_path_(
652652
let (ty, remaining) =
653653
resolver.resolve_path_in_type_ns(db.upcast(), path.mod_path())?;
654654
match remaining {
655-
Some(remaining) if remaining > 1 => None,
655+
Some(remaining) if remaining > 1 => {
656+
if remaining + 1 == path.segments().len() {
657+
Some((ty, path.segments().last()))
658+
} else {
659+
None
660+
}
661+
}
656662
_ => Some((ty, path.segments().get(1))),
657663
}
658664
}

crates/ide/src/hover/tests.rs

+43
Original file line numberDiff line numberDiff line change
@@ -3764,6 +3764,49 @@ pub fn gimme() -> theitem::TheItem {
37643764
);
37653765
}
37663766

3767+
#[test]
3768+
fn test_hover_trait_assoc_typealias() {
3769+
check(
3770+
r#"
3771+
fn main() {}
3772+
3773+
trait T1 {
3774+
type Bar;
3775+
type Baz;
3776+
}
3777+
3778+
struct Foo;
3779+
3780+
mod t2 {
3781+
pub trait T2 {
3782+
type Bar;
3783+
}
3784+
}
3785+
3786+
use t2::T2;
3787+
3788+
impl T2 for Foo {
3789+
type Bar = String;
3790+
}
3791+
3792+
impl T1 for Foo {
3793+
type Bar = <Foo as t2::T2>::Ba$0r;
3794+
// ^^^ unresolvedReference
3795+
}
3796+
"#,
3797+
expect![[r#"
3798+
*Bar*
3799+
3800+
```rust
3801+
test::t2
3802+
```
3803+
3804+
```rust
3805+
pub type Bar
3806+
```
3807+
"#]],
3808+
);
3809+
}
37673810
#[test]
37683811
fn hover_generic_assoc() {
37693812
check(

0 commit comments

Comments
 (0)