From a040fde3ae5e339199237f24a7461812e74475bf Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 16 Sep 2019 22:01:13 +0200 Subject: Remove TraitItem and ImplItem in favor of AssocItem --- crates/ra_hir/src/ty/infer.rs | 26 ++++++++++++-------------- crates/ra_hir/src/ty/method_resolution.rs | 11 +++++------ crates/ra_hir/src/ty/traits/chalk.rs | 6 +++--- 3 files changed, 20 insertions(+), 23 deletions(-) (limited to 'crates/ra_hir/src/ty') 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> { // Find impl // FIXME: consider trait candidates - let def = ty.clone().iterate_impl_items(self.db, krate, |item| match item { - crate::ImplItem::Method(func) => { + let item = ty.clone().iterate_impl_items(self.db, krate, |item| match item { + AssocItem::Function(func) => { if segment.name == func.name(self.db) { - Some(ValueNs::Function(func)) + Some(AssocItem::Function(func)) } else { None } } - crate::ImplItem::Const(konst) => { + AssocItem::Const(konst) => { if konst.name(self.db).map_or(false, |n| n == segment.name) { - Some(ValueNs::Const(konst)) + Some(AssocItem::Const(konst)) } else { None } } - crate::ImplItem::TypeAlias(_) => None, + AssocItem::TypeAlias(_) => None, })?; + let def = match item { + AssocItem::Function(f) => ValueNs::Function(f), + AssocItem::Const(c) => ValueNs::Const(c), + AssocItem::TypeAlias(_) => unreachable!(), + }; let substs = self.find_self_types(&def, ty); - self.write_assoc_resolution( - id, - match def { - ValueNs::Function(f) => AssocItem::Function(f), - ValueNs::Const(c) => AssocItem::Const(c), - _ => unreachable!(), - }, - ); + self.write_assoc_resolution(id, item); Some((def, substs)) } 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 use crate::{ db::HirDatabase, generics::HasGenericParams, - impl_block::{ImplBlock, ImplId, ImplItem}, + impl_block::{ImplBlock, ImplId}, nameres::CrateModuleId, resolve::Resolver, - traits::TraitItem, ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, ty::{Ty, TypeCtor}, - Crate, Function, Module, Name, Trait, + AssocItem, Crate, Function, Module, Name, Trait, }; /// This is used as a key for indexing impls. @@ -232,7 +231,7 @@ fn iterate_trait_method_candidates( // iteration let mut known_implemented = inherently_implemented; for item in data.items() { - if let TraitItem::Function(m) = *item { + if let AssocItem::Function(m) = *item { let data = m.data(db); if name.map_or(true, |name| data.name() == name) && data.has_self_param() { if !known_implemented { @@ -264,7 +263,7 @@ fn iterate_inherent_methods( for impl_block in impls.lookup_impl_blocks(&ty.value) { for item in impl_block.items(db) { - if let ImplItem::Method(f) = item { + if let AssocItem::Function(f) = item { let data = f.data(db); if name.map_or(true, |name| data.name() == name) && data.has_self_param() { if let Some(result) = callback(&ty.value, f) { @@ -304,7 +303,7 @@ impl Ty { self, db: &impl HirDatabase, krate: Crate, - mut callback: impl FnMut(ImplItem) -> Option, + mut callback: impl FnMut(AssocItem) -> Option, ) -> Option { for krate in def_crates(db, krate, &self)? { 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::{ ApplicationTy, CallableDef, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, }, - Crate, HasGenericParams, ImplBlock, ImplItem, Trait, TypeAlias, + AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias, }; /// This represents a trait whose name we could not resolve. @@ -496,7 +496,7 @@ pub(crate) fn trait_datum_query( .items(db) .into_iter() .filter_map(|trait_item| match trait_item { - crate::traits::TraitItem::TypeAlias(type_alias) => Some(type_alias), + crate::AssocItem::TypeAlias(type_alias) => Some(type_alias), _ => None, }) .map(|type_alias| type_alias.to_chalk(db)) @@ -616,7 +616,7 @@ pub(crate) fn impl_datum_query( .items(db) .into_iter() .filter_map(|item| match item { - ImplItem::TypeAlias(t) => Some(t), + AssocItem::TypeAlias(t) => Some(t), _ => None, }) .filter_map(|t| { -- cgit v1.2.3