From 0102fb41337ac0442e689d410bb424d215e9a7bd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Nov 2019 12:21:46 +0300 Subject: Decouple Resolver --- crates/ra_hir/src/ty/infer.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir/src/ty/infer.rs') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 7f9e81d64..684d66946 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -24,6 +24,7 @@ use rustc_hash::FxHashMap; use hir_def::{ path::known, type_ref::{Mutability, TypeRef}, + AdtId, }; use hir_expand::{diagnostics::DiagnosticSink, name}; use ra_arena::map::ArenaMap; @@ -43,7 +44,7 @@ use crate::{ resolve::{HasResolver, Resolver, TypeNs}, ty::infer::diagnostics::InferenceDiagnostic, Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, - StructField, VariantDef, + StructField, Trait, VariantDef, }; macro_rules! ty_app { @@ -518,17 +519,17 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // FIXME: this should resolve assoc items as well, see this example: // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 match resolver.resolve_path_in_type_ns_fully(self.db, &path) { - Some(TypeNs::Adt(Adt::Struct(it))) => it.into(), - Some(TypeNs::Adt(Adt::Union(it))) => it.into(), + Some(TypeNs::AdtId(AdtId::StructId(it))) => it.into(), + Some(TypeNs::AdtId(AdtId::UnionId(it))) => it.into(), Some(TypeNs::AdtSelfType(adt)) => adt.into(), - Some(TypeNs::EnumVariant(it)) => it.into(), - Some(TypeNs::TypeAlias(it)) => it.into(), + Some(TypeNs::EnumVariantId(it)) => it.into(), + Some(TypeNs::TypeAliasId(it)) => it.into(), Some(TypeNs::SelfType(_)) | Some(TypeNs::GenericParam(_)) | Some(TypeNs::BuiltinType(_)) | - Some(TypeNs::Trait(_)) | - Some(TypeNs::Adt(Adt::Enum(_))) | + Some(TypeNs::TraitId(_)) | + Some(TypeNs::AdtId(AdtId::EnumId(_))) | None => { return (Ty::Unknown, None) } @@ -576,26 +577,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_into_iter_item(&self) -> Option { let path = known::std_iter_into_iterator(); - let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + let trait_: Trait = self.resolver.resolve_known_trait(self.db, &path)?.into(); trait_.associated_type_by_name(self.db, &name::ITEM_TYPE) } fn resolve_ops_try_ok(&self) -> Option { let path = known::std_ops_try(); - let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + let trait_: Trait = self.resolver.resolve_known_trait(self.db, &path)?.into(); trait_.associated_type_by_name(self.db, &name::OK_TYPE) } fn resolve_future_future_output(&self) -> Option { let path = known::std_future_future(); - let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + let trait_: Trait = self.resolver.resolve_known_trait(self.db, &path)?.into(); trait_.associated_type_by_name(self.db, &name::OUTPUT_TYPE) } fn resolve_boxed_box(&self) -> Option { let path = known::std_boxed_box(); let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; - Some(Adt::Struct(struct_)) + Some(Adt::Struct(struct_.into())) } } -- cgit v1.2.3 From 00684d708b64fe81a0264795f27594d450a8d08d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Nov 2019 15:24:51 +0300 Subject: Decouple --- crates/ra_hir/src/ty/infer.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir/src/ty/infer.rs') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 684d66946..c3d65afa6 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -24,7 +24,7 @@ use rustc_hash::FxHashMap; use hir_def::{ path::known, type_ref::{Mutability, TypeRef}, - AdtId, + AdtId, DefWithBodyId, }; use hir_expand::{diagnostics::DiagnosticSink, name}; use ra_arena::map::ArenaMap; @@ -65,7 +65,7 @@ mod coerce; /// The entry point of type inference. pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc { let _p = profile("infer_query"); - let resolver = def.resolver(db); + let resolver = DefWithBodyId::from(def).resolver(db); let mut ctx = InferenceContext::new(db, def, resolver); match def { @@ -378,8 +378,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { for obligation in obligations { let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); - let solution = - self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); + let solution = self + .db + .trait_solve(self.resolver.krate().unwrap().into(), canonicalized.value.clone()); match solution { Some(Solution::Unique(substs)) => { -- cgit v1.2.3 From 6d64798a2300858c74b1cc0a22f6d3df578288b3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Nov 2019 15:39:09 +0300 Subject: Move resolver to hir_def --- crates/ra_hir/src/ty/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir/src/ty/infer.rs') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index c3d65afa6..69b13baef 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -23,6 +23,7 @@ use rustc_hash::FxHashMap; use hir_def::{ path::known, + resolver::{HasResolver, Resolver, TypeNs}, type_ref::{Mutability, TypeRef}, AdtId, DefWithBodyId, }; @@ -41,7 +42,6 @@ use crate::{ code_model::TypeAlias, db::HirDatabase, expr::{BindingAnnotation, Body, ExprId, PatId}, - resolve::{HasResolver, Resolver, TypeNs}, ty::infer::diagnostics::InferenceDiagnostic, Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, StructField, Trait, VariantDef, -- cgit v1.2.3