about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/const-generics/macro_rules-braces.full.stderr61
-rw-r--r--src/test/ui/const-generics/macro_rules-braces.min.stderr45
-rw-r--r--src/test/ui/const-generics/macro_rules-braces.rs43
3 files changed, 149 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/macro_rules-braces.full.stderr b/src/test/ui/const-generics/macro_rules-braces.full.stderr
new file mode 100644
index 00000000000..f6e9aabd907
--- /dev/null
+++ b/src/test/ui/const-generics/macro_rules-braces.full.stderr
@@ -0,0 +1,61 @@
+error: expressions must be enclosed in braces to be used as const generic arguments
+  --> $DIR/macro_rules-braces.rs:34:17
+   |
+LL |     let _: baz!(N);
+   |                 ^
+   |
+help: enclose the `const` expression in braces
+   |
+LL |     let _: baz!({ N });
+   |                 ^   ^
+
+error: constant expression depends on a generic parameter
+  --> $DIR/macro_rules-braces.rs:10:13
+   |
+LL |             [u8; $x]
+   |             ^^^^^^^^
+...
+LL |     let _: foo!({{ N }});
+   |            ------------- in this macro invocation
+   |
+   = note: this may fail depending on what value the parameter takes
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: constant expression depends on a generic parameter
+  --> $DIR/macro_rules-braces.rs:15:13
+   |
+LL |             [u8; { $x }]
+   |             ^^^^^^^^^^^^
+...
+LL |     let _: bar!({ N });
+   |            ----------- in this macro invocation
+   |
+   = note: this may fail depending on what value the parameter takes
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: constant expression depends on a generic parameter
+  --> $DIR/macro_rules-braces.rs:20:13
+   |
+LL |             Foo<$x>
+   |             ^^^^^^^
+...
+LL |     let _: baz!({{ N }});
+   |            ------------- in this macro invocation
+   |
+   = note: this may fail depending on what value the parameter takes
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: constant expression depends on a generic parameter
+  --> $DIR/macro_rules-braces.rs:25:13
+   |
+LL |             Foo<{ $x }>
+   |             ^^^^^^^^^^^
+...
+LL |     let _: biz!({ N });
+   |            ----------- in this macro invocation
+   |
+   = note: this may fail depending on what value the parameter takes
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 5 previous errors
+
diff --git a/src/test/ui/const-generics/macro_rules-braces.min.stderr b/src/test/ui/const-generics/macro_rules-braces.min.stderr
new file mode 100644
index 00000000000..1fe18e3fc02
--- /dev/null
+++ b/src/test/ui/const-generics/macro_rules-braces.min.stderr
@@ -0,0 +1,45 @@
+error: expressions must be enclosed in braces to be used as const generic arguments
+  --> $DIR/macro_rules-braces.rs:34:17
+   |
+LL |     let _: baz!(N);
+   |                 ^
+   |
+help: enclose the `const` expression in braces
+   |
+LL |     let _: baz!({ N });
+   |                 ^   ^
+
+error: generic parameters may not be used in const operations
+  --> $DIR/macro_rules-braces.rs:31:20
+   |
+LL |     let _: foo!({{ N }});
+   |                    ^ cannot perform const operation using `N`
+   |
+   = help: const parameters may only be used as standalone arguments, i.e. `N`
+
+error: generic parameters may not be used in const operations
+  --> $DIR/macro_rules-braces.rs:33:19
+   |
+LL |     let _: bar!({ N });
+   |                   ^ cannot perform const operation using `N`
+   |
+   = help: const parameters may only be used as standalone arguments, i.e. `N`
+
+error: generic parameters may not be used in const operations
+  --> $DIR/macro_rules-braces.rs:36:20
+   |
+LL |     let _: baz!({{ N }});
+   |                    ^ cannot perform const operation using `N`
+   |
+   = help: const parameters may only be used as standalone arguments, i.e. `N`
+
+error: generic parameters may not be used in const operations
+  --> $DIR/macro_rules-braces.rs:38:19
+   |
+LL |     let _: biz!({ N });
+   |                   ^ cannot perform const operation using `N`
+   |
+   = help: const parameters may only be used as standalone arguments, i.e. `N`
+
+error: aborting due to 5 previous errors
+
diff --git a/src/test/ui/const-generics/macro_rules-braces.rs b/src/test/ui/const-generics/macro_rules-braces.rs
new file mode 100644
index 00000000000..c3e2c8ba203
--- /dev/null
+++ b/src/test/ui/const-generics/macro_rules-braces.rs
@@ -0,0 +1,43 @@
+// revisions: full min
+#![cfg_attr(full, allow(incomplete_features))]
+#![cfg_attr(full, feature(const_generics))]
+#![cfg_attr(min, feature(min_const_generics))]
+
+fn test<const N: usize>() {
+    struct Foo<const M: usize>;
+    macro_rules! foo {
+        ($x:expr) => {
+            [u8; $x] //[full]~ ERROR constant expression depends
+        }
+    }
+    macro_rules! bar {
+        ($x:expr) => {
+            [u8; { $x }] //[full]~ ERROR constant expression depends
+        }
+    }
+    macro_rules! baz {
+        ( $x:expr) => {
+            Foo<$x> //[full]~ ERROR constant expression depends
+        }
+    }
+    macro_rules! biz {
+        ($x:expr) => {
+            Foo<{ $x }> //[full]~ ERROR constant expression depends
+        };
+    }
+
+    let _: foo!(N);
+    let _: foo!({ N });
+    let _: foo!({{ N }}); //[min]~ ERROR generic parameters may not
+    let _: bar!(N);
+    let _: bar!({ N }); //[min]~ ERROR generic parameters may not
+    let _: baz!(N); //~ ERROR expressions must be enclosed in braces
+    let _: baz!({ N });
+    let _: baz!({{ N }}); //[min]~ ERROR generic parameters may not
+    let _: biz!(N);
+    let _: biz!({ N }); //[min]~ ERROR generic parameters may not
+}
+
+fn main() {
+    test::<3>();
+}