From 739babc39188c93eda82ce16a24680bbf2463fa1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 Nov 2019 23:02:35 +0300 Subject: Move Namespace enum closer to usage --- crates/ra_hir/src/code_model.rs | 4 ++-- crates/ra_hir/src/db.rs | 4 ++-- crates/ra_hir/src/lib.rs | 5 +---- crates/ra_hir/src/ty.rs | 2 +- crates/ra_hir/src/ty/infer/expr.rs | 6 +++--- crates/ra_hir/src/ty/infer/path.rs | 4 ++-- crates/ra_hir/src/ty/lower.rs | 15 +++++++++++++-- crates/ra_hir/src/ty/traits/chalk.rs | 7 +++++-- crates/ra_hir_def/src/nameres/per_ns.rs | 8 -------- 9 files changed, 29 insertions(+), 26 deletions(-) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 181c5d47a..4e273d9e4 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -30,8 +30,8 @@ use crate::{ impl_block::ImplBlock, resolve::{Resolver, Scope, TypeNs}, traits::TraitData, - ty::{InferenceResult, TraitRef}, - Either, HasSource, Name, ScopeDef, Ty, {ImportId, Namespace}, + ty::{InferenceResult, Namespace, TraitRef}, + Either, HasSource, ImportId, Name, ScopeDef, Ty, }; /// hir::Crate describes a single crate. It's the main interface with which diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index eb66325f7..11b3f94ae 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -14,10 +14,10 @@ use crate::{ traits::TraitData, ty::{ method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate, - InferenceResult, Substs, Ty, TypableDef, TypeCtor, + InferenceResult, Namespace, Substs, Ty, TypableDef, TypeCtor, }, type_alias::TypeAliasData, - Const, ConstData, Crate, DefWithBody, ExprScopes, FnData, Function, Module, Namespace, Static, + Const, ConstData, Crate, DefWithBody, ExprScopes, FnData, Function, Module, Static, StructField, Trait, TypeAlias, }; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index da6aa2ed8..5f2a05e76 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -81,10 +81,7 @@ pub use crate::{ pub use hir_def::{ builtin_type::BuiltinType, - nameres::{ - per_ns::{Namespace, PerNs}, - raw::ImportId, - }, + nameres::{per_ns::PerNs, raw::ImportId}, path::{Path, PathKind}, type_ref::Mutability, }; diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index d1a9d7411..cd2ac0e8b 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -27,7 +27,7 @@ pub(crate) use infer::{infer_query, InferTy, InferenceResult}; pub use lower::CallableDef; pub(crate) use lower::{ callable_item_sig, generic_defaults_query, generic_predicates_for_param_query, - generic_predicates_query, type_for_def, type_for_field, TypableDef, + generic_predicates_query, type_for_def, type_for_field, Namespace, TypableDef, }; pub(crate) use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index a09ef5c5d..4af1d65ee 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs @@ -12,10 +12,10 @@ use crate::{ expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, generics::{GenericParams, HasGenericParams}, ty::{ - autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, - ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, + autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Namespace, + Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, }, - Adt, Name, Namespace, + Adt, Name, }; impl<'a, D: HirDatabase> InferenceContext<'a, D> { diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index 59b7f7eb6..865ced5a1 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs @@ -6,8 +6,8 @@ use super::{ExprOrPatId, InferenceContext, TraitRef}; use crate::{ db::HirDatabase, resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, - ty::{method_resolution, Substs, Ty, TypableDef, TypeWalk}, - AssocItem, Container, HasGenericParams, Name, Namespace, Path, + ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, + AssocItem, Container, HasGenericParams, Name, Path, }; impl<'a, D: HirDatabase> InferenceContext<'a, D> { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index e29ab8492..d26b16cb2 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -29,10 +29,21 @@ use crate::{ Adt, }, util::make_mut_slice, - Const, Enum, EnumVariant, Function, ModuleDef, Namespace, Path, Static, Struct, StructField, - Trait, TypeAlias, Union, + Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait, + TypeAlias, Union, }; +// FIXME: this is only really used in `type_for_def`, which contains a bunch of +// impossible cases. Perhaps we should recombine `TypeableDef` and `Namespace` +// into a `AsTypeDef`, `AsValueDef` enums? +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub enum Namespace { + Types, + Values, + // Note that only type inference uses this enum, and it doesn't care about macros. + // Macro, +} + impl Ty { pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self { match type_ref { diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 39ef92182..c694952f3 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs @@ -18,7 +18,10 @@ use crate::{ db::HirDatabase, generics::GenericDef, ty::display::HirDisplay, - ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, + ty::{ + ApplicationTy, GenericPredicate, Namespace, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, + TypeWalk, + }, AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias, }; @@ -652,7 +655,7 @@ fn impl_block_datum( }) .filter_map(|t| { let assoc_ty = trait_.associated_type_by_name(db, &t.name(db))?; - let ty = db.type_for_def(t.into(), crate::Namespace::Types).subst(&bound_vars); + let ty = db.type_for_def(t.into(), Namespace::Types).subst(&bound_vars); Some(chalk_rust_ir::AssociatedTyValue { impl_id, associated_ty_id: assoc_ty.to_chalk(db), diff --git a/crates/ra_hir_def/src/nameres/per_ns.rs b/crates/ra_hir_def/src/nameres/per_ns.rs index 298b0b0c7..717ed1ef9 100644 --- a/crates/ra_hir_def/src/nameres/per_ns.rs +++ b/crates/ra_hir_def/src/nameres/per_ns.rs @@ -4,14 +4,6 @@ use hir_expand::MacroDefId; use crate::ModuleDefId; -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub enum Namespace { - Types, - Values, - // Note that only type inference uses this enum, and it doesn't care about macros. - // Macro, -} - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub struct PerNs { pub types: Option, -- cgit v1.2.3