Rollup merge of #86493 - Smittyvb:ctor-typeck-error, r=davidtwco

Say "this enum variant takes"/"this struct takes" instead of "this function takes"

This makes error messages for functions with incorrect argument counts adapt if they refer to a struct or enum variant:
```
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:7:13
   |
LL |     let _ = Ok();
   |             ^^-- supplied 0 arguments
   |             |
   |             expected 1 argument

error[E0061]: this struct takes 1 argument but 0 arguments were supplied
  --> $DIR/struct-enum-wrong-args.rs:8:13
   |
LL |     let _ = Wrapper();
   |             ^^^^^^^-- supplied 0 arguments
   |             |
   |             expected 1 argument
```

Fixes #86481.
This commit is contained in:
Yuki Okushi 2021-06-22 07:37:56 +09:00 committed by GitHub
commit 4495ce75d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 107 additions and 6 deletions

View file

@ -8,7 +8,7 @@ impl S {
}
fn main() {
let _: Result<(), String> = Ok(); //~ ERROR this function takes
let _: Result<(), String> = Ok(); //~ ERROR this enum variant takes
foo(); //~ ERROR this function takes
foo(()); //~ ERROR this function takes
bar(); //~ ERROR this function takes

View file

@ -1,4 +1,4 @@
error[E0061]: this function takes 1 argument but 0 arguments were supplied
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
--> $DIR/missing-unit-argument.rs:11:33
|
LL | let _: Result<(), String> = Ok();

View file

@ -0,0 +1,14 @@
// Regression test of #86481.
struct Wrapper(i32);
struct DoubleWrapper(i32, i32);
fn main() {
let _ = Some(3, 2); //~ ERROR this enum variant takes
let _ = Ok(3, 6, 2); //~ ERROR this enum variant takes
let _ = Ok(); //~ ERROR this enum variant takes
let _ = Wrapper(); //~ ERROR this struct takes
let _ = Wrapper(5, 2); //~ ERROR this struct takes
let _ = DoubleWrapper(); //~ ERROR this struct takes
let _ = DoubleWrapper(5); //~ ERROR this struct takes
let _ = DoubleWrapper(5, 2, 7); //~ ERROR this struct takes
}

View file

@ -0,0 +1,67 @@
error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied
--> $DIR/struct-enum-wrong-args.rs:6:13
|
LL | let _ = Some(3, 2);
| ^^^^ - - supplied 2 arguments
| |
| expected 1 argument
error[E0061]: this enum variant takes 1 argument but 3 arguments were supplied
--> $DIR/struct-enum-wrong-args.rs:7:13
|
LL | let _ = Ok(3, 6, 2);
| ^^ - - - supplied 3 arguments
| |
| expected 1 argument
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
--> $DIR/struct-enum-wrong-args.rs:8:13
|
LL | let _ = Ok();
| ^^-- supplied 0 arguments
| |
| expected 1 argument
error[E0061]: this struct takes 1 argument but 0 arguments were supplied
--> $DIR/struct-enum-wrong-args.rs:9:13
|
LL | let _ = Wrapper();
| ^^^^^^^-- supplied 0 arguments
| |
| expected 1 argument
error[E0061]: this struct takes 1 argument but 2 arguments were supplied
--> $DIR/struct-enum-wrong-args.rs:10:13
|
LL | let _ = Wrapper(5, 2);
| ^^^^^^^ - - supplied 2 arguments
| |
| expected 1 argument
error[E0061]: this struct takes 2 arguments but 0 arguments were supplied
--> $DIR/struct-enum-wrong-args.rs:11:13
|
LL | let _ = DoubleWrapper();
| ^^^^^^^^^^^^^-- supplied 0 arguments
| |
| expected 2 arguments
error[E0061]: this struct takes 2 arguments but 1 argument was supplied
--> $DIR/struct-enum-wrong-args.rs:12:13
|
LL | let _ = DoubleWrapper(5);
| ^^^^^^^^^^^^^ - supplied 1 argument
| |
| expected 2 arguments
error[E0061]: this struct takes 2 arguments but 3 arguments were supplied
--> $DIR/struct-enum-wrong-args.rs:13:13
|
LL | let _ = DoubleWrapper(5, 2, 7);
| ^^^^^^^^^^^^^ - - - supplied 3 arguments
| |
| expected 2 arguments
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0061`.