Move Namespace enum closer to usage

This commit is contained in:
Aleksey Kladov 2019-11-04 23:02:35 +03:00
parent 50364bd478
commit 739babc391
9 changed files with 29 additions and 26 deletions

View file

@ -30,8 +30,8 @@ use crate::{
impl_block::ImplBlock, impl_block::ImplBlock,
resolve::{Resolver, Scope, TypeNs}, resolve::{Resolver, Scope, TypeNs},
traits::TraitData, traits::TraitData,
ty::{InferenceResult, TraitRef}, ty::{InferenceResult, Namespace, TraitRef},
Either, HasSource, Name, ScopeDef, Ty, {ImportId, Namespace}, Either, HasSource, ImportId, Name, ScopeDef, Ty,
}; };
/// hir::Crate describes a single crate. It's the main interface with which /// hir::Crate describes a single crate. It's the main interface with which

View file

@ -14,10 +14,10 @@ use crate::{
traits::TraitData, traits::TraitData,
ty::{ ty::{
method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate, method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate,
InferenceResult, Substs, Ty, TypableDef, TypeCtor, InferenceResult, Namespace, Substs, Ty, TypableDef, TypeCtor,
}, },
type_alias::TypeAliasData, 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, StructField, Trait, TypeAlias,
}; };

View file

@ -81,10 +81,7 @@ pub use crate::{
pub use hir_def::{ pub use hir_def::{
builtin_type::BuiltinType, builtin_type::BuiltinType,
nameres::{ nameres::{per_ns::PerNs, raw::ImportId},
per_ns::{Namespace, PerNs},
raw::ImportId,
},
path::{Path, PathKind}, path::{Path, PathKind},
type_ref::Mutability, type_ref::Mutability,
}; };

View file

@ -27,7 +27,7 @@ pub(crate) use infer::{infer_query, InferTy, InferenceResult};
pub use lower::CallableDef; pub use lower::CallableDef;
pub(crate) use lower::{ pub(crate) use lower::{
callable_item_sig, generic_defaults_query, generic_predicates_for_param_query, 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}; pub(crate) use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};

View file

@ -12,10 +12,10 @@ use crate::{
expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
generics::{GenericParams, HasGenericParams}, generics::{GenericParams, HasGenericParams},
ty::{ ty::{
autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Namespace,
ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
}, },
Adt, Name, Namespace, Adt, Name,
}; };
impl<'a, D: HirDatabase> InferenceContext<'a, D> { impl<'a, D: HirDatabase> InferenceContext<'a, D> {

View file

@ -6,8 +6,8 @@ use super::{ExprOrPatId, InferenceContext, TraitRef};
use crate::{ use crate::{
db::HirDatabase, db::HirDatabase,
resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs},
ty::{method_resolution, Substs, Ty, TypableDef, TypeWalk}, ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk},
AssocItem, Container, HasGenericParams, Name, Namespace, Path, AssocItem, Container, HasGenericParams, Name, Path,
}; };
impl<'a, D: HirDatabase> InferenceContext<'a, D> { impl<'a, D: HirDatabase> InferenceContext<'a, D> {

View file

@ -29,10 +29,21 @@ use crate::{
Adt, Adt,
}, },
util::make_mut_slice, util::make_mut_slice,
Const, Enum, EnumVariant, Function, ModuleDef, Namespace, Path, Static, Struct, StructField, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait,
Trait, TypeAlias, Union, 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 { impl Ty {
pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self { pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self {
match type_ref { match type_ref {

View file

@ -18,7 +18,10 @@ use crate::{
db::HirDatabase, db::HirDatabase,
generics::GenericDef, generics::GenericDef,
ty::display::HirDisplay, 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, AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias,
}; };
@ -652,7 +655,7 @@ fn impl_block_datum(
}) })
.filter_map(|t| { .filter_map(|t| {
let assoc_ty = trait_.associated_type_by_name(db, &t.name(db))?; 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 { Some(chalk_rust_ir::AssociatedTyValue {
impl_id, impl_id,
associated_ty_id: assoc_ty.to_chalk(db), associated_ty_id: assoc_ty.to_chalk(db),

View file

@ -4,14 +4,6 @@ use hir_expand::MacroDefId;
use crate::ModuleDefId; 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)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct PerNs { pub struct PerNs {
pub types: Option<ModuleDefId>, pub types: Option<ModuleDefId>,