]> git.lizzy.rs Git - rust.git/commitdiff
Show five traits implementation in help when there are exactly five
authorSebastian Waisbrot <seppo0010@gmail.com>
Tue, 14 Feb 2017 04:32:05 +0000 (01:32 -0300)
committerSebastian Waisbrot <seppo0010@gmail.com>
Tue, 14 Feb 2017 15:11:07 +0000 (12:11 -0300)
src/librustc/traits/error_reporting.rs
src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.rs [new file with mode: 0644]
src/test/ui/did_you_mean/issue-39802-show-5-trait-impls.stderr [new file with mode: 0644]

index 024c14ce9d922b1e1cce6acf464b21078a0bbc15..70ca5fe83a93299e3d529113426e60fef2af79b2 100644 (file)
@@ -36,7 +36,6 @@
 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 @@ fn report_similar_impl_candidates(&self,
             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::<String>(),
-                          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 (file)
index 0000000..68b1f79
--- /dev/null
@@ -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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait Foo<B> {
+    fn bar(&self){}
+}
+
+impl Foo<u8> for i8 {}
+impl Foo<u16> for i8 {}
+impl Foo<u32> for i8 {}
+impl Foo<u64> for i8 {}
+impl Foo<bool> for i8 {}
+
+impl Foo<u16> for u8 {}
+impl Foo<u32> for u8 {}
+impl Foo<u64> for u8 {}
+impl Foo<bool> for u8 {}
+
+impl Foo<u8> for bool {}
+impl Foo<u16> for bool {}
+impl Foo<u32> for bool {}
+impl Foo<u64> for bool {}
+impl Foo<bool> for bool {}
+impl Foo<i8> for bool {}
+
+fn main() {
+    Foo::<i32>::bar(&1i8);
+    Foo::<i32>::bar(&1u8);
+    Foo::<i32>::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 (file)
index 0000000..4ea4adf
--- /dev/null
@@ -0,0 +1,43 @@
+error[E0277]: the trait bound `i8: Foo<i32>` is not satisfied
+  --> $DIR/issue-39802-show-5-trait-impls.rs:34:5
+   |
+34 |     Foo::<i32>::bar(&1i8);
+   |     ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `i8`
+   |
+   = help: the following implementations were found:
+             <i8 as Foo<u8>>
+             <i8 as Foo<u16>>
+             <i8 as Foo<u32>>
+             <i8 as Foo<u64>>
+             <i8 as Foo<bool>>
+   = note: required by `Foo::bar`
+
+error[E0277]: the trait bound `u8: Foo<i32>` is not satisfied
+  --> $DIR/issue-39802-show-5-trait-impls.rs:35:5
+   |
+35 |     Foo::<i32>::bar(&1u8);
+   |     ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `u8`
+   |
+   = help: the following implementations were found:
+             <u8 as Foo<u16>>
+             <u8 as Foo<u32>>
+             <u8 as Foo<u64>>
+             <u8 as Foo<bool>>
+   = note: required by `Foo::bar`
+
+error[E0277]: the trait bound `bool: Foo<i32>` is not satisfied
+  --> $DIR/issue-39802-show-5-trait-impls.rs:36:5
+   |
+36 |     Foo::<i32>::bar(&true);
+   |     ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `bool`
+   |
+   = help: the following implementations were found:
+             <bool as Foo<u8>>
+             <bool as Foo<u16>>
+             <bool as Foo<u32>>
+             <bool as Foo<u64>>
+           and 2 others
+   = note: required by `Foo::bar`
+
+error: aborting due to 3 previous errors
+