]> git.lizzy.rs Git - rust.git/commitdiff
Point at every unexpected lifetime and type argument in E0107
authorEsteban Küber <esteban@kuber.com.ar>
Fri, 9 Nov 2018 01:51:13 +0000 (17:51 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Thu, 22 Nov 2018 22:14:27 +0000 (14:14 -0800)
src/librustc_typeck/astconv.rs
src/test/ui/error-codes/E0107-b.rs [new file with mode: 0644]
src/test/ui/error-codes/E0107-b.stderr [new file with mode: 0644]
src/test/ui/error-codes/E0107.rs
src/test/ui/error-codes/E0107.stderr

index d388d75643888ea76908fa8bcdec68f1a672b68b..277f7d345462e0e7fdbed286ea609f7cee6e6b0e 100644 (file)
@@ -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 (file)
index 0000000..58e7718
--- /dev/null
@@ -0,0 +1,8 @@
+pub trait T<X, Y> {
+    type A;
+    type B;
+    type C;
+}
+ pub struct Foo { i: Box<T<usize, usize, usize, usize, B=usize>> }
+
+ 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 (file)
index 0000000..28b957d
--- /dev/null
@@ -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<T<usize, usize, usize, usize, B=usize>> }
+   |                                          ^^^^^  ^^^^^ 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<T<usize, usize, usize, usize, B=usize>> }
+   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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<T<usize, usize, usize, usize, B=usize>> }
+   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`.
index 815c7fefd2a96e79b71594cfae493f8c21bdbe49..87ac9e37853c01ce518c65a1f7233bea661afec4 100644 (file)
@@ -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() {}
index 497fa91bd4f399f58f407dc0516bf16521ce125c..a07c92cf26afb06c174a6b381d2b9005c889ed25 100644 (file)
@@ -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