From 857dd8b1fa815f1955ba86d3a8f516ebf8a3288b Mon Sep 17 00:00:00 2001 From: kadmin Date: Mon, 9 Nov 2020 21:18:04 +0000 Subject: [PATCH] Add macro test for min-const-generics --- .../min_const_generics/macro-fail.rs | 48 ++++++++ .../min_const_generics/macro-fail.stderr | 107 ++++++++++++++++++ .../min_const_generics/macro.rs | 57 ++++++++++ 3 files changed, 212 insertions(+) create mode 100644 src/test/ui/const-generics/min_const_generics/macro-fail.rs create mode 100644 src/test/ui/const-generics/min_const_generics/macro-fail.stderr create mode 100644 src/test/ui/const-generics/min_const_generics/macro.rs diff --git a/src/test/ui/const-generics/min_const_generics/macro-fail.rs b/src/test/ui/const-generics/min_const_generics/macro-fail.rs new file mode 100644 index 00000000000..7f16f2f33de --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/macro-fail.rs @@ -0,0 +1,48 @@ +#![feature(min_const_generics)] + +struct Example; + +macro_rules! external_macro { + () => {{ + //~^ ERROR expected type + const X: usize = 1337; + X + }} +} + +trait Marker {} +impl Marker for Example {} + +fn make_marker() -> impl Marker { + //~^ ERROR wrong number of const + //~| ERROR wrong number of type + Example:: + //~^ ERROR wrong number of const + //~| ERROR wrong number of type +} + +fn from_marker(_: impl Marker<{ + #[macro_export] + macro_rules! inline { () => {{ 3 }} }; inline!() +}>) {} + +fn main() { + let _ok = Example::<{ + #[macro_export] + macro_rules! gimme_a_const { + ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} + //~^ ERROR expected type + //~| ERROR expected type + }; + gimme_a_const!(run) + }>; + + let _fail = Example::; + //~^ ERROR wrong number of const + //~| ERROR wrong number of type + + let _fail = Example::; + //~^ ERROR wrong number of const + //~| ERROR wrong number of type + //~| ERROR unexpected end of macro invocation +} diff --git a/src/test/ui/const-generics/min_const_generics/macro-fail.stderr b/src/test/ui/const-generics/min_const_generics/macro-fail.stderr new file mode 100644 index 00000000000..fe7a4a5c382 --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/macro-fail.stderr @@ -0,0 +1,107 @@ +error: expected type, found `{` + --> $DIR/macro-fail.rs:33:27 + | +LL | fn make_marker() -> impl Marker { + | ---------------------- + | | + | this macro call doesn't expand to a type + | in this macro invocation +... +LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected type, found `{` + --> $DIR/macro-fail.rs:33:27 + | +LL | Example:: + | ---------------------- + | | + | this macro call doesn't expand to a type + | in this macro invocation +... +LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected type, found `{` + --> $DIR/macro-fail.rs:6:10 + | +LL | () => {{ + | __________^ +LL | | +LL | | const X: usize = 1337; +LL | | X +LL | | }} + | |___^ expected type +... +LL | let _fail = Example::; + | ----------------- + | | + | this macro call doesn't expand to a type + | in this macro invocation + | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: unexpected end of macro invocation + --> $DIR/macro-fail.rs:44:25 + | +LL | macro_rules! gimme_a_const { + | -------------------------- when calling this macro +... +LL | let _fail = Example::; + | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments + +error[E0107]: wrong number of const arguments: expected 1, found 0 + --> $DIR/macro-fail.rs:16:26 + | +LL | fn make_marker() -> impl Marker { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/macro-fail.rs:16:33 + | +LL | fn make_marker() -> impl Marker { + | ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument + +error[E0107]: wrong number of const arguments: expected 1, found 0 + --> $DIR/macro-fail.rs:19:3 + | +LL | Example:: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/macro-fail.rs:19:13 + | +LL | Example:: + | ^^^^^^^^^^^^^^^^^^^^^^ unexpected type argument + +error[E0107]: wrong number of const arguments: expected 1, found 0 + --> $DIR/macro-fail.rs:40:15 + | +LL | let _fail = Example::; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/macro-fail.rs:40:25 + | +LL | let _fail = Example::; + | ^^^^^^^^^^^^^^^^^ unexpected type argument + +error[E0107]: wrong number of const arguments: expected 1, found 0 + --> $DIR/macro-fail.rs:44:15 + | +LL | let _fail = Example::; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 const argument + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/macro-fail.rs:44:25 + | +LL | let _fail = Example::; + | ^^^^^^^^^^^^^^^^ unexpected type argument + +error: aborting due to 12 previous errors + +For more information about this error, try `rustc --explain E0107`. diff --git a/src/test/ui/const-generics/min_const_generics/macro.rs b/src/test/ui/const-generics/min_const_generics/macro.rs new file mode 100644 index 00000000000..85ecce551d4 --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/macro.rs @@ -0,0 +1,57 @@ +// run-pass +#![feature(min_const_generics)] + +struct Example; + +macro_rules! external_macro { + () => {{ + const X: usize = 1337; + X + }} +} + +trait Marker {} +impl Marker for Example {} + +fn make_marker() -> impl Marker<{ + #[macro_export] + macro_rules! const_macro { () => {{ 3 }} }; inline!() +}> { + Example::<{ const_macro!() }> +} + +fn from_marker(_: impl Marker<{ + #[macro_export] + macro_rules! inline { () => {{ 3 }} }; inline!() +}>) {} + +fn main() { + let _ok = Example::<{ + #[macro_export] + macro_rules! gimme_a_const { + ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} + }; + gimme_a_const!(run) + }>; + + let _ok = Example::<{ external_macro!() }>; + + let _ok: [_; gimme_a_const!(blah)] = [0,0,0]; + let _ok: [[u8; gimme_a_const!(blah)]; gimme_a_const!(blah)]; + let _ok: [u8; gimme_a_const!(blah)]; + + let _ok: [u8; { + #[macro_export] + macro_rules! const_two { () => {{ 2 }} }; + const_two!() + }]; + + let _ok = [0; { + #[macro_export] + macro_rules! const_three { () => {{ 3 }} }; + const_three!() + }]; + let _ok = [0; const_three!()]; + + from_marker(make_marker()); +}