From ff609cc49715571324b72d2bda60d56878466640 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 11 Nov 2019 17:22:06 +0300 Subject: Don't reexport generics from HIR --- crates/ra_hir/src/lib.rs | 4 ++-- crates/ra_hir/src/ty.rs | 12 ++++++------ crates/ra_hir/src/ty/autoderef.rs | 2 +- crates/ra_hir/src/ty/infer/path.rs | 3 ++- crates/ra_hir/src/ty/traits/chalk.rs | 4 ++-- 5 files changed, 13 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 806f1daed..125c4b289 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -39,7 +39,7 @@ mod ty; mod impl_block; mod expr; mod lang_item; -mod generics; +pub mod generics; mod resolve; pub mod diagnostics; mod util; @@ -70,7 +70,7 @@ pub use crate::{ }, expr::ExprScopes, from_source::FromSource, - generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, + generics::GenericDef, ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, impl_block::ImplBlock, resolve::ScopeDef, diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index cd2ac0e8b..6f24cfad6 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -17,8 +17,11 @@ use std::sync::Arc; use std::{fmt, iter, mem}; use crate::{ - db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, GenericParams, - HasGenericParams, Mutability, Name, Trait, TypeAlias, + db::HirDatabase, + expr::ExprId, + generics::{GenericParams, HasGenericParams}, + util::make_mut_slice, + Adt, Crate, DefWithBody, Mutability, Name, Trait, TypeAlias, }; use display::{HirDisplay, HirFormatter}; @@ -342,10 +345,7 @@ impl Substs { ) } - pub fn build_for_def( - db: &impl HirDatabase, - def: impl crate::HasGenericParams, - ) -> SubstsBuilder { + pub fn build_for_def(db: &impl HirDatabase, def: impl HasGenericParams) -> SubstsBuilder { let params = def.generic_params(db); let param_count = params.count_params_including_parent(); Substs::builder(param_count) diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 3645ee831..872a4517d 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -9,7 +9,7 @@ use hir_expand::name; use log::{info, warn}; use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; -use crate::{db::HirDatabase, HasGenericParams, Resolver}; +use crate::{db::HirDatabase, generics::HasGenericParams, Resolver}; const AUTODEREF_RECURSION_LIMIT: usize = 10; diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index 865ced5a1..31ca675aa 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs @@ -5,9 +5,10 @@ use hir_def::path::PathSegment; use super::{ExprOrPatId, InferenceContext, TraitRef}; use crate::{ db::HirDatabase, + generics::HasGenericParams, resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, - AssocItem, Container, HasGenericParams, Name, Path, + AssocItem, Container, Name, Path, }; impl<'a, D: HirDatabase> InferenceContext<'a, D> { diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index c694952f3..14c54b9fb 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -16,13 +16,13 @@ use ra_db::salsa::{InternId, InternKey}; use super::{Canonical, ChalkContext, Impl, Obligation}; use crate::{ db::HirDatabase, - generics::GenericDef, + generics::{GenericDef, HasGenericParams}, ty::display::HirDisplay, ty::{ ApplicationTy, GenericPredicate, Namespace, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, }, - AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias, + AssocItem, Crate, ImplBlock, Trait, TypeAlias, }; /// This represents a trait whose name we could not resolve. -- cgit v1.2.3 From c5a18c44e5211282c22b9ca7aae8700ee8ca1817 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 11 Nov 2019 17:36:27 +0300 Subject: Introduce hir::GenericParam Unlike existing hir::GenericParams, this is a global ID. --- crates/ra_hir/src/code_model.rs | 8 +++++++- crates/ra_hir/src/lib.rs | 4 ++-- crates/ra_hir/src/source_binder.rs | 11 +++++++---- crates/ra_ide_api/src/references/name_definition.rs | 5 +++-- 4 files changed, 19 insertions(+), 9 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 09c4e97fa..5a0bd0c19 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -23,7 +23,7 @@ use crate::{ adt::VariantDef, db::{AstDatabase, DefDatabase, HirDatabase}, expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId}, - generics::HasGenericParams, + generics::{GenericDef, HasGenericParams}, ids::{ AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, TypeAliasId, @@ -1121,3 +1121,9 @@ impl Local { 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, +} diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 125c4b289..92d71b9e8 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -65,8 +65,8 @@ pub use crate::{ docs::{DocDef, Docs, Documentation}, src::{HasBodySource, HasSource}, Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, - EnumVariant, FieldSource, FnData, Function, HasBody, Local, MacroDef, Module, ModuleDef, - ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, + EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, Local, MacroDef, Module, + ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, }, expr::ExprScopes, from_source::FromSource, diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index c5fdf3bab..fe4211819 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -28,8 +28,8 @@ use crate::{ ids::LocationCtx, resolve::{ScopeDef, TypeNs, ValueNs}, ty::method_resolution::{self, implements_trait}, - AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, Local, - MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, + AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, GenericParam, HasBody, + HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, }; fn try_get_resolver_for_node( @@ -107,7 +107,7 @@ pub enum PathResolution { /// A local binding (only value namespace) Local(Local), /// A generic parameter - GenericParam(u32), + GenericParam(GenericParam), SelfType(crate::ImplBlock), Macro(MacroDef), AssocItem(crate::AssocItem), @@ -227,7 +227,10 @@ impl SourceAnalyzer { ) -> Option { let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { 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::EnumVariant(it) => PathResolution::Def(it.into()), TypeNs::TypeAlias(it) => PathResolution::Def(it.into()), diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs index 450f7ea9b..ccd75278a 100644 --- a/crates/ra_ide_api/src/references/name_definition.rs +++ b/crates/ra_ide_api/src/references/name_definition.rs @@ -4,7 +4,8 @@ //! Note that the reference search is possible for not all of the classified items. 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}; @@ -18,7 +19,7 @@ pub enum NameKind { Def(ModuleDef), SelfType(Ty), Local(Local), - GenericParam(u32), + GenericParam(GenericParam), } #[derive(PartialEq, Eq)] -- cgit v1.2.3