Skip to content

Commit 286f7ae

Browse files
committed
Join multiple E0191 errors in the same location under a single diagnostic
1 parent abdcb86 commit 286f7ae

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,18 +1029,31 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
10291029
associated_types.remove(&projection_bound.projection_def_id());
10301030
}
10311031

1032-
for item_def_id in associated_types {
1033-
let assoc_item = tcx.associated_item(item_def_id);
1034-
let trait_def_id = assoc_item.container.id();
1032+
if !associated_types.is_empty() {
1033+
let names = associated_types.iter().map(|item_def_id| {
1034+
let assoc_item = tcx.associated_item(*item_def_id);
1035+
let trait_def_id = assoc_item.container.id();
1036+
format!(
1037+
"`{}` (from the trait `{}`)",
1038+
assoc_item.ident,
1039+
tcx.item_path_str(trait_def_id),
1040+
)
1041+
}).collect::<Vec<_>>().join(", ");
10351042
let mut err = struct_span_err!(
10361043
tcx.sess,
10371044
span,
10381045
E0191,
1039-
"the value of the associated type `{}` (from the trait `{}`) must be specified",
1040-
assoc_item.ident,
1041-
tcx.item_path_str(trait_def_id),
1046+
"the value of the associated type{} {} must be specified",
1047+
if associated_types.len() == 1 { "" } else { "s" },
1048+
names,
10421049
);
1043-
err.span_label(span, format!("missing associated type `{}` value", assoc_item.ident));
1050+
for item_def_id in associated_types {
1051+
let assoc_item = tcx.associated_item(item_def_id);
1052+
err.span_label(
1053+
span,
1054+
format!("missing associated type `{}` value", assoc_item.ident),
1055+
);
1056+
}
10441057
err.emit();
10451058
}
10461059

src/test/ui/associated-types/associated-types-incomplete-object.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,5 @@ pub fn main() {
3737
//~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified
3838

3939
let d = &42isize as &Foo;
40-
//~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified
41-
//~| ERROR the value of the associated type `B` (from the trait `Foo`) must be specified
40+
//~^ ERROR the value of the associated types `A` (from the trait `Foo`), `B` (from the trait
4241
}

src/test/ui/associated-types/associated-types-incomplete-object.stderr

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ error[E0191]: the value of the associated type `A` (from the trait `Foo`) must b
1010
LL | let c = &42isize as &Foo<B=char>;
1111
| ^^^^^^^^^^^ missing associated type `A` value
1212

13-
error[E0191]: the value of the associated type `A` (from the trait `Foo`) must be specified
14-
--> $DIR/associated-types-incomplete-object.rs:39:26
15-
|
16-
LL | let d = &42isize as &Foo;
17-
| ^^^ missing associated type `A` value
18-
19-
error[E0191]: the value of the associated type `B` (from the trait `Foo`) must be specified
13+
error[E0191]: the value of the associated types `A` (from the trait `Foo`), `B` (from the trait `Foo`) must be specified
2014
--> $DIR/associated-types-incomplete-object.rs:39:26
2115
|
2216
LL | let d = &42isize as &Foo;
23-
| ^^^ missing associated type `B` value
17+
| ^^^
18+
| |
19+
| missing associated type `A` value
20+
| missing associated type `B` value
2421

25-
error: aborting due to 4 previous errors
22+
error: aborting due to 3 previous errors
2623

2724
For more information about this error, try `rustc --explain E0191`.

src/test/ui/error-codes/E0107-b.stderr

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
66
| |
77
| unexpected type argument
88

9-
error[E0191]: the value of the associated type `A` (from the trait `T`) must be specified
9+
error[E0191]: the value of the associated types `A` (from the trait `T`), `C` (from the trait `T`) must be specified
1010
--> $DIR/E0107-b.rs:6:26
1111
|
1212
LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing associated type `A` value
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
| |
15+
| missing associated type `A` value
16+
| missing associated type `C` value
1417

15-
error[E0191]: the value of the associated type `C` (from the trait `T`) must be specified
16-
--> $DIR/E0107-b.rs:6:26
17-
|
18-
LL | pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing associated type `C` value
20-
21-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
2219

2320
Some errors occurred: E0107, E0191.
2421
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)