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/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 +++++-- 4 files changed, 23 insertions(+), 9 deletions(-) (limited to 'crates/ra_hir/src/ty') 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), -- cgit v1.2.3