aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-09-16 21:01:13 +0100
committerFlorian Diebold <[email protected]>2019-09-17 18:47:45 +0100
commita040fde3ae5e339199237f24a7461812e74475bf (patch)
tree007e93e160cd6f0c5e62a4ed4ac72e8f6f8bf76b /crates/ra_hir/src/ty
parent53a932509dbb9dfdaabb27a0d7fc3fe87e44ec55 (diff)
Remove TraitItem and ImplItem in favor of AssocItem
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs26
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs11
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs6
3 files changed, 20 insertions, 23 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 181be0fcc..70da7f311 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -576,34 +576,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
576 576
577 // Find impl 577 // Find impl
578 // FIXME: consider trait candidates 578 // FIXME: consider trait candidates
579 let def = ty.clone().iterate_impl_items(self.db, krate, |item| match item { 579 let item = ty.clone().iterate_impl_items(self.db, krate, |item| match item {
580 crate::ImplItem::Method(func) => { 580 AssocItem::Function(func) => {
581 if segment.name == func.name(self.db) { 581 if segment.name == func.name(self.db) {
582 Some(ValueNs::Function(func)) 582 Some(AssocItem::Function(func))
583 } else { 583 } else {
584 None 584 None
585 } 585 }
586 } 586 }
587 587
588 crate::ImplItem::Const(konst) => { 588 AssocItem::Const(konst) => {
589 if konst.name(self.db).map_or(false, |n| n == segment.name) { 589 if konst.name(self.db).map_or(false, |n| n == segment.name) {
590 Some(ValueNs::Const(konst)) 590 Some(AssocItem::Const(konst))
591 } else { 591 } else {
592 None 592 None
593 } 593 }
594 } 594 }
595 crate::ImplItem::TypeAlias(_) => None, 595 AssocItem::TypeAlias(_) => None,
596 })?; 596 })?;
597 let def = match item {
598 AssocItem::Function(f) => ValueNs::Function(f),
599 AssocItem::Const(c) => ValueNs::Const(c),
600 AssocItem::TypeAlias(_) => unreachable!(),
601 };
597 let substs = self.find_self_types(&def, ty); 602 let substs = self.find_self_types(&def, ty);
598 603
599 self.write_assoc_resolution( 604 self.write_assoc_resolution(id, item);
600 id,
601 match def {
602 ValueNs::Function(f) => AssocItem::Function(f),
603 ValueNs::Const(c) => AssocItem::Const(c),
604 _ => unreachable!(),
605 },
606 );
607 Some((def, substs)) 605 Some((def, substs))
608 } 606 }
609 607
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index be63806d4..8b46b11a9 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -11,13 +11,12 @@ use super::{autoderef, lower, Canonical, InEnvironment, TraitEnvironment, TraitR
11use crate::{ 11use crate::{
12 db::HirDatabase, 12 db::HirDatabase,
13 generics::HasGenericParams, 13 generics::HasGenericParams,
14 impl_block::{ImplBlock, ImplId, ImplItem}, 14 impl_block::{ImplBlock, ImplId},
15 nameres::CrateModuleId, 15 nameres::CrateModuleId,
16 resolve::Resolver, 16 resolve::Resolver,
17 traits::TraitItem,
18 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, 17 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy},
19 ty::{Ty, TypeCtor}, 18 ty::{Ty, TypeCtor},
20 Crate, Function, Module, Name, Trait, 19 AssocItem, Crate, Function, Module, Name, Trait,
21}; 20};
22 21
23/// This is used as a key for indexing impls. 22/// This is used as a key for indexing impls.
@@ -232,7 +231,7 @@ fn iterate_trait_method_candidates<T>(
232 // iteration 231 // iteration
233 let mut known_implemented = inherently_implemented; 232 let mut known_implemented = inherently_implemented;
234 for item in data.items() { 233 for item in data.items() {
235 if let TraitItem::Function(m) = *item { 234 if let AssocItem::Function(m) = *item {
236 let data = m.data(db); 235 let data = m.data(db);
237 if name.map_or(true, |name| data.name() == name) && data.has_self_param() { 236 if name.map_or(true, |name| data.name() == name) && data.has_self_param() {
238 if !known_implemented { 237 if !known_implemented {
@@ -264,7 +263,7 @@ fn iterate_inherent_methods<T>(
264 263
265 for impl_block in impls.lookup_impl_blocks(&ty.value) { 264 for impl_block in impls.lookup_impl_blocks(&ty.value) {
266 for item in impl_block.items(db) { 265 for item in impl_block.items(db) {
267 if let ImplItem::Method(f) = item { 266 if let AssocItem::Function(f) = item {
268 let data = f.data(db); 267 let data = f.data(db);
269 if name.map_or(true, |name| data.name() == name) && data.has_self_param() { 268 if name.map_or(true, |name| data.name() == name) && data.has_self_param() {
270 if let Some(result) = callback(&ty.value, f) { 269 if let Some(result) = callback(&ty.value, f) {
@@ -304,7 +303,7 @@ impl Ty {
304 self, 303 self,
305 db: &impl HirDatabase, 304 db: &impl HirDatabase,
306 krate: Crate, 305 krate: Crate,
307 mut callback: impl FnMut(ImplItem) -> Option<T>, 306 mut callback: impl FnMut(AssocItem) -> Option<T>,
308 ) -> Option<T> { 307 ) -> Option<T> {
309 for krate in def_crates(db, krate, &self)? { 308 for krate in def_crates(db, krate, &self)? {
310 let impls = db.impls_in_crate(krate); 309 let impls = db.impls_in_crate(krate);
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index c748e9d84..693d9b28f 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -21,7 +21,7 @@ use crate::{
21 ApplicationTy, CallableDef, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, 21 ApplicationTy, CallableDef, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
22 TypeWalk, 22 TypeWalk,
23 }, 23 },
24 Crate, HasGenericParams, ImplBlock, ImplItem, Trait, TypeAlias, 24 AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias,
25}; 25};
26 26
27/// This represents a trait whose name we could not resolve. 27/// This represents a trait whose name we could not resolve.
@@ -496,7 +496,7 @@ pub(crate) fn trait_datum_query(
496 .items(db) 496 .items(db)
497 .into_iter() 497 .into_iter()
498 .filter_map(|trait_item| match trait_item { 498 .filter_map(|trait_item| match trait_item {
499 crate::traits::TraitItem::TypeAlias(type_alias) => Some(type_alias), 499 crate::AssocItem::TypeAlias(type_alias) => Some(type_alias),
500 _ => None, 500 _ => None,
501 }) 501 })
502 .map(|type_alias| type_alias.to_chalk(db)) 502 .map(|type_alias| type_alias.to_chalk(db))
@@ -616,7 +616,7 @@ pub(crate) fn impl_datum_query(
616 .items(db) 616 .items(db)
617 .into_iter() 617 .into_iter()
618 .filter_map(|item| match item { 618 .filter_map(|item| match item {
619 ImplItem::TypeAlias(t) => Some(t), 619 AssocItem::TypeAlias(t) => Some(t),
620 _ => None, 620 _ => None,
621 }) 621 })
622 .filter_map(|t| { 622 .filter_map(|t| {