Skip to content

Commit d919dbe

Browse files
committed
Use maybe_whole! to streamline parse_attr_item.
1 parent b9ead99 commit d919dbe

File tree

1 file changed

+10
-19
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+10
-19
lines changed

compiler/rustc_parse/src/parser/attr.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use crate::errors::{
33
SuffixedLiteralInAttribute,
44
};
55
use crate::fluent_generated as fluent;
6+
use crate::maybe_whole;
67

78
use super::{AttrWrapper, Capturing, FnParseMode, ForceCollect, Parser, PathStyle};
89
use rustc_ast as ast;
910
use rustc_ast::attr;
10-
use rustc_ast::token::{self, Delimiter, Nonterminal};
11+
use rustc_ast::token::{self, Delimiter};
1112
use rustc_errors::{codes::*, Diag, PResult};
1213
use rustc_span::{sym, BytePos, Span};
1314
use thin_vec::ThinVec;
@@ -251,25 +252,15 @@ impl<'a> Parser<'a> {
251252
/// PATH `=` UNSUFFIXED_LIT
252253
/// The delimiters or `=` are still put into the resulting token stream.
253254
pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, ast::AttrItem> {
254-
let item = match &self.token.kind {
255-
token::Interpolated(nt) => match &nt.0 {
256-
Nonterminal::NtMeta(item) => Some(item.clone().into_inner()),
257-
_ => None,
258-
},
259-
_ => None,
255+
maybe_whole!(self, NtMeta, |attr| attr.into_inner());
256+
257+
let do_parse = |this: &mut Self| {
258+
let path = this.parse_path(PathStyle::Mod)?;
259+
let args = this.parse_attr_args()?;
260+
Ok(ast::AttrItem { path, args, tokens: None })
260261
};
261-
Ok(if let Some(item) = item {
262-
self.bump();
263-
item
264-
} else {
265-
let do_parse = |this: &mut Self| {
266-
let path = this.parse_path(PathStyle::Mod)?;
267-
let args = this.parse_attr_args()?;
268-
Ok(ast::AttrItem { path, args, tokens: None })
269-
};
270-
// Attr items don't have attributes
271-
if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) }?
272-
})
262+
// Attr items don't have attributes
263+
if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) }
273264
}
274265

275266
/// Parses attributes that appear after the opening of an item. These should

0 commit comments

Comments
 (0)