From aadc436527d88f945ac1e943e308db777c9a31ef Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Wed, 8 May 2024 00:57:53 -0500 Subject: [PATCH] Revert "Properly handle macro_rules" This reverts commit 7e326577e57810048892f0219dde587bf288f742. --- compiler/rustc_ast/src/token.rs | 4 +-- compiler/rustc_expand/src/mbe/macro_rules.rs | 2 +- compiler/rustc_parse/src/parser/attr.rs | 29 ------------------- .../rustc_parse/src/parser/nonterminal.rs | 8 +---- .../unsafe/macro-unsafe-attributes.rs | 12 -------- .../unsafe/macro-unsafe-attributes.stderr | 19 ------------ 6 files changed, 3 insertions(+), 71 deletions(-) delete mode 100644 tests/ui/attributes/unsafe/macro-unsafe-attributes.rs delete mode 100644 tests/ui/attributes/unsafe/macro-unsafe-attributes.stderr diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 54b663bc2aa81..dcdd44c604166 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -883,7 +883,6 @@ pub enum NonterminalKind { Lifetime, Literal, Meta, - Meta2021, Path, Vis, TT, @@ -912,7 +911,7 @@ impl NonterminalKind { sym::ident => NonterminalKind::Ident, sym::lifetime => NonterminalKind::Lifetime, sym::literal => NonterminalKind::Literal, - sym::meta => NonterminalKind::Meta2021, + sym::meta => NonterminalKind::Meta, sym::path => NonterminalKind::Path, sym::vis => NonterminalKind::Vis, sym::tt => NonterminalKind::TT, @@ -932,7 +931,6 @@ impl NonterminalKind { NonterminalKind::Lifetime => sym::lifetime, NonterminalKind::Literal => sym::literal, NonterminalKind::Meta => sym::meta, - NonterminalKind::Meta2021 => sym::meta, NonterminalKind::Path => sym::path, NonterminalKind::Vis => sym::vis, NonterminalKind::TT => sym::tt, diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index f6c3bb09c9948..7099f1b0d3521 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -1358,7 +1358,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { // literals may be of a single token, or two tokens (negative numbers) IsInFollow::Yes } - NonterminalKind::Meta2021 | NonterminalKind::Meta | NonterminalKind::TT => { + NonterminalKind::Meta | NonterminalKind::TT => { // being either a single token or a delimited sequence, tt is // harmless IsInFollow::Yes diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index d24c3fd94175a..c46f9dde92a07 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -250,11 +250,6 @@ impl<'a> Parser<'a> { /// PATH `{` TOKEN_STREAM `}` /// PATH /// PATH `=` UNSUFFIXED_LIT - /// `unsafe` `(` PATH `(` TOKEN_STREAM `)` `)` - /// `unsafe` `(` PATH `[` TOKEN_STREAM `]` `)` - /// `unsafe` `(` PATH `{` TOKEN_STREAM `}` `)` - /// `unsafe` `(` PATH `)` - /// `unsafe` `(` PATH `=` UNSUFFIXED_LIT `)` /// The delimiters or `=` are still put into the resulting token stream. pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, ast::AttrItem> { maybe_whole!(self, NtMeta, |attr| attr.into_inner()); @@ -282,30 +277,6 @@ impl<'a> Parser<'a> { if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) } } - /// Parses an inner part of an attribute (the path and following tokens), disallowing `unsafe()`. - /// The tokens must be either a delimited token stream, or empty token stream, - /// or the "legacy" key-value form. - /// PATH `(` TOKEN_STREAM `)` - /// PATH `[` TOKEN_STREAM `]` - /// PATH `{` TOKEN_STREAM `}` - /// PATH - /// PATH `=` UNSUFFIXED_LIT - /// The delimiters or `=` are still put into the resulting token stream. - pub fn parse_attr_item_no_unsafe( - &mut self, - capture_tokens: bool, - ) -> PResult<'a, ast::AttrItem> { - maybe_whole!(self, NtMeta, |attr| attr.into_inner()); - - let do_parse = |this: &mut Self| { - let path = this.parse_path(PathStyle::Mod)?; - let args = this.parse_attr_args()?; - Ok(ast::AttrItem { unsafety: ast::Unsafe::No, path, args, tokens: None }) - }; - // Attr items don't have attributes - if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) } - } - /// Parses attributes that appear after the opening of an item. These should /// be preceded by an exclamation mark, but we accept and warn about one /// terminated by a semicolon. diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 46d517568228d..73b17353ac90c 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -61,12 +61,7 @@ impl<'a> Parser<'a> { }, _ => false, }, - NonterminalKind::Meta => match &token.kind { - token::PathSep | token::Ident(..) => true, - token::Interpolated(nt) => may_be_ident(&nt.0), - _ => token.is_keyword(kw::Unsafe), - }, - NonterminalKind::Path | NonterminalKind::Meta2021 => match &token.kind { + NonterminalKind::Path | NonterminalKind::Meta => match &token.kind { token::PathSep | token::Ident(..) => true, token::Interpolated(nt) => may_be_ident(&nt.0), _ => false, @@ -175,7 +170,6 @@ impl<'a> Parser<'a> { NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?)) } NonterminalKind::Meta => NtMeta(P(self.parse_attr_item(true)?)), - NonterminalKind::Meta2021 => NtMeta(P(self.parse_attr_item_no_unsafe(true)?)), NonterminalKind::Vis => { NtVis(P(self .collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?)) diff --git a/tests/ui/attributes/unsafe/macro-unsafe-attributes.rs b/tests/ui/attributes/unsafe/macro-unsafe-attributes.rs deleted file mode 100644 index bd32ce0346838..0000000000000 --- a/tests/ui/attributes/unsafe/macro-unsafe-attributes.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(unsafe_attributes)] - -macro_rules! test { - ($meta:meta) => { - #[$meta] - struct Foo; - }; -} - -test!{unsafe(no_mangle)} //~ ERROR: expected identifier, found keyword `unsafe` - //~^ error: cannot find attribute `r#unsafe` in this scope -fn main() {} diff --git a/tests/ui/attributes/unsafe/macro-unsafe-attributes.stderr b/tests/ui/attributes/unsafe/macro-unsafe-attributes.stderr deleted file mode 100644 index c1b66a18924b0..0000000000000 --- a/tests/ui/attributes/unsafe/macro-unsafe-attributes.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: expected identifier, found keyword `unsafe` - --> $DIR/macro-unsafe-attributes.rs:10:7 - | -LL | test!{unsafe(no_mangle)} - | ^^^^^^ expected identifier, found keyword - | -help: escape `unsafe` to use it as an identifier - | -LL | test!{r#unsafe(no_mangle)} - | ++ - -error: cannot find attribute `r#unsafe` in this scope - --> $DIR/macro-unsafe-attributes.rs:10:7 - | -LL | test!{unsafe(no_mangle)} - | ^^^^^^ - -error: aborting due to 2 previous errors -