Use multiline Diagnostic for "relevant impl" list

Provide the following output:

```
error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
  --> $DIR/issue-21659-show-relevant-trait-impls-2.rs:38:8
   |
38 |     f1.foo(1usize);
   |        ^^^ the trait `Foo<usize>` is not implemented for `Bar`
   |
   = help: the following implementations were found:
             <Bar as Foo<i8>>
             <Bar as Foo<i16>>
             <Bar as Foo<i32>>
             <Bar as Foo<u8>>
           and 2 others

error: aborting due to previous error
```

instead of

```
error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
  --> $DIR/issue-21659-show-relevant-trait-impls-2.rs:38:8
   |
38 |     f1.foo(1usize);
   |        ^^^ the trait `Foo<usize>` is not implemented for `Bar`
   |
   = help: the following implementations were found:
   = help:   <Bar as Foo<i8>>
   = help:   <Bar as Foo<i16>>
   = help:   <Bar as Foo<i32>>
   = help:   <Bar as Foo<u8>>
   = help: and 2 others

error: aborting due to previous error
```
This commit is contained in:
Esteban Küber 2017-01-13 11:40:44 -08:00
parent 27b9e6d450
commit d04c027e93
6 changed files with 41 additions and 12 deletions

View File

@ -366,15 +366,17 @@ fn report_similar_impl_candidates(&self,
return;
}
err.help(&format!("the following implementations were found:"));
let end = cmp::min(4, impl_candidates.len());
for candidate in &impl_candidates[0..end] {
err.help(&format!(" {:?}", candidate));
}
if impl_candidates.len() > 4 {
err.help(&format!("and {} others", impl_candidates.len()-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 {
format!("\nand {} others", impl_candidates.len() - 4)
} else {
"".to_owned()
}
));
}
/// Reports that an overflow has occurred and halts compilation. We

View File

@ -0,0 +1,12 @@
error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
--> $DIR/issue-21659-show-relevant-trait-impls-1.rs:34:8
|
34 | f1.foo(1usize);
| ^^^ the trait `Foo<usize>` is not implemented for `Bar`
|
= help: the following implementations were found:
<Bar as Foo<i32>>
<Bar as Foo<u8>>
error: aborting due to previous error

View File

@ -0,0 +1,15 @@
error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
--> $DIR/issue-21659-show-relevant-trait-impls-2.rs:38:8
|
38 | f1.foo(1usize);
| ^^^ the trait `Foo<usize>` is not implemented for `Bar`
|
= help: the following implementations were found:
<Bar as Foo<i8>>
<Bar as Foo<i16>>
<Bar as Foo<i32>>
<Bar as Foo<u8>>
and 2 others
error: aborting due to previous error

View File

@ -10,10 +10,10 @@ error[E0277]: the trait bound `u32: std::ops::Add<()>` is not satisfied
| |______________^ ...ending here: the trait `std::ops::Add<()>` is not implemented for `u32`
|
= help: the following implementations were found:
= help: <u32 as std::ops::Add>
= help: <&'a u32 as std::ops::Add<u32>>
= help: <u32 as std::ops::Add<&'a u32>>
= help: <&'b u32 as std::ops::Add<&'a u32>>
<u32 as std::ops::Add>
<&'a u32 as std::ops::Add<u32>>
<u32 as std::ops::Add<&'a u32>>
<&'b u32 as std::ops::Add<&'a u32>>
error: aborting due to previous error