about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-11-19 16:26:44 +0100
committerGitHub <noreply@github.com>2020-11-19 16:26:44 +0100
commitb5fffdc12be138ddf5fbd0f20d31026597d86d4e (patch)
treed00a739e36f57744c29dc246dfbadce5ed44cf3a /src
parentde622725480148f41e3c1cf0f52aeb230e5e1159 (diff)
parent85bc9538920850e5bd7c1023c9ffbf5e8e69be6a (diff)
downloadrust-b5fffdc12be138ddf5fbd0f20d31026597d86d4e.tar.gz
rust-b5fffdc12be138ddf5fbd0f20d31026597d86d4e.zip
Rollup merge of #79164 - varkor:unbraced-single-segment-const-arguments, r=petrochenkov
Permit standalone generic parameters as const generic arguments in macros

Fixes https://github.com/rust-lang/rust/issues/79127.

r? ```@petrochenkov```
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/const-generics/macro_rules-braces.full.stderr20
-rw-r--r--src/test/ui/const-generics/macro_rules-braces.min.stderr20
-rw-r--r--src/test/ui/const-generics/macro_rules-braces.rs17
3 files changed, 36 insertions, 21 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
index e5b67f61a25..3c9d4c9b470 100644
--- a/src/test/ui/const-generics/macro_rules-braces.full.stderr
+++ b/src/test/ui/const-generics/macro_rules-braces.full.stderr
@@ -1,16 +1,16 @@
 error: expressions must be enclosed in braces to be used as const generic arguments
-  --> $DIR/macro_rules-braces.rs:34:17
+  --> $DIR/macro_rules-braces.rs:49:17
    |
-LL |     let _: baz!(N);
-   |                 ^
+LL |     let _: baz!(m::P);
+   |                 ^^^^
    |
 help: enclose the `const` expression in braces
    |
-LL |     let _: baz!({ N });
-   |                 ^   ^
+LL |     let _: baz!({ m::P });
+   |                 ^      ^
 
 error: expressions must be enclosed in braces to be used as const generic arguments
-  --> $DIR/macro_rules-braces.rs:54:17
+  --> $DIR/macro_rules-braces.rs:69:17
    |
 LL |     let _: baz!(10 + 7);
    |                 ^^^^^^
@@ -21,7 +21,7 @@ LL |     let _: baz!({ 10 + 7 });
    |                 ^        ^
 
 error: constant expression depends on a generic parameter
-  --> $DIR/macro_rules-braces.rs:10:13
+  --> $DIR/macro_rules-braces.rs:16:13
    |
 LL |             [u8; $x]
    |             ^^^^^^^^
@@ -33,7 +33,7 @@ LL |     let _: foo!({{ N }});
    = 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
+  --> $DIR/macro_rules-braces.rs:21:13
    |
 LL |             [u8; { $x }]
    |             ^^^^^^^^^^^^
@@ -45,7 +45,7 @@ LL |     let _: bar!({ N });
    = 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
+  --> $DIR/macro_rules-braces.rs:26:13
    |
 LL |             Foo<$x>
    |             ^^^^^^^
@@ -57,7 +57,7 @@ LL |     let _: baz!({{ N }});
    = 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
+  --> $DIR/macro_rules-braces.rs:31:13
    |
 LL |             Foo<{ $x }>
    |             ^^^^^^^^^^^
diff --git a/src/test/ui/const-generics/macro_rules-braces.min.stderr b/src/test/ui/const-generics/macro_rules-braces.min.stderr
index a4ef732017d..c6425edc10f 100644
--- a/src/test/ui/const-generics/macro_rules-braces.min.stderr
+++ b/src/test/ui/const-generics/macro_rules-braces.min.stderr
@@ -1,16 +1,16 @@
 error: expressions must be enclosed in braces to be used as const generic arguments
-  --> $DIR/macro_rules-braces.rs:34:17
+  --> $DIR/macro_rules-braces.rs:49:17
    |
-LL |     let _: baz!(N);
-   |                 ^
+LL |     let _: baz!(m::P);
+   |                 ^^^^
    |
 help: enclose the `const` expression in braces
    |
-LL |     let _: baz!({ N });
-   |                 ^   ^
+LL |     let _: baz!({ m::P });
+   |                 ^      ^
 
 error: expressions must be enclosed in braces to be used as const generic arguments
-  --> $DIR/macro_rules-braces.rs:54:17
+  --> $DIR/macro_rules-braces.rs:69:17
    |
 LL |     let _: baz!(10 + 7);
    |                 ^^^^^^
@@ -21,7 +21,7 @@ LL |     let _: baz!({ 10 + 7 });
    |                 ^        ^
 
 error: generic parameters may not be used in const operations
-  --> $DIR/macro_rules-braces.rs:31:20
+  --> $DIR/macro_rules-braces.rs:37:20
    |
 LL |     let _: foo!({{ N }});
    |                    ^ cannot perform const operation using `N`
@@ -29,7 +29,7 @@ LL |     let _: foo!({{ 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
+  --> $DIR/macro_rules-braces.rs:41:19
    |
 LL |     let _: bar!({ N });
    |                   ^ cannot perform const operation using `N`
@@ -37,7 +37,7 @@ LL |     let _: bar!({ 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
+  --> $DIR/macro_rules-braces.rs:46:20
    |
 LL |     let _: baz!({{ N }});
    |                    ^ cannot perform const operation using `N`
@@ -45,7 +45,7 @@ LL |     let _: baz!({{ 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
+  --> $DIR/macro_rules-braces.rs:51:19
    |
 LL |     let _: biz!({ N });
    |                   ^ cannot perform const operation using `N`
diff --git a/src/test/ui/const-generics/macro_rules-braces.rs b/src/test/ui/const-generics/macro_rules-braces.rs
index bc67d464f11..c6b43bec243 100644
--- a/src/test/ui/const-generics/macro_rules-braces.rs
+++ b/src/test/ui/const-generics/macro_rules-braces.rs
@@ -3,6 +3,12 @@
 #![cfg_attr(full, feature(const_generics))]
 #![cfg_attr(min, feature(min_const_generics))]
 
+mod m {
+    pub const P: usize = 0;
+}
+
+const Q: usize = 0;
+
 fn test<const N: usize>() {
     struct Foo<const M: usize>;
     macro_rules! foo {
@@ -29,13 +35,22 @@ fn test<const N: usize>() {
     let _: foo!(N);
     let _: foo!({ N });
     let _: foo!({{ N }}); //[min]~ ERROR generic parameters may not
+    let _: foo!(Q);
+    let _: foo!(m::P);
     let _: bar!(N);
     let _: bar!({ N }); //[min]~ ERROR generic parameters may not
-    let _: baz!(N); //~ ERROR expressions must be enclosed in braces
+    let _: bar!(Q);
+    let _: bar!(m::P);
+    let _: baz!(N);
     let _: baz!({ N });
     let _: baz!({{ N }}); //[min]~ ERROR generic parameters may not
+    let _: baz!(Q);
+    let _: baz!({ m::P });
+    let _: baz!(m::P); //~ ERROR expressions must be enclosed in braces
     let _: biz!(N);
     let _: biz!({ N }); //[min]~ ERROR generic parameters may not
+    let _: biz!(Q);
+    let _: biz!(m::P);
     let _: foo!(3);
     let _: foo!({ 3 });
     let _: foo!({{ 3 }});