aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs4
-rw-r--r--crates/ra_hir/src/ty/infer.rs9
-rw-r--r--crates/ra_hir/src/ty/infer/coerce.rs4
-rw-r--r--crates/ra_hir/src/ty/lower.rs7
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs15
5 files changed, 23 insertions, 16 deletions
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
index 872a4517d..f77492170 100644
--- a/crates/ra_hir/src/ty/autoderef.rs
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -39,7 +39,7 @@ fn deref_by_trait(
39 ty: &Canonical<Ty>, 39 ty: &Canonical<Ty>,
40) -> Option<Canonical<Ty>> { 40) -> Option<Canonical<Ty>> {
41 let krate = resolver.krate()?; 41 let krate = resolver.krate()?;
42 let deref_trait = match db.lang_item(krate, "deref".into())? { 42 let deref_trait = match db.lang_item(krate.into(), "deref".into())? {
43 crate::lang_item::LangItemTarget::Trait(t) => t, 43 crate::lang_item::LangItemTarget::Trait(t) => t,
44 _ => return None, 44 _ => return None,
45 }; 45 };
@@ -71,7 +71,7 @@ fn deref_by_trait(
71 71
72 let canonical = super::Canonical { num_vars: 1 + ty.num_vars, value: in_env }; 72 let canonical = super::Canonical { num_vars: 1 + ty.num_vars, value: in_env };
73 73
74 let solution = db.trait_solve(krate, canonical)?; 74 let solution = db.trait_solve(krate.into(), canonical)?;
75 75
76 match &solution { 76 match &solution {
77 Solution::Unique(vars) => { 77 Solution::Unique(vars) => {
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;
24use hir_def::{ 24use hir_def::{
25 path::known, 25 path::known,
26 type_ref::{Mutability, TypeRef}, 26 type_ref::{Mutability, TypeRef},
27 AdtId, 27 AdtId, DefWithBodyId,
28}; 28};
29use hir_expand::{diagnostics::DiagnosticSink, name}; 29use hir_expand::{diagnostics::DiagnosticSink, name};
30use ra_arena::map::ArenaMap; 30use ra_arena::map::ArenaMap;
@@ -65,7 +65,7 @@ mod coerce;
65/// The entry point of type inference. 65/// The entry point of type inference.
66pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> { 66pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> {
67 let _p = profile("infer_query"); 67 let _p = profile("infer_query");
68 let resolver = def.resolver(db); 68 let resolver = DefWithBodyId::from(def).resolver(db);
69 let mut ctx = InferenceContext::new(db, def, resolver); 69 let mut ctx = InferenceContext::new(db, def, resolver);
70 70
71 match def { 71 match def {
@@ -378,8 +378,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
378 for obligation in obligations { 378 for obligation in obligations {
379 let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); 379 let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone());
380 let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); 380 let canonicalized = self.canonicalizer().canonicalize_obligation(in_env);
381 let solution = 381 let solution = self
382 self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); 382 .db
383 .trait_solve(self.resolver.krate().unwrap().into(), canonicalized.value.clone());
383 384
384 match solution { 385 match solution {
385 Some(Solution::Unique(substs)) => { 386 Some(Solution::Unique(substs)) => {
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs
index 6ea135126..6d297c268 100644
--- a/crates/ra_hir/src/ty/infer/coerce.rs
+++ b/crates/ra_hir/src/ty/infer/coerce.rs
@@ -49,8 +49,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
49 resolver: &Resolver, 49 resolver: &Resolver,
50 ) -> FxHashMap<(TypeCtor, TypeCtor), usize> { 50 ) -> FxHashMap<(TypeCtor, TypeCtor), usize> {
51 let krate = resolver.krate().unwrap(); 51 let krate = resolver.krate().unwrap();
52 let impls = match db.lang_item(krate, "coerce_unsized".into()) { 52 let impls = match db.lang_item(krate.into(), "coerce_unsized".into()) {
53 Some(LangItemTarget::Trait(trait_)) => db.impls_for_trait(krate, trait_), 53 Some(LangItemTarget::Trait(trait_)) => db.impls_for_trait(krate.into(), trait_),
54 _ => return FxHashMap::default(), 54 _ => return FxHashMap::default(),
55 }; 55 };
56 56
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 8ea2806dd..e477b2439 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -12,6 +12,7 @@ use hir_def::{
12 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType}, 12 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType},
13 path::{GenericArg, PathSegment}, 13 path::{GenericArg, PathSegment},
14 type_ref::{TypeBound, TypeRef}, 14 type_ref::{TypeBound, TypeRef},
15 GenericDefId,
15}; 16};
16 17
17use super::{ 18use super::{
@@ -574,7 +575,7 @@ pub(crate) fn generic_predicates_for_param_query(
574 def: GenericDef, 575 def: GenericDef,
575 param_idx: u32, 576 param_idx: u32,
576) -> Arc<[GenericPredicate]> { 577) -> Arc<[GenericPredicate]> {
577 let resolver = def.resolver(db); 578 let resolver = GenericDefId::from(def).resolver(db);
578 resolver 579 resolver
579 .where_predicates_in_scope() 580 .where_predicates_in_scope()
580 // we have to filter out all other predicates *first*, before attempting to lower them 581 // we have to filter out all other predicates *first*, before attempting to lower them
@@ -600,7 +601,7 @@ pub(crate) fn generic_predicates_query(
600 db: &impl HirDatabase, 601 db: &impl HirDatabase,
601 def: GenericDef, 602 def: GenericDef,
602) -> Arc<[GenericPredicate]> { 603) -> Arc<[GenericPredicate]> {
603 let resolver = def.resolver(db); 604 let resolver = GenericDefId::from(def).resolver(db);
604 resolver 605 resolver
605 .where_predicates_in_scope() 606 .where_predicates_in_scope()
606 .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred)) 607 .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred))
@@ -609,7 +610,7 @@ pub(crate) fn generic_predicates_query(
609 610
610/// Resolve the default type params from generics 611/// Resolve the default type params from generics
611pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs { 612pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs {
612 let resolver = def.resolver(db); 613 let resolver = GenericDefId::from(def).resolver(db);
613 let generic_params = def.generic_params(db); 614 let generic_params = def.generic_params(db);
614 615
615 let defaults = generic_params 616 let defaults = generic_params
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 26dd06171..5ad72ef9f 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -172,9 +172,14 @@ pub(crate) fn iterate_method_candidates<T>(
172 // rustc does an autoderef and then autoref again). 172 // rustc does an autoderef and then autoref again).
173 173
174 for derefed_ty in autoderef::autoderef(db, resolver, ty.clone()) { 174 for derefed_ty in autoderef::autoderef(db, resolver, ty.clone()) {
175 if let Some(result) = 175 if let Some(result) = iterate_inherent_methods(
176 iterate_inherent_methods(&derefed_ty, db, name, mode, krate, &mut callback) 176 &derefed_ty,
177 { 177 db,
178 name,
179 mode,
180 krate.into(),
181 &mut callback,
182 ) {
178 return Some(result); 183 return Some(result);
179 } 184 }
180 if let Some(result) = iterate_trait_method_candidates( 185 if let Some(result) = iterate_trait_method_candidates(
@@ -192,7 +197,7 @@ pub(crate) fn iterate_method_candidates<T>(
192 LookupMode::Path => { 197 LookupMode::Path => {
193 // No autoderef for path lookups 198 // No autoderef for path lookups
194 if let Some(result) = 199 if let Some(result) =
195 iterate_inherent_methods(&ty, db, name, mode, krate, &mut callback) 200 iterate_inherent_methods(&ty, db, name, mode, krate.into(), &mut callback)
196 { 201 {
197 return Some(result); 202 return Some(result);
198 } 203 }
@@ -240,7 +245,7 @@ fn iterate_trait_method_candidates<T>(
240 } 245 }
241 if !known_implemented { 246 if !known_implemented {
242 let goal = generic_implements_goal(db, env.clone(), t, ty.clone()); 247 let goal = generic_implements_goal(db, env.clone(), t, ty.clone());
243 if db.trait_solve(krate, goal).is_none() { 248 if db.trait_solve(krate.into(), goal).is_none() {
244 continue 'traits; 249 continue 'traits;
245 } 250 }
246 } 251 }