Skip to content

Commit f4e4a3a

Browse files
bors[bot]Veykril
andauthored
Merge #11914
11914: fix: Fix path qualifiers not resolving generic type params when shadowed by trait r=Veykril a=Veykril Fixes #10707 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents a852758 + 7959c24 commit f4e4a3a

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

crates/hir/src/source_analyzer.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -749,22 +749,23 @@ fn resolve_hir_path_qualifier(
749749
resolver: &Resolver,
750750
path: &Path,
751751
) -> Option<PathResolution> {
752-
let items = resolver
753-
.resolve_module_path_in_items(db.upcast(), path.mod_path())
754-
.take_types()
755-
.map(|it| PathResolution::Def(it.into()));
756-
757-
if items.is_some() {
758-
return items;
759-
}
760-
761-
resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty {
762-
TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
763-
TypeNs::GenericParam(id) => PathResolution::TypeParam(id.into()),
764-
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()),
765-
TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
766-
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
767-
TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
768-
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
769-
})
752+
resolver
753+
.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path())
754+
.map(|ty| match ty {
755+
TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
756+
TypeNs::GenericParam(id) => PathResolution::TypeParam(id.into()),
757+
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => {
758+
PathResolution::Def(Adt::from(it).into())
759+
}
760+
TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
761+
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
762+
TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()),
763+
TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()),
764+
})
765+
.or_else(|| {
766+
resolver
767+
.resolve_module_path_in_items(db.upcast(), path.mod_path())
768+
.take_types()
769+
.map(|it| PathResolution::Def(it.into()))
770+
})
770771
}

crates/ide/src/syntax_highlighting/test_data/highlight_general.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,8 @@
225225
<span class="type_param">T</span><span class="colon">:</span> <span class="trait">Baz</span><span class="comma">,</span>
226226
<span class="angle">&lt;</span><span class="type_param">T</span> <span class="keyword">as</span> <span class="trait">Baz</span><span class="angle">&gt;</span><span class="operator">::</span><span class="type_alias associated trait">Qux</span><span class="colon">:</span> <span class="trait">Bar</span> <span class="brace">{</span><span class="brace">}</span>
227227

228+
<span class="keyword">fn</span> <span class="function declaration">gp_shadows_trait</span><span class="angle">&lt;</span><span class="type_param declaration">Baz</span><span class="colon">:</span> <span class="trait">Bar</span><span class="angle">&gt;</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span>
229+
<span class="type_param">Baz</span><span class="operator">::</span><span class="function associated reference trait">bar</span><span class="semicolon">;</span>
230+
<span class="brace">}</span>
231+
228232
</code></pre>

crates/ide/src/syntax_highlighting/tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct Foo;
3131
false,
3232
);
3333
}
34+
3435
#[test]
3536
fn macros() {
3637
check_highlighting(
@@ -278,6 +279,10 @@ where
278279
T: Baz,
279280
<T as Baz>::Qux: Bar {}
280281
282+
fn gp_shadows_trait<Baz: Bar>() {
283+
Baz::bar;
284+
}
285+
281286
//- /foo.rs crate:foo
282287
pub struct Person {
283288
pub name: &'static str,

0 commit comments

Comments
 (0)