about summary refs log tree commit diff
path: root/src/test/ui/error-codes
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-13 20:35:58 +0000
committerbors <bors@rust-lang.org>2021-01-13 20:35:58 +0000
commita62a76047ea24aad7639f14eb3ce0e620b77bdb7 (patch)
treea3a7fb0140d8cc55261f719e566e7221b1d3c41b /src/test/ui/error-codes
parent9bc8b00b4a4e38ccbc3aeec2c123538973c67eba (diff)
parentd2f8e398f19b5b3d38646328ec158f50db6b8b06 (diff)
downloadrust-a62a76047ea24aad7639f14eb3ce0e620b77bdb7.tar.gz
rust-a62a76047ea24aad7639f14eb3ce0e620b77bdb7.zip
Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
Diffstat (limited to 'src/test/ui/error-codes')
-rw-r--r--src/test/ui/error-codes/E0107.rs15
-rw-r--r--src/test/ui/error-codes/E0107.stderr46
2 files changed, 44 insertions, 17 deletions
diff --git a/src/test/ui/error-codes/E0107.rs b/src/test/ui/error-codes/E0107.rs
index 35173dcce30..c3dde72599b 100644
--- a/src/test/ui/error-codes/E0107.rs
+++ b/src/test/ui/error-codes/E0107.rs
@@ -9,15 +9,16 @@ enum Bar {
 
 struct Baz<'a, 'b, 'c> {
     buzz: Buzz<'a>,
-    //~^ ERROR E0107
-    //~| expected 2 lifetime arguments
+    //~^ ERROR this struct takes 2 lifetime arguments but only 1 lifetime argument was supplied
+    //~| HELP add missing lifetime argument
+
     bar: Bar<'a>,
-    //~^ ERROR E0107
-    //~| unexpected lifetime argument
+    //~^ ERROR this enum takes 0 lifetime arguments but 1 lifetime argument was supplied
+    //~| HELP remove these generics
+
     foo2: Foo<'a, 'b, 'c>,
-    //~^ ERROR E0107
-    //~| unexpected lifetime argument
-    //~| unexpected lifetime argument
+    //~^ ERROR this struct takes 1 lifetime argument but 3 lifetime arguments were supplied
+    //~| HELP remove these lifetime arguments
 }
 
 fn main() {}
diff --git a/src/test/ui/error-codes/E0107.stderr b/src/test/ui/error-codes/E0107.stderr
index 486810ab113..30a2768d060 100644
--- a/src/test/ui/error-codes/E0107.stderr
+++ b/src/test/ui/error-codes/E0107.stderr
@@ -1,22 +1,48 @@
-error[E0107]: wrong number of lifetime arguments: expected 2, found 1
+error[E0107]: this struct takes 2 lifetime arguments but only 1 lifetime argument was supplied
   --> $DIR/E0107.rs:11:11
    |
 LL |     buzz: Buzz<'a>,
-   |           ^^^^^^^^ expected 2 lifetime arguments
+   |           ^^^^ -- supplied 1 lifetime argument
+   |           |
+   |           expected 2 lifetime arguments
+   |
+note: struct defined here, with 2 lifetime parameters: `'a`, `'b`
+  --> $DIR/E0107.rs:2:8
+   |
+LL | struct Buzz<'a, 'b>(&'a str, &'b str);
+   |        ^^^^ --  --
+help: add missing lifetime argument
+   |
+LL |     buzz: Buzz<'a, 'b>,
+   |                  ^^^^
 
-error[E0107]: wrong number of lifetime arguments: expected 0, found 1
-  --> $DIR/E0107.rs:14:14
+error[E0107]: this enum takes 0 lifetime arguments but 1 lifetime argument was supplied
+  --> $DIR/E0107.rs:15:10
    |
 LL |     bar: Bar<'a>,
-   |              ^^ unexpected lifetime argument
+   |          ^^^---- help: remove these generics
+   |          |
+   |          expected 0 lifetime arguments
+   |
+note: enum defined here, with 0 lifetime parameters
+  --> $DIR/E0107.rs:4:6
+   |
+LL | enum Bar {
+   |      ^^^
 
-error[E0107]: wrong number of lifetime arguments: expected 1, found 3
-  --> $DIR/E0107.rs:17:19
+error[E0107]: this struct takes 1 lifetime argument but 3 lifetime arguments were supplied
+  --> $DIR/E0107.rs:19:11
    |
 LL |     foo2: Foo<'a, 'b, 'c>,
-   |                   ^^  ^^ unexpected lifetime argument
-   |                   |
-   |                   unexpected lifetime argument
+   |           ^^^   -------- help: remove these lifetime arguments
+   |           |
+   |           expected 1 lifetime argument
+   |
+note: struct defined here, with 1 lifetime parameter: `'a`
+  --> $DIR/E0107.rs:1:8
+   |
+LL | struct Foo<'a>(&'a str);
+   |        ^^^ --
 
 error: aborting due to 3 previous errors