diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 3af47000f4..2e0dbf82b7 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -70,7 +70,7 @@ impl PathResolution { | PathResolution::Local(_) | PathResolution::Macro(_) | PathResolution::ConstParam(_) => None, - PathResolution::TypeParam(param) => Some(TypeNs::GenericParam(param.merge().into())), + PathResolution::TypeParam(param) => Some(TypeNs::GenericParam((*param).into())), PathResolution::SelfType(impl_def) => Some(TypeNs::SelfType((*impl_def).into())), PathResolution::AssocItem(AssocItem::Const(_) | AssocItem::Function(_)) => None, PathResolution::AssocItem(AssocItem::TypeAlias(alias)) => { diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index 1295d05007..c6462a2c78 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -34,7 +34,7 @@ use syntax::{ use crate::{ db::HirDatabase, semantics::PathResolution, Adt, BuiltinAttr, BuiltinType, Const, Field, Function, Local, MacroDef, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias, - TypeOrConstParam, Variant, + Variant, }; use base_db::CrateId; @@ -609,10 +609,7 @@ fn resolve_hir_path_( let res = match ty { TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), - TypeNs::GenericParam(id) => match (TypeOrConstParam { id }).split(db) { - either::Either::Left(x) => PathResolution::ConstParam(x), - either::Either::Right(x) => PathResolution::TypeParam(x), - }, + TypeNs::GenericParam(id) => PathResolution::TypeParam(id.into()), TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { PathResolution::Def(Adt::from(it).into()) } @@ -706,10 +703,7 @@ fn resolve_hir_path_qualifier( 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) => match (TypeOrConstParam { id }).split(db) { - either::Either::Left(x) => PathResolution::ConstParam(x), - either::Either::Right(x) => PathResolution::TypeParam(x), - }, + 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()), diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index 341d444d61..b5a11a1ba5 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs @@ -365,6 +365,13 @@ impl GenericParams { where_predicates.shrink_to_fit(); } + pub fn find_type_by_name(&self, name: &Name) -> Option { + self.types + .iter() + .filter(|x| matches!(x.1, TypeOrConstParamData::TypeParamData(_))) + .find_map(|(id, p)| if p.name().as_ref() == Some(&name) { Some(id) } else { None }) + } + pub fn find_type_or_const_by_name(&self, name: &Name) -> Option { self.types .iter() diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index e19e8543b4..d5e62f226a 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -25,7 +25,7 @@ use crate::{ AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, - TypeOrConstParamId, VariantId, + TypeOrConstParamId, TypeParamId, VariantId, }; #[derive(Debug, Clone, Default)] @@ -68,7 +68,7 @@ enum Scope { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum TypeNs { SelfType(ImplId), - GenericParam(TypeOrConstParamId), + GenericParam(TypeParamId), AdtId(AdtId), AdtSelfType(AdtId), // Yup, enum variants are added to the types ns, but any usage of variant as @@ -192,7 +192,7 @@ impl Resolver { Scope::GenericParams { .. } | Scope::ImplDefScope(_) if skip_to_mod => continue, Scope::GenericParams { params, def } => { - if let Some(local_id) = params.find_type_or_const_by_name(first_name) { + if let Some(local_id) = params.find_type_by_name(first_name) { let idx = if path.segments().len() == 1 { None } else { Some(1) }; return Some(( TypeNs::GenericParam( diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 3444ffd202..3147b6f330 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -372,7 +372,7 @@ impl<'a> TyLoweringContext<'a> { _ => return None, }; match resolution { - TypeNs::GenericParam(param_id) => Some(param_id), + TypeNs::GenericParam(param_id) => Some(param_id.into()), _ => None, } } @@ -991,9 +991,9 @@ fn named_associated_type_shorthand_candidates( return res; } // Handle `Self::Type` referring to own associated type in trait definitions - if let GenericDefId::TraitId(trait_id) = param_id.parent { + if let GenericDefId::TraitId(trait_id) = param_id.parent() { let generics = generics(db.upcast(), trait_id.into()); - if generics.params.types[param_id.local_id].is_trait_self() { + if generics.params.types[param_id.local_id()].is_trait_self() { let trait_ref = TyBuilder::trait_ref(db, trait_id) .fill_with_bound_vars(DebruijnIndex::INNERMOST, 0) .build();