add macro test cases to extra arguments test

This commit is contained in:
Lukas Markeffsky 2023-06-10 18:54:46 +02:00
parent 89acdae9f2
commit 10ef96f6a5
2 changed files with 108 additions and 21 deletions

View File

@ -4,9 +4,15 @@ fn two_arg_same(_a: i32, _b: i32) {}
fn two_arg_diff(_a: i32, _b: &str) {}
macro_rules! foo {
($x:expr) => {
($x:expr, ~) => {
empty($x, 1); //~ ERROR function takes
}
};
($x:expr, $y:expr) => {
empty($x, $y); //~ ERROR function takes
};
(~, $y:expr) => {
empty(1, $y); //~ ERROR function takes
};
}
fn main() {
@ -39,5 +45,11 @@ fn main() {
1,
""
);
foo!(1);
// Check with macro expansions
foo!(1, ~);
foo!(~, 1);
foo!(1, 1);
one_arg(1, panic!()); //~ ERROR function takes
one_arg(panic!(), 1); //~ ERROR function takes
}

View File

@ -1,5 +1,5 @@
error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> $DIR/extra_arguments.rs:13:3
--> $DIR/extra_arguments.rs:19:3
|
LL | empty("");
| ^^^^^ --
@ -14,7 +14,7 @@ LL | fn empty() {}
| ^^^^^
error[E0061]: this function takes 0 arguments but 2 arguments were supplied
--> $DIR/extra_arguments.rs:14:3
--> $DIR/extra_arguments.rs:20:3
|
LL | empty(1, 1);
| ^^^^^ - - unexpected argument of type `{integer}`
@ -33,7 +33,7 @@ LL + empty();
|
error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:16:3
--> $DIR/extra_arguments.rs:22:3
|
LL | one_arg(1, 1);
| ^^^^^^^ ---
@ -48,7 +48,7 @@ LL | fn one_arg(_a: i32) {}
| ^^^^^^^ -------
error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:17:3
--> $DIR/extra_arguments.rs:23:3
|
LL | one_arg(1, "");
| ^^^^^^^ ----
@ -63,7 +63,7 @@ LL | fn one_arg(_a: i32) {}
| ^^^^^^^ -------
error[E0061]: this function takes 1 argument but 3 arguments were supplied
--> $DIR/extra_arguments.rs:18:3
--> $DIR/extra_arguments.rs:24:3
|
LL | one_arg(1, "", 1.0);
| ^^^^^^^ -- --- unexpected argument of type `{float}`
@ -82,7 +82,7 @@ LL + one_arg(1);
|
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:20:3
--> $DIR/extra_arguments.rs:26:3
|
LL | two_arg_same(1, 1, 1);
| ^^^^^^^^^^^^ ---
@ -97,7 +97,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {}
| ^^^^^^^^^^^^ ------- -------
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:21:3
--> $DIR/extra_arguments.rs:27:3
|
LL | two_arg_same(1, 1, 1.0);
| ^^^^^^^^^^^^ -----
@ -112,7 +112,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {}
| ^^^^^^^^^^^^ ------- -------
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:23:3
--> $DIR/extra_arguments.rs:29:3
|
LL | two_arg_diff(1, 1, "");
| ^^^^^^^^^^^^ ---
@ -127,7 +127,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {}
| ^^^^^^^^^^^^ ------- --------
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:24:3
--> $DIR/extra_arguments.rs:30:3
|
LL | two_arg_diff(1, "", "");
| ^^^^^^^^^^^^ ----
@ -142,7 +142,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {}
| ^^^^^^^^^^^^ ------- --------
error[E0061]: this function takes 2 arguments but 4 arguments were supplied
--> $DIR/extra_arguments.rs:25:3
--> $DIR/extra_arguments.rs:31:3
|
LL | two_arg_diff(1, 1, "", "");
| ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str`
@ -161,7 +161,7 @@ LL + two_arg_diff(1, "");
|
error[E0061]: this function takes 2 arguments but 4 arguments were supplied
--> $DIR/extra_arguments.rs:26:3
--> $DIR/extra_arguments.rs:32:3
|
LL | two_arg_diff(1, "", 1, "");
| ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str`
@ -180,7 +180,7 @@ LL + two_arg_diff(1, "");
|
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:29:3
--> $DIR/extra_arguments.rs:35:3
|
LL | two_arg_same(1, 1, "");
| ^^^^^^^^^^^^ --------
@ -195,7 +195,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {}
| ^^^^^^^^^^^^ ------- -------
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:30:3
--> $DIR/extra_arguments.rs:36:3
|
LL | two_arg_diff(1, 1, "");
| ^^^^^^^^^^^^ ---
@ -210,7 +210,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {}
| ^^^^^^^^^^^^ ------- --------
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:31:3
--> $DIR/extra_arguments.rs:37:3
|
LL | two_arg_same(
| ^^^^^^^^^^^^
@ -230,7 +230,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {}
| ^^^^^^^^^^^^ ------- -------
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
--> $DIR/extra_arguments.rs:37:3
--> $DIR/extra_arguments.rs:43:3
|
LL | two_arg_diff(
| ^^^^^^^^^^^^
@ -254,8 +254,8 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied
LL | empty($x, 1);
| ^^^^^ - unexpected argument of type `{integer}`
...
LL | foo!(1);
| -------
LL | foo!(1, ~);
| ----------
| | |
| | unexpected argument of type `{integer}`
| | help: remove the extra argument
@ -268,6 +268,81 @@ LL | fn empty() {}
| ^^^^^
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 16 previous errors
error[E0061]: this function takes 0 arguments but 2 arguments were supplied
--> $DIR/extra_arguments.rs:14:9
|
LL | empty(1, $y);
| ^^^^^ ----- help: remove the extra argument
| |
| unexpected argument of type `{integer}`
...
LL | foo!(~, 1);
| ----------
| | |
| | unexpected argument of type `{integer}`
| in this macro invocation
|
note: function defined here
--> $DIR/extra_arguments.rs:1:4
|
LL | fn empty() {}
| ^^^^^
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0061]: this function takes 0 arguments but 2 arguments were supplied
--> $DIR/extra_arguments.rs:11:9
|
LL | empty($x, $y);
| ^^^^^
...
LL | foo!(1, 1);
| ----------
| | | |
| | | unexpected argument of type `{integer}`
| | unexpected argument of type `{integer}`
| in this macro invocation
|
note: function defined here
--> $DIR/extra_arguments.rs:1:4
|
LL | fn empty() {}
| ^^^^^
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
help: remove the extra arguments
|
LL ~ empty($x, $y;
LL | };
...
LL | foo!(~, 1);
LL ~ foo!(, 1);
|
error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:53:3
|
LL | one_arg(1, panic!());
| ^^^^^^^ -------- unexpected argument
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
|
LL | fn one_arg(_a: i32) {}
| ^^^^^^^ -------
error[E0061]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/extra_arguments.rs:54:3
|
LL | one_arg(panic!(), 1);
| ^^^^^^^ - - unexpected argument of type `{integer}`
| |
| help: remove the extra argument
|
note: function defined here
--> $DIR/extra_arguments.rs:2:4
|
LL | fn one_arg(_a: i32) {}
| ^^^^^^^ -------
error: aborting due to 20 previous errors
For more information about this error, try `rustc --explain E0061`.