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
+2 -2
View File
@@ -30,8 +30,8 @@
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
+2 -2
View File
@@ -14,10 +14,10 @@
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,
};
+1 -4
View File
@@ -81,10 +81,7 @@ fn from(it: $sv) -> $e {
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,
};
+1 -1
View File
@@ -27,7 +27,7 @@
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};
+3 -3
View File
@@ -12,10 +12,10 @@
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> {
+2 -2
View File
@@ -6,8 +6,8 @@
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> {
+13 -2
View File
@@ -29,10 +29,21 @@
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 {
+5 -2
View File
@@ -18,7 +18,10 @@
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),
-8
View File
@@ -4,14 +4,6 @@
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>,