Skip to content

Commit a4eec2f

Browse files
authored
Rollup merge of rust-lang#39804 - seppo0010:recommend-five-traits, r=jonathandturner
Show five traits implementation in help when there are exactly five Fixes rust-lang#39802
2 parents a6bd2a9 + ca54fc7 commit a4eec2f

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

src/librustc/traits/error_reporting.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use ty::fold::TypeFolder;
3636
use ty::subst::Subst;
3737
use util::nodemap::{FxHashMap, FxHashSet};
3838

39-
use std::cmp;
4039
use std::fmt;
4140
use syntax::ast;
4241
use hir::{intravisit, Local, Pat};
@@ -392,12 +391,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
392391
return;
393392
}
394393

395-
let end = cmp::min(4, impl_candidates.len());
394+
let end = if impl_candidates.len() <= 5 {
395+
impl_candidates.len()
396+
} else {
397+
4
398+
};
396399
err.help(&format!("the following implementations were found:{}{}",
397400
&impl_candidates[0..end].iter().map(|candidate| {
398401
format!("\n {:?}", candidate)
399402
}).collect::<String>(),
400-
if impl_candidates.len() > 4 {
403+
if impl_candidates.len() > 5 {
401404
format!("\nand {} others", impl_candidates.len() - 4)
402405
} else {
403406
"".to_owned()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo<B> {
12+
fn bar(&self){}
13+
}
14+
15+
impl Foo<u8> for i8 {}
16+
impl Foo<u16> for i8 {}
17+
impl Foo<u32> for i8 {}
18+
impl Foo<u64> for i8 {}
19+
impl Foo<bool> for i8 {}
20+
21+
impl Foo<u16> for u8 {}
22+
impl Foo<u32> for u8 {}
23+
impl Foo<u64> for u8 {}
24+
impl Foo<bool> for u8 {}
25+
26+
impl Foo<u8> for bool {}
27+
impl Foo<u16> for bool {}
28+
impl Foo<u32> for bool {}
29+
impl Foo<u64> for bool {}
30+
impl Foo<bool> for bool {}
31+
impl Foo<i8> for bool {}
32+
33+
fn main() {
34+
Foo::<i32>::bar(&1i8);
35+
Foo::<i32>::bar(&1u8);
36+
Foo::<i32>::bar(&true);
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0277]: the trait bound `i8: Foo<i32>` is not satisfied
2+
--> $DIR/issue-39802-show-5-trait-impls.rs:34:5
3+
|
4+
34 | Foo::<i32>::bar(&1i8);
5+
| ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `i8`
6+
|
7+
= help: the following implementations were found:
8+
<i8 as Foo<u8>>
9+
<i8 as Foo<u16>>
10+
<i8 as Foo<u32>>
11+
<i8 as Foo<u64>>
12+
<i8 as Foo<bool>>
13+
= note: required by `Foo::bar`
14+
15+
error[E0277]: the trait bound `u8: Foo<i32>` is not satisfied
16+
--> $DIR/issue-39802-show-5-trait-impls.rs:35:5
17+
|
18+
35 | Foo::<i32>::bar(&1u8);
19+
| ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `u8`
20+
|
21+
= help: the following implementations were found:
22+
<u8 as Foo<u16>>
23+
<u8 as Foo<u32>>
24+
<u8 as Foo<u64>>
25+
<u8 as Foo<bool>>
26+
= note: required by `Foo::bar`
27+
28+
error[E0277]: the trait bound `bool: Foo<i32>` is not satisfied
29+
--> $DIR/issue-39802-show-5-trait-impls.rs:36:5
30+
|
31+
36 | Foo::<i32>::bar(&true);
32+
| ^^^^^^^^^^^^^^^ the trait `Foo<i32>` is not implemented for `bool`
33+
|
34+
= help: the following implementations were found:
35+
<bool as Foo<u8>>
36+
<bool as Foo<u16>>
37+
<bool as Foo<u32>>
38+
<bool as Foo<u64>>
39+
and 2 others
40+
= note: required by `Foo::bar`
41+
42+
error: aborting due to 3 previous errors
43+

0 commit comments

Comments
 (0)