Skip to content

Commit

Permalink
Revert "Properly handle macro_rules"
Browse files Browse the repository at this point in the history
This reverts commit 7e32657.
  • Loading branch information
carbotaniuman committed May 8, 2024
1 parent b1c591d commit aadc436
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 71 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,6 @@ pub enum NonterminalKind {
Lifetime,
Literal,
Meta,
Meta2021,
Path,
Vis,
TT,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_parse/src/parser/nonterminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))?))
Expand Down
12 changes: 0 additions & 12 deletions tests/ui/attributes/unsafe/macro-unsafe-attributes.rs

This file was deleted.

19 changes: 0 additions & 19 deletions tests/ui/attributes/unsafe/macro-unsafe-attributes.stderr

This file was deleted.

0 comments on commit aadc436

Please sign in to comment.