diff options
Diffstat (limited to 'crates/ra_hir_ty/src/method_resolution.rs')
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 7f5e1469e..69c059ac8 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -48,10 +48,7 @@ pub struct CrateImplDefs { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | impl CrateImplDefs { | 50 | impl CrateImplDefs { |
51 | pub(crate) fn impls_in_crate_query( | 51 | pub(crate) fn impls_in_crate_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<CrateImplDefs> { |
52 | db: &impl HirDatabase, | ||
53 | krate: CrateId, | ||
54 | ) -> Arc<CrateImplDefs> { | ||
55 | let _p = profile("impls_in_crate_query"); | 52 | let _p = profile("impls_in_crate_query"); |
56 | let mut res = | 53 | let mut res = |
57 | CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; | 54 | CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; |
@@ -92,7 +89,7 @@ impl CrateImplDefs { | |||
92 | impl Ty { | 89 | impl Ty { |
93 | pub fn def_crates( | 90 | pub fn def_crates( |
94 | &self, | 91 | &self, |
95 | db: &impl HirDatabase, | 92 | db: &dyn HirDatabase, |
96 | cur_crate: CrateId, | 93 | cur_crate: CrateId, |
97 | ) -> Option<ArrayVec<[CrateId; 2]>> { | 94 | ) -> Option<ArrayVec<[CrateId; 2]>> { |
98 | // Types like slice can have inherent impls in several crates, (core and alloc). | 95 | // Types like slice can have inherent impls in several crates, (core and alloc). |
@@ -110,7 +107,7 @@ impl Ty { | |||
110 | let lang_item_targets = match self { | 107 | let lang_item_targets = match self { |
111 | Ty::Apply(a_ty) => match a_ty.ctor { | 108 | Ty::Apply(a_ty) => match a_ty.ctor { |
112 | TypeCtor::Adt(def_id) => { | 109 | TypeCtor::Adt(def_id) => { |
113 | return Some(std::iter::once(def_id.module(db).krate).collect()) | 110 | return Some(std::iter::once(def_id.module(db.upcast()).krate).collect()) |
114 | } | 111 | } |
115 | TypeCtor::Bool => lang_item_crate!("bool"), | 112 | TypeCtor::Bool => lang_item_crate!("bool"), |
116 | TypeCtor::Char => lang_item_crate!("char"), | 113 | TypeCtor::Char => lang_item_crate!("char"), |
@@ -134,7 +131,7 @@ impl Ty { | |||
134 | LangItemTarget::ImplDefId(it) => Some(it), | 131 | LangItemTarget::ImplDefId(it) => Some(it), |
135 | _ => None, | 132 | _ => None, |
136 | }) | 133 | }) |
137 | .map(|it| it.lookup(db).container.module(db).krate) | 134 | .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate) |
138 | .collect(); | 135 | .collect(); |
139 | Some(res) | 136 | Some(res) |
140 | } | 137 | } |
@@ -143,7 +140,7 @@ impl Ty { | |||
143 | /// receiver type (but without autoref applied yet). | 140 | /// receiver type (but without autoref applied yet). |
144 | pub(crate) fn lookup_method( | 141 | pub(crate) fn lookup_method( |
145 | ty: &Canonical<Ty>, | 142 | ty: &Canonical<Ty>, |
146 | db: &impl HirDatabase, | 143 | db: &dyn HirDatabase, |
147 | env: Arc<TraitEnvironment>, | 144 | env: Arc<TraitEnvironment>, |
148 | krate: CrateId, | 145 | krate: CrateId, |
149 | traits_in_scope: &FxHashSet<TraitId>, | 146 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -181,7 +178,7 @@ pub enum LookupMode { | |||
181 | // FIXME add a context type here? | 178 | // FIXME add a context type here? |
182 | pub fn iterate_method_candidates<T>( | 179 | pub fn iterate_method_candidates<T>( |
183 | ty: &Canonical<Ty>, | 180 | ty: &Canonical<Ty>, |
184 | db: &impl HirDatabase, | 181 | db: &dyn HirDatabase, |
185 | env: Arc<TraitEnvironment>, | 182 | env: Arc<TraitEnvironment>, |
186 | krate: CrateId, | 183 | krate: CrateId, |
187 | traits_in_scope: &FxHashSet<TraitId>, | 184 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -247,7 +244,7 @@ pub fn iterate_method_candidates<T>( | |||
247 | 244 | ||
248 | fn iterate_method_candidates_with_autoref<T>( | 245 | fn iterate_method_candidates_with_autoref<T>( |
249 | deref_chain: &[Canonical<Ty>], | 246 | deref_chain: &[Canonical<Ty>], |
250 | db: &impl HirDatabase, | 247 | db: &dyn HirDatabase, |
251 | env: Arc<TraitEnvironment>, | 248 | env: Arc<TraitEnvironment>, |
252 | krate: CrateId, | 249 | krate: CrateId, |
253 | traits_in_scope: &FxHashSet<TraitId>, | 250 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -304,7 +301,7 @@ fn iterate_method_candidates_with_autoref<T>( | |||
304 | fn iterate_method_candidates_by_receiver<T>( | 301 | fn iterate_method_candidates_by_receiver<T>( |
305 | receiver_ty: &Canonical<Ty>, | 302 | receiver_ty: &Canonical<Ty>, |
306 | rest_of_deref_chain: &[Canonical<Ty>], | 303 | rest_of_deref_chain: &[Canonical<Ty>], |
307 | db: &impl HirDatabase, | 304 | db: &dyn HirDatabase, |
308 | env: Arc<TraitEnvironment>, | 305 | env: Arc<TraitEnvironment>, |
309 | krate: CrateId, | 306 | krate: CrateId, |
310 | traits_in_scope: &FxHashSet<TraitId>, | 307 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -340,7 +337,7 @@ fn iterate_method_candidates_by_receiver<T>( | |||
340 | 337 | ||
341 | fn iterate_method_candidates_for_self_ty<T>( | 338 | fn iterate_method_candidates_for_self_ty<T>( |
342 | self_ty: &Canonical<Ty>, | 339 | self_ty: &Canonical<Ty>, |
343 | db: &impl HirDatabase, | 340 | db: &dyn HirDatabase, |
344 | env: Arc<TraitEnvironment>, | 341 | env: Arc<TraitEnvironment>, |
345 | krate: CrateId, | 342 | krate: CrateId, |
346 | traits_in_scope: &FxHashSet<TraitId>, | 343 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -367,7 +364,7 @@ fn iterate_method_candidates_for_self_ty<T>( | |||
367 | 364 | ||
368 | fn iterate_trait_method_candidates<T>( | 365 | fn iterate_trait_method_candidates<T>( |
369 | self_ty: &Canonical<Ty>, | 366 | self_ty: &Canonical<Ty>, |
370 | db: &impl HirDatabase, | 367 | db: &dyn HirDatabase, |
371 | env: Arc<TraitEnvironment>, | 368 | env: Arc<TraitEnvironment>, |
372 | krate: CrateId, | 369 | krate: CrateId, |
373 | traits_in_scope: &FxHashSet<TraitId>, | 370 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -381,7 +378,7 @@ fn iterate_trait_method_candidates<T>( | |||
381 | // if we have `T: Trait` in the param env, the trait doesn't need to be in scope | 378 | // if we have `T: Trait` in the param env, the trait doesn't need to be in scope |
382 | env.trait_predicates_for_self_ty(&self_ty.value) | 379 | env.trait_predicates_for_self_ty(&self_ty.value) |
383 | .map(|tr| tr.trait_) | 380 | .map(|tr| tr.trait_) |
384 | .flat_map(|t| all_super_traits(db, t)) | 381 | .flat_map(|t| all_super_traits(db.upcast(), t)) |
385 | .collect() | 382 | .collect() |
386 | } else { | 383 | } else { |
387 | Vec::new() | 384 | Vec::new() |
@@ -416,7 +413,7 @@ fn iterate_trait_method_candidates<T>( | |||
416 | 413 | ||
417 | fn iterate_inherent_methods<T>( | 414 | fn iterate_inherent_methods<T>( |
418 | self_ty: &Canonical<Ty>, | 415 | self_ty: &Canonical<Ty>, |
419 | db: &impl HirDatabase, | 416 | db: &dyn HirDatabase, |
420 | name: Option<&Name>, | 417 | name: Option<&Name>, |
421 | receiver_ty: Option<&Canonical<Ty>>, | 418 | receiver_ty: Option<&Canonical<Ty>>, |
422 | krate: CrateId, | 419 | krate: CrateId, |
@@ -449,7 +446,7 @@ fn iterate_inherent_methods<T>( | |||
449 | 446 | ||
450 | /// Returns the self type for the index trait call. | 447 | /// Returns the self type for the index trait call. |
451 | pub fn resolve_indexing_op( | 448 | pub fn resolve_indexing_op( |
452 | db: &impl HirDatabase, | 449 | db: &dyn HirDatabase, |
453 | ty: &Canonical<Ty>, | 450 | ty: &Canonical<Ty>, |
454 | env: Arc<TraitEnvironment>, | 451 | env: Arc<TraitEnvironment>, |
455 | krate: CrateId, | 452 | krate: CrateId, |
@@ -467,7 +464,7 @@ pub fn resolve_indexing_op( | |||
467 | } | 464 | } |
468 | 465 | ||
469 | fn is_valid_candidate( | 466 | fn is_valid_candidate( |
470 | db: &impl HirDatabase, | 467 | db: &dyn HirDatabase, |
471 | name: Option<&Name>, | 468 | name: Option<&Name>, |
472 | receiver_ty: Option<&Canonical<Ty>>, | 469 | receiver_ty: Option<&Canonical<Ty>>, |
473 | item: AssocItemId, | 470 | item: AssocItemId, |
@@ -504,7 +501,7 @@ fn is_valid_candidate( | |||
504 | } | 501 | } |
505 | 502 | ||
506 | pub(crate) fn inherent_impl_substs( | 503 | pub(crate) fn inherent_impl_substs( |
507 | db: &impl HirDatabase, | 504 | db: &dyn HirDatabase, |
508 | impl_id: ImplId, | 505 | impl_id: ImplId, |
509 | self_ty: &Canonical<Ty>, | 506 | self_ty: &Canonical<Ty>, |
510 | ) -> Option<Substs> { | 507 | ) -> Option<Substs> { |
@@ -544,11 +541,11 @@ fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { | |||
544 | } | 541 | } |
545 | 542 | ||
546 | fn transform_receiver_ty( | 543 | fn transform_receiver_ty( |
547 | db: &impl HirDatabase, | 544 | db: &dyn HirDatabase, |
548 | function_id: FunctionId, | 545 | function_id: FunctionId, |
549 | self_ty: &Canonical<Ty>, | 546 | self_ty: &Canonical<Ty>, |
550 | ) -> Option<Ty> { | 547 | ) -> Option<Ty> { |
551 | let substs = match function_id.lookup(db).container { | 548 | let substs = match function_id.lookup(db.upcast()).container { |
552 | AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) | 549 | AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) |
553 | .push(self_ty.value.clone()) | 550 | .push(self_ty.value.clone()) |
554 | .fill_with_unknown() | 551 | .fill_with_unknown() |
@@ -562,7 +559,7 @@ fn transform_receiver_ty( | |||
562 | 559 | ||
563 | pub fn implements_trait( | 560 | pub fn implements_trait( |
564 | ty: &Canonical<Ty>, | 561 | ty: &Canonical<Ty>, |
565 | db: &impl HirDatabase, | 562 | db: &dyn HirDatabase, |
566 | env: Arc<TraitEnvironment>, | 563 | env: Arc<TraitEnvironment>, |
567 | krate: CrateId, | 564 | krate: CrateId, |
568 | trait_: TraitId, | 565 | trait_: TraitId, |
@@ -581,7 +578,7 @@ pub fn implements_trait( | |||
581 | /// This creates Substs for a trait with the given Self type and type variables | 578 | /// This creates Substs for a trait with the given Self type and type variables |
582 | /// for all other parameters, to query Chalk with it. | 579 | /// for all other parameters, to query Chalk with it. |
583 | fn generic_implements_goal( | 580 | fn generic_implements_goal( |
584 | db: &impl HirDatabase, | 581 | db: &dyn HirDatabase, |
585 | env: Arc<TraitEnvironment>, | 582 | env: Arc<TraitEnvironment>, |
586 | trait_: TraitId, | 583 | trait_: TraitId, |
587 | self_ty: Canonical<Ty>, | 584 | self_ty: Canonical<Ty>, |
@@ -598,7 +595,7 @@ fn generic_implements_goal( | |||
598 | } | 595 | } |
599 | 596 | ||
600 | fn autoderef_method_receiver( | 597 | fn autoderef_method_receiver( |
601 | db: &impl HirDatabase, | 598 | db: &dyn HirDatabase, |
602 | krate: CrateId, | 599 | krate: CrateId, |
603 | ty: InEnvironment<Canonical<Ty>>, | 600 | ty: InEnvironment<Canonical<Ty>>, |
604 | ) -> Vec<Canonical<Ty>> { | 601 | ) -> Vec<Canonical<Ty>> { |