about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-12-09 09:54:19 -0500
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2016-12-20 11:37:15 +0100
commit5d41be3629067ddfd16fc672e75c2fcaf95c27ff (patch)
tree8c4d5c5c17c2d44408dfadc238fe4f3a0568a35d /src
parent25a2d13cdea6011046a9929824deafd332b94436 (diff)
downloadrust-5d41be3629067ddfd16fc672e75c2fcaf95c27ff.tar.gz
rust-5d41be3629067ddfd16fc672e75c2fcaf95c27ff.zip
don't special case having 1 item
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/method/probe.rs93
1 files changed, 22 insertions, 71 deletions
diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs
index b11f6e837d2..e478638a5e0 100644
--- a/src/librustc_typeck/check/method/probe.rs
+++ b/src/librustc_typeck/check/method/probe.rs
@@ -484,22 +484,16 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
 
         debug!("assemble_inherent_impl_probe {:?}", impl_def_id);
 
-        let items = self.impl_or_trait_item(impl_def_id);
-        if items.len() < 1 {
-            return // No method with correct name on this impl
-        }
-
-        if self.looking_for.is_method_name() {
-            let item = items[0];
-
+        for item in self.impl_or_trait_item(impl_def_id) {
             if !self.has_applicable_self(&item) {
                 // No receiver declared. Not a candidate.
-                return self.record_static_candidate(ImplSource(impl_def_id));
+                self.record_static_candidate(ImplSource(impl_def_id));
+                continue
             }
 
             if !item.vis.is_accessible_from(self.body_id, &self.tcx.map) {
                 self.private_candidate = Some(item.def());
-                return;
+                continue
             }
 
             let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
@@ -523,41 +517,6 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
                 kind: InherentImplCandidate(impl_substs, obligations),
                 import_id: self.import_id,
             });
-        } else {
-            for item in items {
-                if !self.has_applicable_self(&item) {
-                    // No receiver declared. Not a candidate.
-                    self.record_static_candidate(ImplSource(impl_def_id));
-                    continue
-                }
-
-                if !item.vis.is_accessible_from(self.body_id, &self.tcx.map) {
-                    self.private_candidate = Some(item.def());
-                    continue
-                }
-
-                let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
-                let impl_ty = impl_ty.subst(self.tcx, impl_substs);
-
-                // Determine the receiver type that the method itself expects.
-                let xform_self_ty = self.xform_self_ty(&item, impl_ty, impl_substs);
-
-                // We can't use normalize_associated_types_in as it will pollute the
-                // fcx's fulfillment context after this probe is over.
-                let cause = traits::ObligationCause::misc(self.span, self.body_id);
-                let mut selcx = &mut traits::SelectionContext::new(self.fcx);
-                let traits::Normalized { value: xform_self_ty, obligations } =
-                    traits::normalize(selcx, cause, &xform_self_ty);
-                debug!("assemble_inherent_impl_probe: xform_self_ty = {:?}",
-                       xform_self_ty);
-
-                self.inherent_candidates.push(Candidate {
-                    xform_self_ty: xform_self_ty,
-                    item: item,
-                    kind: InherentImplCandidate(impl_substs, obligations),
-                    import_id: self.import_id,
-                });
-            }
         }
     }
 
@@ -651,16 +610,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
 
         let tcx = self.tcx;
         for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
-            let items = self.impl_or_trait_item(bound_trait_ref.def_id());
-            if items.len() < 1 {
-                continue
-            }
-            let item = items[0];
-
-            if !self.has_applicable_self(&item) {
-                self.record_static_candidate(TraitSource(bound_trait_ref.def_id()));
-            } else {
-                mk_cand(self, bound_trait_ref, item);
+            for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
+                if !self.has_applicable_self(&item) {
+                    self.record_static_candidate(TraitSource(bound_trait_ref.def_id()));
+                } else {
+                    mk_cand(self, bound_trait_ref, item);
+                }
             }
         }
     }
@@ -717,26 +672,22 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
         debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})",
                trait_def_id);
 
-        let items = self.impl_or_trait_item(trait_def_id);
-        if items.len() < 1 {
-            return Ok(());
-        }
-        let item = items[0];
-
-        // Check whether `trait_def_id` defines a method with suitable name:
-        if !self.has_applicable_self(&item) {
-            debug!("method has inapplicable self");
-            self.record_static_candidate(TraitSource(trait_def_id));
-            return Ok(());
-        }
+        for item in self.impl_or_trait_item(trait_def_id) {
+            // Check whether `trait_def_id` defines a method with suitable name:
+            if !self.has_applicable_self(&item) {
+                debug!("method has inapplicable self");
+                self.record_static_candidate(TraitSource(trait_def_id));
+                continue;
+            }
 
-        self.assemble_extension_candidates_for_trait_impls(trait_def_id, item.clone());
+            self.assemble_extension_candidates_for_trait_impls(trait_def_id, item.clone());
 
-        self.assemble_closure_candidates(trait_def_id, item.clone())?;
+            self.assemble_closure_candidates(trait_def_id, item.clone())?;
 
-        self.assemble_projection_candidates(trait_def_id, item.clone());
+            self.assemble_projection_candidates(trait_def_id, item.clone());
 
-        self.assemble_where_clause_candidates(trait_def_id, item.clone());
+            self.assemble_where_clause_candidates(trait_def_id, item.clone());
+        }
 
         Ok(())
     }