diff options
Diffstat (limited to 'tests')
8 files changed, 108 insertions, 0 deletions
diff --git a/tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.rs b/tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.rs new file mode 100644 index 00000000000..33630205369 --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.rs @@ -0,0 +1,14 @@ +macro_rules! y { + () => { + N + }; +} + +struct A<const N: usize>; + +fn foo<const N: usize>() -> A<{ y!() }> { + A::<1> + //~^ ERROR: mismatched types +} + +fn main() {} diff --git a/tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.stderr b/tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.stderr new file mode 100644 index 00000000000..4461477f3e9 --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-macro-braced-expansion.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/trivial-const-arg-macro-braced-expansion.rs:10:5 + | +LL | fn foo<const N: usize>() -> A<{ y!() }> { + | ----------- expected `A<N>` because of return type +LL | A::<1> + | ^^^^^^ expected `N`, found `1` + | + = note: expected struct `A<N>` + found struct `A<1>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.rs b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.rs new file mode 100644 index 00000000000..5a9e62561dc --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.rs @@ -0,0 +1,15 @@ +macro_rules! y { + () => { + N + //~^ ERROR: generic parameters may not be used in const operations + }; +} + +struct A<const N: usize>; + +#[rustfmt::skip] +fn foo<const N: usize>() -> A<{{ y!() }}> { + A::<1> +} + +fn main() {} diff --git a/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.stderr b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.stderr new file mode 100644 index 00000000000..e40d05924b1 --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces-2.stderr @@ -0,0 +1,15 @@ +error: generic parameters may not be used in const operations + --> $DIR/trivial-const-arg-macro-nested-braces-2.rs:3:9 + | +LL | N + | ^ cannot perform const operation using `N` +... +LL | fn foo<const N: usize>() -> A<{{ y!() }}> { + | ---- in this macro invocation + | + = help: const parameters may only be used as standalone arguments, i.e. `N` + = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions + = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + diff --git a/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.rs b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.rs new file mode 100644 index 00000000000..45c0768dde4 --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.rs @@ -0,0 +1,15 @@ +#[rustfmt::skip] +macro_rules! y { + () => { + { N } + //~^ ERROR: generic parameters may not be used in const operations + }; +} + +struct A<const N: usize>; + +fn foo<const N: usize>() -> A<{ y!() }> { + A::<1> +} + +fn main() {} diff --git a/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.stderr b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.stderr new file mode 100644 index 00000000000..b91d6c7a024 --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-macro-nested-braces.stderr @@ -0,0 +1,15 @@ +error: generic parameters may not be used in const operations + --> $DIR/trivial-const-arg-macro-nested-braces.rs:4:11 + | +LL | { N } + | ^ cannot perform const operation using `N` +... +LL | fn foo<const N: usize>() -> A<{ y!() }> { + | ---- in this macro invocation + | + = help: const parameters may only be used as standalone arguments, i.e. `N` + = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions + = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + diff --git a/tests/ui/const-generics/early/trivial-const-arg-nested-braces.rs b/tests/ui/const-generics/early/trivial-const-arg-nested-braces.rs new file mode 100644 index 00000000000..941ba6bfea7 --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-nested-braces.rs @@ -0,0 +1,9 @@ +struct A<const N: usize>; + +#[rustfmt::skip] +fn foo<const N: usize>() -> A<{ { N } }> { + //~^ ERROR: generic parameters may not be used in const operations + A::<1> +} + +fn main() {} diff --git a/tests/ui/const-generics/early/trivial-const-arg-nested-braces.stderr b/tests/ui/const-generics/early/trivial-const-arg-nested-braces.stderr new file mode 100644 index 00000000000..d60516ba4bc --- /dev/null +++ b/tests/ui/const-generics/early/trivial-const-arg-nested-braces.stderr @@ -0,0 +1,11 @@ +error: generic parameters may not be used in const operations + --> $DIR/trivial-const-arg-nested-braces.rs:4:35 + | +LL | fn foo<const N: usize>() -> A<{ { N } }> { + | ^ cannot perform const operation using `N` + | + = help: const parameters may only be used as standalone arguments, i.e. `N` + = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: aborting due to 1 previous error + |
