diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 91d02ab5c93..e96c4007407 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -749,22 +749,23 @@ fn resolve_hir_path_qualifier( resolver: &Resolver, path: &Path, ) -> Option { - let items = resolver - .resolve_module_path_in_items(db.upcast(), path.mod_path()) - .take_types() - .map(|it| PathResolution::Def(it.into())); - - if items.is_some() { - return items; - } - - resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty { - TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), - TypeNs::GenericParam(id) => PathResolution::TypeParam(id.into()), - TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()), - TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()), - TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), - TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()), - TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), - }) + resolver + .resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()) + .map(|ty| match ty { + TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), + TypeNs::GenericParam(id) => PathResolution::TypeParam(id.into()), + TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { + PathResolution::Def(Adt::from(it).into()) + } + TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()), + TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()), + TypeNs::BuiltinType(it) => PathResolution::Def(BuiltinType::from(it).into()), + TypeNs::TraitId(it) => PathResolution::Def(Trait::from(it).into()), + }) + .or_else(|| { + resolver + .resolve_module_path_in_items(db.upcast(), path.mod_path()) + .take_types() + .map(|it| PathResolution::Def(it.into())) + }) } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_general.html b/crates/ide/src/syntax_highlighting/test_data/highlight_general.html index d5c930e0494..1abb6eb8f39 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_general.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_general.html @@ -225,4 +225,8 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd T: Baz, <T as Baz>::Qux: Bar {} +fn gp_shadows_trait<Baz: Bar>() { + Baz::bar; +} + \ No newline at end of file diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index fdfe347a328..d7686695942 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -31,6 +31,7 @@ struct Foo; false, ); } + #[test] fn macros() { check_highlighting( @@ -278,6 +279,10 @@ where T: Baz, ::Qux: Bar {} +fn gp_shadows_trait() { + Baz::bar; +} + //- /foo.rs crate:foo pub struct Person { pub name: &'static str,