From: Esteban Küber Date: Fri, 9 Nov 2018 01:51:13 +0000 (-0800) Subject: Point at every unexpected lifetime and type argument in E0107 X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=abdcb868ff69a5f6a96dd188ff845a1ec67335f8;p=rust.git Point at every unexpected lifetime and type argument in E0107 --- diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d388d756438..277f7d34546 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -338,33 +338,31 @@ fn check_generic_arg_count( (required, "") }; - let mut span = span; - let label = if required == permitted && provided > permitted { - let diff = provided - permitted; - if diff == 1 { - // In the case when the user has provided too many arguments, - // we want to point to the first unexpected argument. - let first_superfluous_arg: &GenericArg = &args.args[offset + permitted]; - span = first_superfluous_arg.span(); - } - format!( - "{}unexpected {} argument{}", - if diff != 1 { format!("{} ", diff) } else { String::new() }, - kind, - if diff != 1 { "s" } else { "" }, + let (spans, label) = if required == permitted && provided > permitted { + // In the case when the user has provided too many arguments, + // we want to point to the unexpected arguments. + ( + args.args[offset+permitted .. offset+provided] + .iter() + .map(|arg| arg.span()) + .collect(), + format!( + "unexpected {} argument", + kind, + ), ) } else { - format!( + (vec![span], format!( "expected {}{} {} argument{}", quantifier, bound, kind, if bound != 1 { "s" } else { "" }, - ) + )) }; - tcx.sess.struct_span_err_with_code( - span, + let mut err = tcx.sess.struct_span_err_with_code( + spans.clone(), &format!( "wrong number of {} arguments: expected {}{}, found {}", kind, @@ -373,7 +371,11 @@ fn check_generic_arg_count( provided, ), DiagnosticId::Error("E0107".into()) - ).span_label(span, label).emit(); + ); + for span in spans { + err.span_label(span, label.as_str()); + } + err.emit(); provided > required // `suppress_error` }; @@ -1030,13 +1032,16 @@ fn conv_object_ty_poly_trait_ref(&self, for item_def_id in associated_types { let assoc_item = tcx.associated_item(item_def_id); let trait_def_id = assoc_item.container.id(); - 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)) - .span_label(span, format!("missing associated type `{}` value", - assoc_item.ident)) - .emit(); + 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), + ); + err.span_label(span, format!("missing associated type `{}` value", assoc_item.ident)); + err.emit(); } // Erase the `dummy_self` (`TRAIT_OBJECT_DUMMY_SELF`) used above. diff --git a/src/test/ui/error-codes/E0107-b.rs b/src/test/ui/error-codes/E0107-b.rs new file mode 100644 index 00000000000..58e7718ba5b --- /dev/null +++ b/src/test/ui/error-codes/E0107-b.rs @@ -0,0 +1,8 @@ +pub trait T { + type A; + type B; + type C; +} + pub struct Foo { i: Box> } + + fn main() {} diff --git a/src/test/ui/error-codes/E0107-b.stderr b/src/test/ui/error-codes/E0107-b.stderr new file mode 100644 index 00000000000..28b957dc91e --- /dev/null +++ b/src/test/ui/error-codes/E0107-b.stderr @@ -0,0 +1,24 @@ +error[E0107]: wrong number of type arguments: expected 2, found 4 + --> $DIR/E0107-b.rs:6:42 + | +LL | pub struct Foo { i: Box> } + | ^^^^^ ^^^^^ unexpected type argument + | | + | unexpected type argument + +error[E0191]: the value of the associated type `A` (from the trait `T`) must be specified + --> $DIR/E0107-b.rs:6:26 + | +LL | pub struct Foo { i: Box> } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing associated type `A` 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 + +Some errors occurred: E0107, E0191. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/error-codes/E0107.rs b/src/test/ui/error-codes/E0107.rs index 815c7fefd2a..87ac9e37853 100644 --- a/src/test/ui/error-codes/E0107.rs +++ b/src/test/ui/error-codes/E0107.rs @@ -26,7 +26,8 @@ struct Baz<'a, 'b, 'c> { //~| unexpected lifetime argument foo2: Foo<'a, 'b, 'c>, //~^ ERROR E0107 - //~| 2 unexpected lifetime arguments + //~| unexpected lifetime argument + //~| unexpected lifetime argument } fn main() {} diff --git a/src/test/ui/error-codes/E0107.stderr b/src/test/ui/error-codes/E0107.stderr index 497fa91bd4f..a07c92cf26a 100644 --- a/src/test/ui/error-codes/E0107.stderr +++ b/src/test/ui/error-codes/E0107.stderr @@ -11,10 +11,12 @@ LL | bar: Bar<'a>, | ^^ unexpected lifetime argument error[E0107]: wrong number of lifetime arguments: expected 1, found 3 - --> $DIR/E0107.rs:27:11 + --> $DIR/E0107.rs:27:19 | LL | foo2: Foo<'a, 'b, 'c>, - | ^^^^^^^^^^^^^^^ 2 unexpected lifetime arguments + | ^^ ^^ unexpected lifetime argument + | | + | unexpected lifetime argument error: aborting due to 3 previous errors