about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhkalbasi <hamidrezakalbasi@protonmail.com>2022-03-04 12:30:53 +0330
committerhkalbasi <hamidrezakalbasi@protonmail.com>2022-03-04 12:30:53 +0330
commit660fd4ab415e9543e4d677622aba309ca716ca12 (patch)
tree8c78044e5bc27fe0e7fd5e22a366dbcc7c53a2f2
parent4fa8749c44e1c91335002eb46d59b2a72e756bb3 (diff)
downloadrust-660fd4ab415e9543e4d677622aba309ca716ca12.tar.gz
rust-660fd4ab415e9543e4d677622aba309ca716ca12.zip
Resolve only type params in type ns
-rw-r--r--crates/hir/src/semantics.rs2
-rw-r--r--crates/hir/src/source_analyzer.rs12
-rw-r--r--crates/hir_def/src/generics.rs7
-rw-r--r--crates/hir_def/src/resolver.rs6
-rw-r--r--crates/hir_ty/src/lower.rs6
5 files changed, 17 insertions, 16 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 3af47000f41..2e0dbf82b77 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 1295d050071..c6462a2c78a 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 341d444d619..b5a11a1ba55 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<LocalTypeOrConstParamId> {
+        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<LocalTypeOrConstParamId> {
         self.types
             .iter()
diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs
index e19e8543b41..d5e62f226a0 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 3444ffd2020..3147b6f330b 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<R>(
                 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();