From 286f7ae1dde03478fc0f36b7d1f3dc97cb47b730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Nov 2018 18:11:37 -0800 Subject: [PATCH] Join multiple E0191 errors in the same location under a single diagnostic --- src/librustc_typeck/astconv.rs | 27 ++++++++++++++----- .../associated-types-incomplete-object.rs | 3 +-- .../associated-types-incomplete-object.stderr | 15 +++++------ src/test/ui/error-codes/E0107-b.stderr | 15 +++++------ 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 277f7d345462..906b800ee447 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1029,18 +1029,31 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o { associated_types.remove(&projection_bound.projection_def_id()); } - for item_def_id in associated_types { - let assoc_item = tcx.associated_item(item_def_id); - let trait_def_id = assoc_item.container.id(); + if !associated_types.is_empty() { + let names = associated_types.iter().map(|item_def_id| { + let assoc_item = tcx.associated_item(*item_def_id); + let trait_def_id = assoc_item.container.id(); + format!( + "`{}` (from the trait `{}`)", + assoc_item.ident, + tcx.item_path_str(trait_def_id), + ) + }).collect::>().join(", "); let mut err = struct_span_err!( tcx.sess, span, E0191, - "the value of the associated type `{}` (from the trait `{}`) must be specified", - assoc_item.ident, - tcx.item_path_str(trait_def_id), + "the value of the associated type{} {} must be specified", + if associated_types.len() == 1 { "" } else { "s" }, + names, ); - err.span_label(span, format!("missing associated type `{}` value", assoc_item.ident)); + for item_def_id in associated_types { + let assoc_item = tcx.associated_item(item_def_id); + err.span_label( + span, + format!("missing associated type `{}` value", assoc_item.ident), + ); + } err.emit(); } diff --git a/src/test/ui/associated-types/associated-types-incomplete-object.rs b/src/test/ui/associated-types/associated-types-incomplete-object.rs index 9f1df14605b6..e575fd695b2d 100644 --- a/src/test/ui/associated-types/associated-types-incomplete-object.rs +++ b/src/test/ui/associated-types/associated-types-incomplete-object.rs @@ -37,6 +37,5 @@ pub fn main() { //~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified let d = &42isize as &Foo; - //~^ ERROR the value of the associated type `A` (from the trait `Foo`) must be specified - //~| ERROR the value of the associated type `B` (from the trait `Foo`) must be specified + //~^ ERROR the value of the associated types `A` (from the trait `Foo`), `B` (from the trait } diff --git a/src/test/ui/associated-types/associated-types-incomplete-object.stderr b/src/test/ui/associated-types/associated-types-incomplete-object.stderr index 95b1c6312500..5a3c243efd08 100644 --- a/src/test/ui/associated-types/associated-types-incomplete-object.stderr +++ b/src/test/ui/associated-types/associated-types-incomplete-object.stderr @@ -10,18 +10,15 @@ error[E0191]: the value of the associated type `A` (from the trait `Foo`) must b LL | let c = &42isize as &Foo; | ^^^^^^^^^^^ missing associated type `A` value -error[E0191]: the value of the associated type `A` (from the trait `Foo`) must be specified +error[E0191]: the value of the associated types `A` (from the trait `Foo`), `B` (from the trait `Foo`) must be specified --> $DIR/associated-types-incomplete-object.rs:39:26 | LL | let d = &42isize as &Foo; - | ^^^ missing associated type `A` value + | ^^^ + | | + | missing associated type `A` value + | missing associated type `B` value -error[E0191]: the value of the associated type `B` (from the trait `Foo`) must be specified - --> $DIR/associated-types-incomplete-object.rs:39:26 - | -LL | let d = &42isize as &Foo; - | ^^^ missing associated type `B` value - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0191`. diff --git a/src/test/ui/error-codes/E0107-b.stderr b/src/test/ui/error-codes/E0107-b.stderr index 28b957dc91e7..f779ca1e0b13 100644 --- a/src/test/ui/error-codes/E0107-b.stderr +++ b/src/test/ui/error-codes/E0107-b.stderr @@ -6,19 +6,16 @@ LL | pub struct Foo { i: Box> } | | | unexpected type argument -error[E0191]: the value of the associated type `A` (from the trait `T`) must be specified +error[E0191]: the value of the associated types `A` (from the trait `T`), `C` (from the trait `T`) must be specified --> $DIR/E0107-b.rs:6:26 | LL | pub struct Foo { i: Box> } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing associated type `A` value + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | missing associated type `A` value + | missing associated type `C` value -error[E0191]: the value of the associated type `C` (from the trait `T`) must be specified - --> $DIR/E0107-b.rs:6:26 - | -LL | pub struct Foo { i: Box> } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing associated type `C` value - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors occurred: E0107, E0191. For more information about an error, try `rustc --explain E0107`.