mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Resolve only type params in type ns
This commit is contained in:
parent
4fa8749c44
commit
660fd4ab41
5 changed files with 17 additions and 16 deletions
|
@ -70,7 +70,7 @@ impl PathResolution {
|
||||||
| PathResolution::Local(_)
|
| PathResolution::Local(_)
|
||||||
| PathResolution::Macro(_)
|
| PathResolution::Macro(_)
|
||||||
| PathResolution::ConstParam(_) => None,
|
| 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::SelfType(impl_def) => Some(TypeNs::SelfType((*impl_def).into())),
|
||||||
PathResolution::AssocItem(AssocItem::Const(_) | AssocItem::Function(_)) => None,
|
PathResolution::AssocItem(AssocItem::Const(_) | AssocItem::Function(_)) => None,
|
||||||
PathResolution::AssocItem(AssocItem::TypeAlias(alias)) => {
|
PathResolution::AssocItem(AssocItem::TypeAlias(alias)) => {
|
||||||
|
|
|
@ -34,7 +34,7 @@ use syntax::{
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, semantics::PathResolution, Adt, BuiltinAttr, BuiltinType, Const, Field,
|
db::HirDatabase, semantics::PathResolution, Adt, BuiltinAttr, BuiltinType, Const, Field,
|
||||||
Function, Local, MacroDef, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias,
|
Function, Local, MacroDef, ModuleDef, Static, Struct, ToolModule, Trait, Type, TypeAlias,
|
||||||
TypeOrConstParam, Variant,
|
Variant,
|
||||||
};
|
};
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
|
|
||||||
|
@ -609,10 +609,7 @@ fn resolve_hir_path_(
|
||||||
|
|
||||||
let res = match ty {
|
let res = match ty {
|
||||||
TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
|
TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
|
||||||
TypeNs::GenericParam(id) => match (TypeOrConstParam { id }).split(db) {
|
TypeNs::GenericParam(id) => PathResolution::TypeParam(id.into()),
|
||||||
either::Either::Left(x) => PathResolution::ConstParam(x),
|
|
||||||
either::Either::Right(x) => PathResolution::TypeParam(x),
|
|
||||||
},
|
|
||||||
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => {
|
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => {
|
||||||
PathResolution::Def(Adt::from(it).into())
|
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 {
|
resolver.resolve_path_in_type_ns_fully(db.upcast(), path.mod_path()).map(|ty| match ty {
|
||||||
TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
|
TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
|
||||||
TypeNs::GenericParam(id) => match (TypeOrConstParam { id }).split(db) {
|
TypeNs::GenericParam(id) => PathResolution::TypeParam(id.into()),
|
||||||
either::Either::Left(x) => PathResolution::ConstParam(x),
|
|
||||||
either::Either::Right(x) => PathResolution::TypeParam(x),
|
|
||||||
},
|
|
||||||
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()),
|
TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => PathResolution::Def(Adt::from(it).into()),
|
||||||
TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
|
TypeNs::EnumVariantId(it) => PathResolution::Def(Variant::from(it).into()),
|
||||||
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
|
TypeNs::TypeAliasId(it) => PathResolution::Def(TypeAlias::from(it).into()),
|
||||||
|
|
|
@ -365,6 +365,13 @@ impl GenericParams {
|
||||||
where_predicates.shrink_to_fit();
|
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> {
|
pub fn find_type_or_const_by_name(&self, name: &Name) -> Option<LocalTypeOrConstParamId> {
|
||||||
self.types
|
self.types
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::{
|
||||||
AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId,
|
AdtId, AssocItemId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId,
|
||||||
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
|
||||||
LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
|
LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId,
|
||||||
TypeOrConstParamId, VariantId,
|
TypeOrConstParamId, TypeParamId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
@ -68,7 +68,7 @@ enum Scope {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum TypeNs {
|
pub enum TypeNs {
|
||||||
SelfType(ImplId),
|
SelfType(ImplId),
|
||||||
GenericParam(TypeOrConstParamId),
|
GenericParam(TypeParamId),
|
||||||
AdtId(AdtId),
|
AdtId(AdtId),
|
||||||
AdtSelfType(AdtId),
|
AdtSelfType(AdtId),
|
||||||
// Yup, enum variants are added to the types ns, but any usage of variant as
|
// 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 { .. } | Scope::ImplDefScope(_) if skip_to_mod => continue,
|
||||||
|
|
||||||
Scope::GenericParams { params, def } => {
|
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) };
|
let idx = if path.segments().len() == 1 { None } else { Some(1) };
|
||||||
return Some((
|
return Some((
|
||||||
TypeNs::GenericParam(
|
TypeNs::GenericParam(
|
||||||
|
|
|
@ -372,7 +372,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
match resolution {
|
match resolution {
|
||||||
TypeNs::GenericParam(param_id) => Some(param_id),
|
TypeNs::GenericParam(param_id) => Some(param_id.into()),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -991,9 +991,9 @@ fn named_associated_type_shorthand_candidates<R>(
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
// Handle `Self::Type` referring to own associated type in trait definitions
|
// 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());
|
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)
|
let trait_ref = TyBuilder::trait_ref(db, trait_id)
|
||||||
.fill_with_bound_vars(DebruijnIndex::INNERMOST, 0)
|
.fill_with_bound_vars(DebruijnIndex::INNERMOST, 0)
|
||||||
.build();
|
.build();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue