From a150fc2990bb89d804761f64d2ce3cf497b7fc81 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 1 Apr 2022 23:54:05 +0300 Subject: [PATCH] ast_lowering: Stop wrapping `ident` matchers into groups The lowered forms goes to metadata, for example during encoding of macro definitions --- compiler/rustc_session/src/lib.rs | 1 + compiler/rustc_session/src/utils.rs | 3 +++ .../ui/proc-macro/nested-macro-rules.stdout | 24 +++++-------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 14273b07ebd..3151b025fff 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -1,5 +1,6 @@ #![feature(crate_visibility_modifier)] #![feature(derive_default_enum)] +#![feature(if_let_guard)] #![feature(let_chains)] #![feature(let_else)] #![feature(min_specialization)] diff --git a/compiler/rustc_session/src/utils.rs b/compiler/rustc_session/src/utils.rs index 6a8775bd10b..9a286d94ab8 100644 --- a/compiler/rustc_session/src/utils.rs +++ b/compiler/rustc_session/src/utils.rs @@ -132,6 +132,9 @@ impl<'a> FlattenNonterminals<'a> { pub fn process_token(&mut self, token: Token) -> TokenStream { match token.kind { + token::Interpolated(nt) if let token::NtIdent(ident, is_raw) = *nt => { + TokenTree::Token(Token::new(token::Ident(ident.name, is_raw), ident.span)).into() + } token::Interpolated(nt) => { let tts = (self.nt_to_tokenstream)(&nt, self.parse_sess, self.synthesize_tokens); TokenTree::Delimited( diff --git a/src/test/ui/proc-macro/nested-macro-rules.stdout b/src/test/ui/proc-macro/nested-macro-rules.stdout index fa35e81148b..31113904041 100644 --- a/src/test/ui/proc-macro/nested-macro-rules.stdout +++ b/src/test/ui/proc-macro/nested-macro-rules.stdout @@ -1,14 +1,8 @@ PRINT-BANG INPUT (DISPLAY): FirstStruct PRINT-BANG INPUT (DEBUG): TokenStream [ - Group { - delimiter: None, - stream: TokenStream [ - Ident { - ident: "FirstStruct", - span: $DIR/auxiliary/nested-macro-rules.rs:16:14: 16:25 (#7), - }, - ], - span: $DIR/auxiliary/nested-macro-rules.rs:9:30: 9:35 (#6), + Ident { + ident: "FirstStruct", + span: $DIR/auxiliary/nested-macro-rules.rs:16:14: 16:25 (#7), }, ] PRINT-ATTR INPUT (DISPLAY): struct FirstAttrStruct {} @@ -17,15 +11,9 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ ident: "struct", span: $DIR/auxiliary/nested-macro-rules.rs:10:32: 10:38 (#6), }, - Group { - delimiter: None, - stream: TokenStream [ - Ident { - ident: "FirstAttrStruct", - span: $DIR/auxiliary/nested-macro-rules.rs:16:27: 16:42 (#7), - }, - ], - span: $DIR/auxiliary/nested-macro-rules.rs:10:39: 10:56 (#6), + Ident { + ident: "FirstAttrStruct", + span: $DIR/auxiliary/nested-macro-rules.rs:16:27: 16:42 (#7), }, Group { delimiter: Brace,