Skip to content

Commit 6ab93d7

Browse files
committedMay 12, 2016
typeck: limit number of candidates shown for a single error
Limit of 4 taken consistent with limit for "similar impl candidates" in rustc::traits::error_reporting. Fixes: #25356
1 parent 22ac88f commit 6ab93d7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed
 

‎src/librustc_typeck/check/method/suggest.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
101101

102102
sources.sort();
103103
sources.dedup();
104+
// Dynamic limit to avoid hiding just one candidate, which is silly.
105+
let limit = if sources.len() == 5 { 5 } else { 4 };
104106

105-
for (idx, source) in sources.iter().enumerate() {
107+
for (idx, source) in sources.iter().take(limit).enumerate() {
106108
match *source {
107109
CandidateSource::ImplSource(impl_did) => {
108110
// 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> {
151153
}
152154
}
153155
}
156+
if sources.len() > limit {
157+
err.note(&format!("and {} others", sources.len() - limit));
158+
}
154159
};
155160

156161
match error {
@@ -295,11 +300,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
295300

296301
err.help(&msg[..]);
297302

298-
for (i, trait_did) in candidates.iter().enumerate() {
303+
let limit = if candidates.len() == 5 { 5 } else { 4 };
304+
for (i, trait_did) in candidates.iter().take(limit).enumerate() {
299305
err.help(&format!("candidate #{}: `use {}`",
300306
i + 1,
301307
self.tcx.item_path_str(*trait_did)));
302308
}
309+
if candidates.len() > limit {
310+
err.note(&format!("and {} others", candidates.len() - limit));
311+
}
303312
return
304313
}
305314

0 commit comments

Comments
 (0)
Please sign in to comment.