From 559aeb2932368b40cda9ff8d3f7c4cf3aa065819 Mon Sep 17 00:00:00 2001 From: veetaha Date: Mon, 23 Mar 2020 02:01:07 +0200 Subject: ra_hir: add more privacy for Type --- crates/ra_hir/src/code_model.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src/code_model.rs') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 4b150ef06..e91abf6f5 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -10,7 +10,7 @@ use hir_def::{ docs::Documentation, expr::{BindingAnnotation, Pat, PatId}, per_ns::PerNs, - resolver::HasResolver, + resolver::{HasResolver, Resolver}, type_ref::{Mutability, TypeRef}, AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, ImplId, LocalEnumVariantId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, @@ -912,10 +912,8 @@ impl Local { let def = DefWithBodyId::from(self.parent); let infer = db.infer(def); let ty = infer[self.pat_id].clone(); - let resolver = def.resolver(db.upcast()); let krate = def.module(db.upcast()).krate; - let environment = TraitEnvironment::lower(db, &resolver); - Type { krate, ty: InEnvironment { value: ty, environment } } + Type::new(db, krate, def, ty) } pub fn source(self, db: &dyn HirDatabase) -> InFile> { @@ -1020,11 +1018,21 @@ impl ImplDef { #[derive(Clone, PartialEq, Eq, Debug)] pub struct Type { - pub(crate) krate: CrateId, - pub(crate) ty: InEnvironment, + krate: CrateId, + ty: InEnvironment, } impl Type { + pub(crate) fn new_with_resolver( + db: &dyn HirDatabase, + resolver: &Resolver, + ty: Ty, + ) -> Option { + let krate = resolver.krate()?; + let environment = TraitEnvironment::lower(db, &resolver); + Some(Type { krate, ty: InEnvironment { value: ty, environment } }) + } + fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type { let resolver = lexical_env.resolver(db.upcast()); let environment = TraitEnvironment::lower(db, &resolver); -- cgit v1.2.3