2176: Move Namespace enum closer to usage r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-11-04 20:03:11 +00:00 committed by GitHub
commit c08cff4fd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 26 deletions

View file

@ -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

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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};

View file

@ -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> {

View file

@ -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> {

View file

@ -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 {

View file

@ -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),

View file

@ -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<ModuleDefId>,