Skip to content

Commit 2ed280d

Browse files
committed
Use ForceCollect in parse_attr_item.
Instead of a `bool`. Because `ForceCollect` is used in this way everywhere else.
1 parent 7f92392 commit 2ed280d

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

compiler/rustc_builtin_macros/src/cmdline_attrs.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::errors;
44
use rustc_ast::attr::mk_attr;
55
use rustc_ast::token;
66
use rustc_ast::{self as ast, AttrItem, AttrStyle};
7+
use rustc_parse::parser::ForceCollect;
78
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
89
use rustc_session::parse::ParseSess;
910
use rustc_span::FileName;
@@ -17,13 +18,14 @@ pub fn inject(krate: &mut ast::Crate, psess: &ParseSess, attrs: &[String]) {
1718
));
1819

1920
let start_span = parser.token.span;
20-
let AttrItem { unsafety, path, args, tokens: _ } = match parser.parse_attr_item(false) {
21-
Ok(ai) => ai,
22-
Err(err) => {
23-
err.emit();
24-
continue;
25-
}
26-
};
21+
let AttrItem { unsafety, path, args, tokens: _ } =
22+
match parser.parse_attr_item(ForceCollect::No) {
23+
Ok(ai) => ai,
24+
Err(err) => {
25+
err.emit();
26+
continue;
27+
}
28+
};
2729
let end_span = parser.token.span;
2830
if parser.token != token::Eof {
2931
psess.dcx().emit_err(errors::InvalidCrateAttr { span: start_span.to(end_span) });

compiler/rustc_parse/src/parser/attr.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a> Parser<'a> {
124124
if this.eat(&token::Not) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
125125

126126
this.expect(&token::OpenDelim(Delimiter::Bracket))?;
127-
let item = this.parse_attr_item(false)?;
127+
let item = this.parse_attr_item(ForceCollect::No)?;
128128
this.expect(&token::CloseDelim(Delimiter::Bracket))?;
129129
let attr_sp = lo.to(this.prev_token.span);
130130

@@ -248,7 +248,7 @@ impl<'a> Parser<'a> {
248248
/// PATH
249249
/// PATH `=` UNSUFFIXED_LIT
250250
/// The delimiters or `=` are still put into the resulting token stream.
251-
pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, ast::AttrItem> {
251+
pub fn parse_attr_item(&mut self, force_collect: ForceCollect) -> PResult<'a, ast::AttrItem> {
252252
maybe_whole!(self, NtMeta, |attr| attr.into_inner());
253253

254254
let do_parse = |this: &mut Self| {
@@ -271,7 +271,10 @@ impl<'a> Parser<'a> {
271271
Ok(ast::AttrItem { unsafety, path, args, tokens: None })
272272
};
273273
// Attr items don't have attributes
274-
if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) }
274+
match force_collect {
275+
ForceCollect::Yes => self.collect_tokens_no_attrs(do_parse),
276+
ForceCollect::No => do_parse(self),
277+
}
275278
}
276279

277280
/// Parses attributes that appear after the opening of an item. These should
@@ -344,7 +347,7 @@ impl<'a> Parser<'a> {
344347
let mut expanded_attrs = Vec::with_capacity(1);
345348
while self.token.kind != token::Eof {
346349
let lo = self.token.span;
347-
let item = self.parse_attr_item(true)?;
350+
let item = self.parse_attr_item(ForceCollect::Yes)?;
348351
expanded_attrs.push((item, lo.to(self.prev_token.span)));
349352
if !self.eat(&token::Comma) {
350353
break;

compiler/rustc_parse/src/parser/nonterminal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'a> Parser<'a> {
171171
NonterminalKind::Path => {
172172
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
173173
}
174-
NonterminalKind::Meta => NtMeta(P(self.parse_attr_item(true)?)),
174+
NonterminalKind::Meta => NtMeta(P(self.parse_attr_item(ForceCollect::Yes)?)),
175175
NonterminalKind::Vis => {
176176
NtVis(P(self
177177
.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?))

0 commit comments

Comments
 (0)