about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-05-12 04:01:55 -0700
committerbors <bors@rust-lang.org>2016-05-12 04:01:55 -0700
commite88defe71806ad190588e168e513bc1098f7c9fb (patch)
treea17438bee0f1f5315699e4447d03af13f3d04543
parent992bb1332ffc68093a6aa555807b9129a1e94977 (diff)
parent6ab93d7430d75941373ad48fc681bb8337a31465 (diff)
downloadrust-e88defe71806ad190588e168e513bc1098f7c9fb.tar.gz
rust-e88defe71806ad190588e168e513bc1098f7c9fb.zip
Auto merge of #33338 - birkenfeld:issue-25356, r=jseyfried
typeck: limit number of candidates shown for a single error

No idea if 10/11 is a good limit. Are there any other such limits in rustc currently?

Fixes: #25356
-rw-r--r--src/librustc_typeck/check/method/suggest.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index 540af8b04bf..be329ec11af 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -101,8 +101,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
 
             sources.sort();
             sources.dedup();
+            // Dynamic limit to avoid hiding just one candidate, which is silly.
+            let limit = if sources.len() == 5 { 5 } else { 4 };
 
-            for (idx, source) in sources.iter().enumerate() {
+            for (idx, source) in sources.iter().take(limit).enumerate() {
                 match *source {
                     CandidateSource::ImplSource(impl_did) => {
                         // Provide the best span we can. Use the item, if local to crate, else
@@ -151,6 +153,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                     }
                 }
             }
+            if sources.len() > limit {
+                err.note(&format!("and {} others", sources.len() - limit));
+            }
         };
 
         match error {
@@ -295,11 +300,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
 
             err.help(&msg[..]);
 
-            for (i, trait_did) in candidates.iter().enumerate() {
+            let limit = if candidates.len() == 5 { 5 } else { 4 };
+            for (i, trait_did) in candidates.iter().take(limit).enumerate() {
                 err.help(&format!("candidate #{}: `use {}`",
                                   i + 1,
                                   self.tcx.item_path_str(*trait_did)));
             }
+            if candidates.len() > limit {
+                err.note(&format!("and {} others", candidates.len() - limit));
+            }
             return
         }