Skip to content

Commit 4f0508a

Browse files
committed
Auto merge of #39040 - estebank:relevant-impl-multiline, r=nikomatsakis
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 ```
2 parents bf6d7b6 + d04c027 commit 4f0508a

6 files changed

+41
-12
lines changed

src/librustc/traits/error_reporting.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
366366
return;
367367
}
368368

369-
err.help(&format!("the following implementations were found:"));
370-
371369
let end = cmp::min(4, impl_candidates.len());
372-
for candidate in &impl_candidates[0..end] {
373-
err.help(&format!(" {:?}", candidate));
374-
}
375-
if impl_candidates.len() > 4 {
376-
err.help(&format!("and {} others", impl_candidates.len()-4));
377-
}
370+
err.help(&format!("the following implementations were found:{}{}",
371+
&impl_candidates[0..end].iter().map(|candidate| {
372+
format!("\n {:?}", candidate)
373+
}).collect::<String>(),
374+
if impl_candidates.len() > 4 {
375+
format!("\nand {} others", impl_candidates.len() - 4)
376+
} else {
377+
"".to_owned()
378+
}
379+
));
378380
}
379381

380382
/// Reports that an overflow has occurred and halts compilation. We
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
2+
--> $DIR/issue-21659-show-relevant-trait-impls-1.rs:34:8
3+
|
4+
34 | f1.foo(1usize);
5+
| ^^^ the trait `Foo<usize>` is not implemented for `Bar`
6+
|
7+
= help: the following implementations were found:
8+
<Bar as Foo<i32>>
9+
<Bar as Foo<u8>>
10+
11+
error: aborting due to previous error
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `Bar: Foo<usize>` is not satisfied
2+
--> $DIR/issue-21659-show-relevant-trait-impls-2.rs:38:8
3+
|
4+
38 | f1.foo(1usize);
5+
| ^^^ the trait `Foo<usize>` is not implemented for `Bar`
6+
|
7+
= help: the following implementations were found:
8+
<Bar as Foo<i8>>
9+
<Bar as Foo<i16>>
10+
<Bar as Foo<i32>>
11+
<Bar as Foo<u8>>
12+
and 2 others
13+
14+
error: aborting due to previous error
15+

src/test/ui/span/multiline-span-simple.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ error[E0277]: the trait bound `u32: std::ops::Add<()>` is not satisfied
1010
| |______________^ ...ending here: the trait `std::ops::Add<()>` is not implemented for `u32`
1111
|
1212
= help: the following implementations were found:
13-
= help: <u32 as std::ops::Add>
14-
= help: <&'a u32 as std::ops::Add<u32>>
15-
= help: <u32 as std::ops::Add<&'a u32>>
16-
= help: <&'b u32 as std::ops::Add<&'a u32>>
13+
<u32 as std::ops::Add>
14+
<&'a u32 as std::ops::Add<u32>>
15+
<u32 as std::ops::Add<&'a u32>>
16+
<&'b u32 as std::ops::Add<&'a u32>>
1717

1818
error: aborting due to previous error
1919

0 commit comments

Comments
 (0)