mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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
This commit is contained in:
parent
22ac88f1a4
commit
6ab93d7430
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user