Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c586fe4

Browse files
committed
macro_rules: Add more tests for using tt in addition to ident
Generally, `tt` and `ident` should behave identically, modulo the latter accepting only a subset of token trees.
1 parent 205fb75 commit c586fe4

19 files changed

+159
-27
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// check-pass
21
// edition:2018
32
// aux-build:anon-params-edition-hygiene.rs
43

@@ -8,6 +7,8 @@
87
#[macro_use]
98
extern crate anon_params_edition_hygiene;
109

11-
generate_trait_2015!(u8);
10+
generate_trait_2015_ident!(u8);
11+
// FIXME: Edition hygiene doesn't work correctly with `tt`s in this case.
12+
generate_trait_2015_tt!(u8); //~ ERROR expected one of `:`, `@`, or `|`, found `)`
1213

1314
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: expected one of `:`, `@`, or `|`, found `)`
2+
--> $DIR/anon-params-edition-hygiene.rs:12:1
3+
|
4+
LL | generate_trait_2015_tt!(u8);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected one of `:`, `@`, or `|`
6+
|
7+
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
8+
= note: this error originates in the macro `generate_trait_2015_tt` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
help: if this is a `self` type, give it a parameter name
10+
|
11+
LL | generate_trait_2015_tt!(self: u8);
12+
| +++++
13+
help: if this is a parameter name, give it a type
14+
|
15+
LL | generate_trait_2015_tt!(u8: TypeName);
16+
| ++++++++++
17+
help: if this is a type, explicitly ignore the parameter name
18+
|
19+
LL | generate_trait_2015_tt!(_: u8);
20+
| ++
21+
22+
error: aborting due to 1 previous error
23+

tests/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
// edition:2015
22

33
#[macro_export]
4-
macro_rules! generate_trait_2015 {
4+
macro_rules! generate_trait_2015_ident {
55
($Type: ident) => {
6-
trait Trait {
6+
trait Trait1 {
7+
fn method($Type) {}
8+
}
9+
};
10+
}
11+
12+
#[macro_export]
13+
macro_rules! generate_trait_2015_tt {
14+
($Type: tt) => {
15+
trait Trait2 {
716
fn method($Type) {}
817
}
918
};

tests/ui/editions/auxiliary/edition-kw-macro-2015.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ macro_rules! consumes_async_raw {
2626
macro_rules! passes_ident {
2727
($i: ident) => ($i)
2828
}
29+
30+
#[macro_export]
31+
macro_rules! passes_tt {
32+
($i: tt) => ($i)
33+
}

tests/ui/editions/auxiliary/edition-kw-macro-2018.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ macro_rules! consumes_async_raw {
2626
macro_rules! passes_ident {
2727
($i: ident) => ($i)
2828
}
29+
30+
#[macro_export]
31+
macro_rules! passes_tt {
32+
($i: tt) => ($i)
33+
}

tests/ui/editions/edition-keywords-2015-2015-parsing.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub fn check_async() {
1919

2020
if passes_ident!(async) == 1 {} // OK
2121
if passes_ident!(r#async) == 1 {} // OK
22+
if passes_tt!(async) == 1 {} // OK
23+
if passes_tt!(r#async) == 1 {} // OK
2224
module::async(); // OK
2325
module::r#async(); // OK
2426
}

tests/ui/editions/edition-keywords-2015-2015.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn check_async() {
2020

2121
if passes_ident!(async) == 1 {} // OK
2222
if passes_ident!(r#async) == 1 {} // OK
23+
if passes_tt!(async) == 1 {} // OK
24+
if passes_tt!(r#async) == 1 {} // OK
2325
one_async::async(); // OK
2426
one_async::r#async(); // OK
2527
two_async::async(); // OK

tests/ui/editions/edition-keywords-2015-2018-parsing.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub fn check_async() {
1919

2020
if passes_ident!(async) == 1 {} // OK
2121
if passes_ident!(r#async) == 1 {} // OK
22+
if passes_tt!(async) == 1 {} // OK
23+
if passes_tt!(r#async) == 1 {} // OK
2224
module::async(); // OK
2325
module::r#async(); // OK
2426
}

tests/ui/editions/edition-keywords-2015-2018.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn check_async() {
2020

2121
if passes_ident!(async) == 1 {} // OK
2222
if passes_ident!(r#async) == 1 {} // OK
23+
if passes_tt!(async) == 1 {} // OK
24+
if passes_tt!(r#async) == 1 {} // OK
2325
// one_async::async(); // ERROR, unresolved name
2426
// one_async::r#async(); // ERROR, unresolved name
2527
two_async::async(); // OK

tests/ui/editions/edition-keywords-2018-2015-parsing.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ pub fn check_async() {
2121
r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
2222
r#async = consumes_async_raw!(r#async); // OK
2323

24-
if passes_ident!(async) == 1 {}
24+
if passes_ident!(async) == 1 {} // FIXME: Edition hygiene bug, async here is 2018 and reserved
2525
if passes_ident!(r#async) == 1 {} // OK
26+
if passes_tt!(async) == 1 {} //~ ERROR macro expansion ends with an incomplete expression
27+
if passes_tt!(r#async) == 1 {} // OK
2628
module::async(); //~ ERROR expected identifier, found keyword `async`
2729
module::r#async(); // OK
2830

0 commit comments

Comments
 (0)