From b29092ade31d7ff37532649dfbe1dc811edf3651 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 1 Nov 2019 19:56:56 +0100 Subject: Various review fixes --- crates/ra_hir/src/ty.rs | 1 + crates/ra_hir/src/ty/infer/path.rs | 18 +++++++----------- crates/ra_hir/src/ty/method_resolution.rs | 11 +++++------ 3 files changed, 13 insertions(+), 17 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index e39f06e68..d1a9d7411 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -400,6 +400,7 @@ impl SubstsBuilder { pub fn fill(mut self, filler: impl Iterator) -> Self { self.vec.extend(filler.take(self.remaining())); + assert_eq!(self.remaining(), 0); self } diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs index 1946bf608..59b7f7eb6 100644 --- a/crates/ra_hir/src/ty/infer/path.rs +++ b/crates/ra_hir/src/ty/infer/path.rs @@ -196,13 +196,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { AssocItem::Const(c) => ValueNs::Const(c), AssocItem::TypeAlias(_) => unreachable!(), }; - match item.container(self.db) { - Container::ImplBlock(_) => { - let substs = self.find_self_types(&def, ty.clone()); - - self.write_assoc_resolution(id, item); - Some((def, substs)) - } + let substs = match item.container(self.db) { + Container::ImplBlock(_) => self.find_self_types(&def, ty.clone()), Container::Trait(t) => { // we're picking this method let trait_substs = Substs::build_for_def(self.db, t) @@ -217,11 +212,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { trait_: t, substs: trait_substs, })); - - self.write_assoc_resolution(id, item); - Some((def, Some(substs))) + Some(substs) } - } + }; + + 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 8d682bb18..8c3d32d09 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -166,12 +166,10 @@ pub(crate) fn lookup_method( name: &Name, resolver: &Resolver, ) -> Option<(Ty, Function)> { - iterate_method_candidates(ty, db, resolver, Some(name), LookupMode::MethodCall, |ty, f| { - if let AssocItem::Function(f) = f { - Some((ty.clone(), f)) - } else { - None - } + iterate_method_candidates(ty, db, resolver, Some(name), LookupMode::MethodCall, |ty, f| match f + { + AssocItem::Function(f) => Some((ty.clone(), f)), + _ => None, }) } @@ -189,6 +187,7 @@ pub enum LookupMode { // This would be nicer if it just returned an iterator, but that runs into // lifetime problems, because we need to borrow temp `CrateImplBlocks`. +// FIXME add a context type here? pub(crate) fn iterate_method_candidates( ty: &Canonical, db: &impl HirDatabase, -- cgit v1.2.3