Introduce hir::GenericParam

Unlike existing hir::GenericParams, this is a global ID.
This commit is contained in:
Aleksey Kladov 2019-11-11 17:36:27 +03:00
parent ff609cc497
commit c5a18c44e5
4 changed files with 19 additions and 9 deletions

View File

@ -23,7 +23,7 @@ use crate::{
adt::VariantDef, adt::VariantDef,
db::{AstDatabase, DefDatabase, HirDatabase}, db::{AstDatabase, DefDatabase, HirDatabase},
expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId}, expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId},
generics::HasGenericParams, generics::{GenericDef, HasGenericParams},
ids::{ ids::{
AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId,
TypeAliasId, TypeAliasId,
@ -1121,3 +1121,9 @@ impl Local {
src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root)))
} }
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct GenericParam {
pub(crate) parent: GenericDef,
pub(crate) idx: u32,
}

View File

@ -65,8 +65,8 @@ pub use crate::{
docs::{DocDef, Docs, Documentation}, docs::{DocDef, Docs, Documentation},
src::{HasBodySource, HasSource}, src::{HasBodySource, HasSource},
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
EnumVariant, FieldSource, FnData, Function, HasBody, Local, MacroDef, Module, ModuleDef, EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, Local, MacroDef, Module,
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
}, },
expr::ExprScopes, expr::ExprScopes,
from_source::FromSource, from_source::FromSource,

View File

@ -28,8 +28,8 @@ use crate::{
ids::LocationCtx, ids::LocationCtx,
resolve::{ScopeDef, TypeNs, ValueNs}, resolve::{ScopeDef, TypeNs, ValueNs},
ty::method_resolution::{self, implements_trait}, ty::method_resolution::{self, implements_trait},
AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, Local, AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, GenericParam, HasBody,
MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty,
}; };
fn try_get_resolver_for_node( fn try_get_resolver_for_node(
@ -107,7 +107,7 @@ pub enum PathResolution {
/// A local binding (only value namespace) /// A local binding (only value namespace)
Local(Local), Local(Local),
/// A generic parameter /// A generic parameter
GenericParam(u32), GenericParam(GenericParam),
SelfType(crate::ImplBlock), SelfType(crate::ImplBlock),
Macro(MacroDef), Macro(MacroDef),
AssocItem(crate::AssocItem), AssocItem(crate::AssocItem),
@ -227,7 +227,10 @@ impl SourceAnalyzer {
) -> Option<PathResolution> { ) -> Option<PathResolution> {
let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty {
TypeNs::SelfType(it) => PathResolution::SelfType(it), TypeNs::SelfType(it) => PathResolution::SelfType(it),
TypeNs::GenericParam(it) => PathResolution::GenericParam(it), TypeNs::GenericParam(idx) => PathResolution::GenericParam(GenericParam {
parent: self.resolver.generic_def().unwrap(),
idx,
}),
TypeNs::AdtSelfType(it) | TypeNs::Adt(it) => PathResolution::Def(it.into()), TypeNs::AdtSelfType(it) | TypeNs::Adt(it) => PathResolution::Def(it.into()),
TypeNs::EnumVariant(it) => PathResolution::Def(it.into()), TypeNs::EnumVariant(it) => PathResolution::Def(it.into()),
TypeNs::TypeAlias(it) => PathResolution::Def(it.into()), TypeNs::TypeAlias(it) => PathResolution::Def(it.into()),

View File

@ -4,7 +4,8 @@
//! Note that the reference search is possible for not all of the classified items. //! Note that the reference search is possible for not all of the classified items.
use hir::{ use hir::{
Adt, AssocItem, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, VariantDef, Adt, AssocItem, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty,
VariantDef,
}; };
use ra_syntax::{ast, ast::VisibilityOwner}; use ra_syntax::{ast, ast::VisibilityOwner};
@ -18,7 +19,7 @@ pub enum NameKind {
Def(ModuleDef), Def(ModuleDef),
SelfType(Ty), SelfType(Ty),
Local(Local), Local(Local),
GenericParam(u32), GenericParam(GenericParam),
} }
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]