diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-21 12:50:12 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-21 12:50:12 +0000 |
commit | 1f61915bde4c5d8d4fe2e9b8dfa9445008730b79 (patch) | |
tree | a6fd0b6ad8b6c87d28e6e1b36bb9b2fbae2c1b09 /crates/ra_hir/src/ty/infer.rs | |
parent | 612a72fc4ea4376920f2a7da7b3c334227c1716c (diff) | |
parent | c37d1c5b381365ce2d07dfe4b871e43995ccea2d (diff) |
Merge #2337
2337: Move resolver to hir_def r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 7f9e81d64..69b13baef 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -23,7 +23,9 @@ use rustc_hash::FxHashMap; | |||
23 | 23 | ||
24 | use hir_def::{ | 24 | use hir_def::{ |
25 | path::known, | 25 | path::known, |
26 | resolver::{HasResolver, Resolver, TypeNs}, | ||
26 | type_ref::{Mutability, TypeRef}, | 27 | type_ref::{Mutability, TypeRef}, |
28 | AdtId, DefWithBodyId, | ||
27 | }; | 29 | }; |
28 | use hir_expand::{diagnostics::DiagnosticSink, name}; | 30 | use hir_expand::{diagnostics::DiagnosticSink, name}; |
29 | use ra_arena::map::ArenaMap; | 31 | use ra_arena::map::ArenaMap; |
@@ -40,10 +42,9 @@ use crate::{ | |||
40 | code_model::TypeAlias, | 42 | code_model::TypeAlias, |
41 | db::HirDatabase, | 43 | db::HirDatabase, |
42 | expr::{BindingAnnotation, Body, ExprId, PatId}, | 44 | expr::{BindingAnnotation, Body, ExprId, PatId}, |
43 | resolve::{HasResolver, Resolver, TypeNs}, | ||
44 | ty::infer::diagnostics::InferenceDiagnostic, | 45 | ty::infer::diagnostics::InferenceDiagnostic, |
45 | Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, | 46 | Adt, AssocItem, ConstData, DefWithBody, FloatTy, FnData, Function, HasBody, IntTy, Path, |
46 | StructField, VariantDef, | 47 | StructField, Trait, VariantDef, |
47 | }; | 48 | }; |
48 | 49 | ||
49 | macro_rules! ty_app { | 50 | macro_rules! ty_app { |
@@ -64,7 +65,7 @@ mod coerce; | |||
64 | /// The entry point of type inference. | 65 | /// The entry point of type inference. |
65 | pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> { | 66 | pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> { |
66 | let _p = profile("infer_query"); | 67 | let _p = profile("infer_query"); |
67 | let resolver = def.resolver(db); | 68 | let resolver = DefWithBodyId::from(def).resolver(db); |
68 | let mut ctx = InferenceContext::new(db, def, resolver); | 69 | let mut ctx = InferenceContext::new(db, def, resolver); |
69 | 70 | ||
70 | match def { | 71 | match def { |
@@ -377,8 +378,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
377 | for obligation in obligations { | 378 | for obligation in obligations { |
378 | let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); | 379 | let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); |
379 | let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); | 380 | let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); |
380 | let solution = | 381 | let solution = self |
381 | self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); | 382 | .db |
383 | .trait_solve(self.resolver.krate().unwrap().into(), canonicalized.value.clone()); | ||
382 | 384 | ||
383 | match solution { | 385 | match solution { |
384 | Some(Solution::Unique(substs)) => { | 386 | Some(Solution::Unique(substs)) => { |
@@ -518,17 +520,17 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
518 | // FIXME: this should resolve assoc items as well, see this example: | 520 | // FIXME: this should resolve assoc items as well, see this example: |
519 | // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 | 521 | // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 |
520 | match resolver.resolve_path_in_type_ns_fully(self.db, &path) { | 522 | match resolver.resolve_path_in_type_ns_fully(self.db, &path) { |
521 | Some(TypeNs::Adt(Adt::Struct(it))) => it.into(), | 523 | Some(TypeNs::AdtId(AdtId::StructId(it))) => it.into(), |
522 | Some(TypeNs::Adt(Adt::Union(it))) => it.into(), | 524 | Some(TypeNs::AdtId(AdtId::UnionId(it))) => it.into(), |
523 | Some(TypeNs::AdtSelfType(adt)) => adt.into(), | 525 | Some(TypeNs::AdtSelfType(adt)) => adt.into(), |
524 | Some(TypeNs::EnumVariant(it)) => it.into(), | 526 | Some(TypeNs::EnumVariantId(it)) => it.into(), |
525 | Some(TypeNs::TypeAlias(it)) => it.into(), | 527 | Some(TypeNs::TypeAliasId(it)) => it.into(), |
526 | 528 | ||
527 | Some(TypeNs::SelfType(_)) | | 529 | Some(TypeNs::SelfType(_)) | |
528 | Some(TypeNs::GenericParam(_)) | | 530 | Some(TypeNs::GenericParam(_)) | |
529 | Some(TypeNs::BuiltinType(_)) | | 531 | Some(TypeNs::BuiltinType(_)) | |
530 | Some(TypeNs::Trait(_)) | | 532 | Some(TypeNs::TraitId(_)) | |
531 | Some(TypeNs::Adt(Adt::Enum(_))) | | 533 | Some(TypeNs::AdtId(AdtId::EnumId(_))) | |
532 | None => { | 534 | None => { |
533 | return (Ty::Unknown, None) | 535 | return (Ty::Unknown, None) |
534 | } | 536 | } |
@@ -576,26 +578,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
576 | 578 | ||
577 | fn resolve_into_iter_item(&self) -> Option<TypeAlias> { | 579 | fn resolve_into_iter_item(&self) -> Option<TypeAlias> { |
578 | let path = known::std_iter_into_iterator(); | 580 | let path = known::std_iter_into_iterator(); |
579 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 581 | let trait_: Trait = self.resolver.resolve_known_trait(self.db, &path)?.into(); |
580 | trait_.associated_type_by_name(self.db, &name::ITEM_TYPE) | 582 | trait_.associated_type_by_name(self.db, &name::ITEM_TYPE) |
581 | } | 583 | } |
582 | 584 | ||
583 | fn resolve_ops_try_ok(&self) -> Option<TypeAlias> { | 585 | fn resolve_ops_try_ok(&self) -> Option<TypeAlias> { |
584 | let path = known::std_ops_try(); | 586 | let path = known::std_ops_try(); |
585 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 587 | let trait_: Trait = self.resolver.resolve_known_trait(self.db, &path)?.into(); |
586 | trait_.associated_type_by_name(self.db, &name::OK_TYPE) | 588 | trait_.associated_type_by_name(self.db, &name::OK_TYPE) |
587 | } | 589 | } |
588 | 590 | ||
589 | fn resolve_future_future_output(&self) -> Option<TypeAlias> { | 591 | fn resolve_future_future_output(&self) -> Option<TypeAlias> { |
590 | let path = known::std_future_future(); | 592 | let path = known::std_future_future(); |
591 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 593 | let trait_: Trait = self.resolver.resolve_known_trait(self.db, &path)?.into(); |
592 | trait_.associated_type_by_name(self.db, &name::OUTPUT_TYPE) | 594 | trait_.associated_type_by_name(self.db, &name::OUTPUT_TYPE) |
593 | } | 595 | } |
594 | 596 | ||
595 | fn resolve_boxed_box(&self) -> Option<Adt> { | 597 | fn resolve_boxed_box(&self) -> Option<Adt> { |
596 | let path = known::std_boxed_box(); | 598 | let path = known::std_boxed_box(); |
597 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 599 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
598 | Some(Adt::Struct(struct_)) | 600 | Some(Adt::Struct(struct_.into())) |
599 | } | 601 | } |
600 | } | 602 | } |
601 | 603 | ||