Auto merge of #92472 - petrochenkov:nowrapident, r=Aaron1011

proc-macro: Stop wrapping `ident` matchers into groups

`ident` is always a single token and can be treated in the same way as `tt`.
r? `@Aaron1011`
This commit is contained in:
bors 2022-03-26 23:01:12 +00:00
commit 551b4fa395
18 changed files with 25 additions and 520 deletions

View file

@ -112,15 +112,9 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:14:54: 14:55 (#8),
},
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "my_name",
span: $DIR/capture-macro-rules-invoke.rs:42:13: 42:20 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:14:56: 14:62 (#8),
Ident {
ident: "my_name",
span: $DIR/capture-macro-rules-invoke.rs:42:13: 42:20 (#0),
},
Punct {
ch: ',',

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! tuple_from_req {
($T:ident) => {
#[my_macro] struct Three($T);
}
}

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! tuple_from_req {
($T:ident) => {
#[my_macro] struct Three($T);
}
}

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! tuple_from_req {
($T:ident) => {
#[my_macro] struct Four($T);
}
}

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! tuple_from_req {
($T:ident) => {
#[my_macro] struct Four($T);
}
}

View file

@ -1,17 +0,0 @@
// force-host
// no-prefer-dynamic
#![crate_type = "proc-macro"]
#![crate_name = "group_compat_hack"]
// This file has an unusual name in order to trigger the back-compat
// code in the compiler
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn my_macro(_attr: TokenStream, input: TokenStream) -> TokenStream {
println!("Called proc_macro_hack with {:?}", input);
input
}

View file

@ -1,87 +0,0 @@
// aux-build:pin-project-internal-0.4.0.rs
// compile-flags: -Z span-debug
#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;
#[macro_use] extern crate group_compat_hack;
// Tests the backwards compatibility hack added for certain macros
// When an attribute macro named `proc_macro_hack` or `wasm_bindgen`
// has an `NtIdent` named `$name`, we pass a plain `Ident` token in
// place of a `None`-delimited group. This allows us to maintain
// backwards compatibility for older versions of these crates.
mod no_version {
include!("js-sys/src/lib.rs");
include!("time-macros-impl/src/lib.rs");
macro_rules! other {
($name:ident) => {
#[my_macro] struct Three($name);
}
}
struct Foo;
impl_macros!(Foo); //~ ERROR using an old version
//~| WARN this was previously
arrays!(Foo);
other!(Foo);
}
mod with_version {
include!("js-sys-0.3.17/src/lib.rs");
include!("time-macros-impl-0.1.0/src/lib.rs");
macro_rules! other {
($name:ident) => {
#[my_macro] struct Three($name);
}
}
struct Foo;
impl_macros!(Foo); //~ ERROR using an old version
//~| WARN this was previously
arrays!(Foo); //~ ERROR using an old version
//~| WARN this was previously
other!(Foo);
}
mod actix_web_test {
include!("actix-web/src/extract.rs");
struct Foo;
tuple_from_req!(Foo); //~ ERROR using an old version
//~| WARN this was previously
}
mod actix_web_version_test {
include!("actix-web-2.0.0/src/extract.rs");
struct Foo;
tuple_from_req!(Foo); //~ ERROR using an old version
//~| WARN this was previously
}
mod actori_web_test {
include!("actori-web/src/extract.rs");
struct Foo;
tuple_from_req!(Foo);
}
mod actori_web_version_test {
include!("actori-web-2.0.0/src/extract.rs");
struct Foo;
tuple_from_req!(Foo);
}
mod with_good_js_sys_version {
include!("js-sys-0.3.40/src/lib.rs");
struct Foo;
arrays!(Foo);
}
fn main() {}

View file

@ -1,173 +0,0 @@
error: using an old version of `time-macros-impl`
--> $DIR/time-macros-impl/src/lib.rs:5:32
|
LL | #[my_macro] struct One($name);
| ^^^^^
|
::: $DIR/group-compat-hack.rs:26:5
|
LL | impl_macros!(Foo);
| ----------------- in this macro invocation
|
= note: `#[deny(proc_macro_back_compat)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
= note: this error originates in the macro `impl_macros` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using an old version of `time-macros-impl`
--> $DIR/time-macros-impl-0.1.0/src/lib.rs:5:32
|
LL | #[my_macro] struct One($name);
| ^^^^^
|
::: $DIR/group-compat-hack.rs:43:5
|
LL | impl_macros!(Foo);
| ----------------- in this macro invocation
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
= note: this error originates in the macro `impl_macros` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using an old version of `js-sys`
--> $DIR/js-sys-0.3.17/src/lib.rs:5:32
|
LL | #[my_macro] struct Two($name);
| ^^^^^
|
::: $DIR/group-compat-hack.rs:45:5
|
LL | arrays!(Foo);
| ------------ in this macro invocation
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: older versions of the `js-sys` crate will stop compiling in future versions of Rust; please update to `js-sys` v0.3.40 or above
= note: this error originates in the macro `arrays` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using an old version of `actix-web`
--> $DIR/actix-web/src/extract.rs:5:34
|
LL | #[my_macro] struct Three($T);
| ^^
|
::: $DIR/group-compat-hack.rs:54:5
|
LL | tuple_from_req!(Foo);
| -------------------- in this macro invocation
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
= note: this error originates in the macro `tuple_from_req` (in Nightly builds, run with -Z macro-backtrace for more info)
error: using an old version of `actix-web`
--> $DIR/actix-web-2.0.0/src/extract.rs:5:34
|
LL | #[my_macro] struct Three($T);
| ^^
|
::: $DIR/group-compat-hack.rs:62:5
|
LL | tuple_from_req!(Foo);
| -------------------- in this macro invocation
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
= note: this error originates in the macro `tuple_from_req` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 5 previous errors
Future incompatibility report: Future breakage diagnostic:
error: using an old version of `time-macros-impl`
--> $DIR/time-macros-impl/src/lib.rs:5:32
|
LL | #[my_macro] struct One($name);
| ^^^^^
|
::: $DIR/group-compat-hack.rs:26:5
|
LL | impl_macros!(Foo);
| ----------------- in this macro invocation
|
= note: `#[deny(proc_macro_back_compat)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
= note: this error originates in the macro `impl_macros` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
error: using an old version of `time-macros-impl`
--> $DIR/time-macros-impl-0.1.0/src/lib.rs:5:32
|
LL | #[my_macro] struct One($name);
| ^^^^^
|
::: $DIR/group-compat-hack.rs:43:5
|
LL | impl_macros!(Foo);
| ----------------- in this macro invocation
|
= note: `#[deny(proc_macro_back_compat)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
= note: this error originates in the macro `impl_macros` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
error: using an old version of `js-sys`
--> $DIR/js-sys-0.3.17/src/lib.rs:5:32
|
LL | #[my_macro] struct Two($name);
| ^^^^^
|
::: $DIR/group-compat-hack.rs:45:5
|
LL | arrays!(Foo);
| ------------ in this macro invocation
|
= note: `#[deny(proc_macro_back_compat)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: older versions of the `js-sys` crate will stop compiling in future versions of Rust; please update to `js-sys` v0.3.40 or above
= note: this error originates in the macro `arrays` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
error: using an old version of `actix-web`
--> $DIR/actix-web/src/extract.rs:5:34
|
LL | #[my_macro] struct Three($T);
| ^^
|
::: $DIR/group-compat-hack.rs:54:5
|
LL | tuple_from_req!(Foo);
| -------------------- in this macro invocation
|
= note: `#[deny(proc_macro_back_compat)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
= note: this error originates in the macro `tuple_from_req` (in Nightly builds, run with -Z macro-backtrace for more info)
Future breakage diagnostic:
error: using an old version of `actix-web`
--> $DIR/actix-web-2.0.0/src/extract.rs:5:34
|
LL | #[my_macro] struct Three($T);
| ^^
|
::: $DIR/group-compat-hack.rs:62:5
|
LL | tuple_from_req!(Foo);
| -------------------- in this macro invocation
|
= note: `#[deny(proc_macro_back_compat)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
= note: this error originates in the macro `tuple_from_req` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -1,11 +0,0 @@
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/time-macros-impl/src/lib.rs:5:21: 5:27 (#6) }, Ident { ident: "One", span: $DIR/time-macros-impl/src/lib.rs:5:28: 5:31 (#6) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:26:18: 26:21 (#0) }], span: $DIR/time-macros-impl/src/lib.rs:5:31: 5:38 (#6) }, Punct { ch: ';', spacing: Alone, span: $DIR/time-macros-impl/src/lib.rs:5:38: 5:39 (#6) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/js-sys/src/lib.rs:5:21: 5:27 (#10) }, Ident { ident: "Two", span: $DIR/js-sys/src/lib.rs:5:28: 5:31 (#10) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:28:13: 28:16 (#0) }], span: $DIR/js-sys/src/lib.rs:5:32: 5:37 (#10) }], span: $DIR/js-sys/src/lib.rs:5:31: 5:38 (#10) }, Punct { ch: ';', spacing: Alone, span: $DIR/js-sys/src/lib.rs:5:38: 5:39 (#10) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/group-compat-hack.rs:21:25: 21:31 (#14) }, Ident { ident: "Three", span: $DIR/group-compat-hack.rs:21:32: 21:37 (#14) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:29:12: 29:15 (#0) }], span: $DIR/group-compat-hack.rs:21:38: 21:43 (#14) }], span: $DIR/group-compat-hack.rs:21:37: 21:44 (#14) }, Punct { ch: ';', spacing: Alone, span: $DIR/group-compat-hack.rs:21:44: 21:45 (#14) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:21: 5:27 (#20) }, Ident { ident: "One", span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:28: 5:31 (#20) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:43:18: 43:21 (#0) }], span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:31: 5:38 (#20) }, Punct { ch: ';', spacing: Alone, span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:38: 5:39 (#20) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/js-sys-0.3.17/src/lib.rs:5:21: 5:27 (#24) }, Ident { ident: "Two", span: $DIR/js-sys-0.3.17/src/lib.rs:5:28: 5:31 (#24) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:45:13: 45:16 (#0) }], span: $DIR/js-sys-0.3.17/src/lib.rs:5:31: 5:38 (#24) }, Punct { ch: ';', spacing: Alone, span: $DIR/js-sys-0.3.17/src/lib.rs:5:38: 5:39 (#24) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/group-compat-hack.rs:38:25: 38:31 (#28) }, Ident { ident: "Three", span: $DIR/group-compat-hack.rs:38:32: 38:37 (#28) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:47:12: 47:15 (#0) }], span: $DIR/group-compat-hack.rs:38:38: 38:43 (#28) }], span: $DIR/group-compat-hack.rs:38:37: 38:44 (#28) }, Punct { ch: ';', spacing: Alone, span: $DIR/group-compat-hack.rs:38:44: 38:45 (#28) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actix-web/src/extract.rs:5:21: 5:27 (#33) }, Ident { ident: "Three", span: $DIR/actix-web/src/extract.rs:5:28: 5:33 (#33) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:54:21: 54:24 (#0) }], span: $DIR/actix-web/src/extract.rs:5:33: 5:37 (#33) }, Punct { ch: ';', spacing: Alone, span: $DIR/actix-web/src/extract.rs:5:37: 5:38 (#33) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actix-web-2.0.0/src/extract.rs:5:21: 5:27 (#38) }, Ident { ident: "Three", span: $DIR/actix-web-2.0.0/src/extract.rs:5:28: 5:33 (#38) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:62:21: 62:24 (#0) }], span: $DIR/actix-web-2.0.0/src/extract.rs:5:33: 5:37 (#38) }, Punct { ch: ';', spacing: Alone, span: $DIR/actix-web-2.0.0/src/extract.rs:5:37: 5:38 (#38) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actori-web/src/extract.rs:5:21: 5:27 (#43) }, Ident { ident: "Four", span: $DIR/actori-web/src/extract.rs:5:28: 5:32 (#43) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:70:21: 70:24 (#0) }], span: $DIR/actori-web/src/extract.rs:5:33: 5:35 (#43) }], span: $DIR/actori-web/src/extract.rs:5:32: 5:36 (#43) }, Punct { ch: ';', spacing: Alone, span: $DIR/actori-web/src/extract.rs:5:36: 5:37 (#43) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actori-web-2.0.0/src/extract.rs:5:21: 5:27 (#48) }, Ident { ident: "Four", span: $DIR/actori-web-2.0.0/src/extract.rs:5:28: 5:32 (#48) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:77:21: 77:24 (#0) }], span: $DIR/actori-web-2.0.0/src/extract.rs:5:33: 5:35 (#48) }], span: $DIR/actori-web-2.0.0/src/extract.rs:5:32: 5:36 (#48) }, Punct { ch: ';', spacing: Alone, span: $DIR/actori-web-2.0.0/src/extract.rs:5:36: 5:37 (#48) }]
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/js-sys-0.3.40/src/lib.rs:5:21: 5:27 (#53) }, Ident { ident: "Two", span: $DIR/js-sys-0.3.40/src/lib.rs:5:28: 5:31 (#53) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:83:13: 83:16 (#0) }], span: $DIR/js-sys-0.3.40/src/lib.rs:5:32: 5:37 (#53) }], span: $DIR/js-sys-0.3.40/src/lib.rs:5:31: 5:38 (#53) }, Punct { ch: ';', spacing: Alone, span: $DIR/js-sys-0.3.40/src/lib.rs:5:38: 5:39 (#53) }]

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! arrays {
($name:ident) => {
#[my_macro] struct Two($name);
}
}

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! arrays {
($name:ident) => {
#[my_macro] struct Two($name);
}
}

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! arrays {
($name:ident) => {
#[my_macro] struct Two($name);
}
}

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! impl_macros {
($name:ident) => {
#[my_macro] struct One($name);
}
}

View file

@ -1,7 +0,0 @@
// ignore-test this is not a test
macro_rules! impl_macros {
($name:ident) => {
#[my_macro] struct One($name);
}
}

View file

@ -1,14 +1,8 @@
PRINT-BANG INPUT (DISPLAY): A
PRINT-BANG INPUT (DEBUG): TokenStream [
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "A",
span: #0 bytes(503..504),
},
],
span: #4 bytes(370..372),
Ident {
ident: "A",
span: #0 bytes(503..504),
},
]
PRINT-ATTR INPUT (DISPLAY): const A : u8 = 0 ;
@ -17,15 +11,9 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
ident: "const",
span: #4 bytes(416..421),
},
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "A",
span: #0 bytes(503..504),
},
],
span: #4 bytes(422..424),
Ident {
ident: "A",
span: #0 bytes(503..504),
},
Punct {
ch: ':',
@ -59,15 +47,9 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
ident: "struct",
span: #4 bytes(468..474),
},
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "A",
span: #0 bytes(503..504),
},
],
span: #4 bytes(475..477),
Ident {
ident: "A",
span: #0 bytes(503..504),
},
Group {
delimiter: Brace,

View file

@ -35,15 +35,9 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
]
PRINT-BANG INPUT (DISPLAY): SecondStruct
PRINT-BANG INPUT (DEBUG): TokenStream [
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "SecondStruct",
span: $DIR/nested-macro-rules.rs:21:38: 21:50 (#16),
},
],
span: $DIR/auxiliary/nested-macro-rules.rs:9:30: 9:35 (#15),
Ident {
ident: "SecondStruct",
span: $DIR/nested-macro-rules.rs:21:38: 21:50 (#16),
},
]
PRINT-ATTR INPUT (DISPLAY): struct SecondAttrStruct {}
@ -52,15 +46,9 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
ident: "struct",
span: $DIR/auxiliary/nested-macro-rules.rs:10:32: 10:38 (#15),
},
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "SecondAttrStruct",
span: $DIR/nested-macro-rules.rs:21:52: 21:68 (#16),
},
],
span: $DIR/auxiliary/nested-macro-rules.rs:10:39: 10:56 (#15),
Ident {
ident: "SecondAttrStruct",
span: $DIR/nested-macro-rules.rs:21:52: 21:68 (#16),
},
Group {
delimiter: Brace,

View file

@ -1,13 +1,7 @@
First recollected: TokenStream [
Group {
delimiter: None,
stream: TokenStream [
Ident {
ident: "pub",
span: $DIR/nonterminal-recollect-attr.rs:20:11: 20:14 (#0),
},
],
span: $DIR/nonterminal-recollect-attr.rs:14:9: 14:11 (#4),
Ident {
ident: "pub",
span: $DIR/nonterminal-recollect-attr.rs:20:11: 20:14 (#0),
},
Ident {
ident: "struct",