diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index e39f06e687..d1a9d74111 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 1946bf6084..59b7f7eb64 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 8d682bb180..8c3d32d09d 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,