diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 024c14ce9d9..70ca5fe83a9 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -36,7 +36,6 @@ use ty::fold::TypeFolder; use ty::subst::Subst; use util::nodemap::{FxHashMap, FxHashSet}; -use std::cmp; use std::fmt; use syntax::ast; use hir::{intravisit, Local, Pat}; @@ -392,12 +391,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { return; } - let end = cmp::min(4, impl_candidates.len()); + let end = if impl_candidates.len() <= 5 { + impl_candidates.len() + } else { + 4 + }; err.help(&format!("the following implementations were found:{}{}", &impl_candidates[0..end].iter().map(|candidate| { format!("\n {:?}", candidate) }).collect::(), - if impl_candidates.len() > 4 { + if impl_candidates.len() > 5 { format!("\nand {} others", impl_candidates.len() - 4) } else { "".to_owned() diff --git a/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs new file mode 100644 index 00000000000..68b1f79c89b --- /dev/null +++ b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs @@ -0,0 +1,37 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + fn bar(&self){} +} + +impl Foo for i8 {} +impl Foo for i8 {} +impl Foo for i8 {} +impl Foo for i8 {} +impl Foo for i8 {} + +impl Foo for u8 {} +impl Foo for u8 {} +impl Foo for u8 {} +impl Foo for u8 {} + +impl Foo for bool {} +impl Foo for bool {} +impl Foo for bool {} +impl Foo for bool {} +impl Foo for bool {} +impl Foo for bool {} + +fn main() { + Foo::::bar(&1i8); + Foo::::bar(&1u8); + Foo::::bar(&true); +} diff --git a/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr new file mode 100644 index 00000000000..4ea4adfcfe0 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr @@ -0,0 +1,43 @@ +error[E0277]: the trait bound `i8: Foo` is not satisfied + --> $DIR/issue-39802-show-5-trait-impls.rs:34:5 + | +34 | Foo::::bar(&1i8); + | ^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i8` + | + = help: the following implementations were found: + > + > + > + > + > + = note: required by `Foo::bar` + +error[E0277]: the trait bound `u8: Foo` is not satisfied + --> $DIR/issue-39802-show-5-trait-impls.rs:35:5 + | +35 | Foo::::bar(&1u8); + | ^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `u8` + | + = help: the following implementations were found: + > + > + > + > + = note: required by `Foo::bar` + +error[E0277]: the trait bound `bool: Foo` is not satisfied + --> $DIR/issue-39802-show-5-trait-impls.rs:36:5 + | +36 | Foo::::bar(&true); + | ^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `bool` + | + = help: the following implementations were found: + > + > + > + > + and 2 others + = note: required by `Foo::bar` + +error: aborting due to 3 previous errors +