-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add macro_rules test regarding braces
- Loading branch information
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(); | ||
} |