Use ForceCollect
in parse_attr_item
.
Instead of a `bool`. Because `ForceCollect` is used in this way everywhere else.
This commit is contained in:
parent
7d7e2a173a
commit
9d908a2877
3 changed files with 17 additions and 12 deletions
|
@ -4,6 +4,7 @@ use crate::errors;
|
||||||
use rustc_ast::attr::mk_attr;
|
use rustc_ast::attr::mk_attr;
|
||||||
use rustc_ast::token;
|
use rustc_ast::token;
|
||||||
use rustc_ast::{self as ast, AttrItem, AttrStyle};
|
use rustc_ast::{self as ast, AttrItem, AttrStyle};
|
||||||
|
use rustc_parse::parser::ForceCollect;
|
||||||
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
|
use rustc_parse::{new_parser_from_source_str, unwrap_or_emit_fatal};
|
||||||
use rustc_session::parse::ParseSess;
|
use rustc_session::parse::ParseSess;
|
||||||
use rustc_span::FileName;
|
use rustc_span::FileName;
|
||||||
|
@ -17,7 +18,8 @@ pub fn inject(krate: &mut ast::Crate, psess: &ParseSess, attrs: &[String]) {
|
||||||
));
|
));
|
||||||
|
|
||||||
let start_span = parser.token.span;
|
let start_span = parser.token.span;
|
||||||
let AttrItem { unsafety, path, args, tokens: _ } = match parser.parse_attr_item(false) {
|
let AttrItem { unsafety, path, args, tokens: _ } =
|
||||||
|
match parser.parse_attr_item(ForceCollect::No) {
|
||||||
Ok(ai) => ai,
|
Ok(ai) => ai,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
err.emit();
|
err.emit();
|
||||||
|
|
|
@ -124,7 +124,7 @@ impl<'a> Parser<'a> {
|
||||||
if this.eat(&token::Not) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
|
if this.eat(&token::Not) { ast::AttrStyle::Inner } else { ast::AttrStyle::Outer };
|
||||||
|
|
||||||
this.expect(&token::OpenDelim(Delimiter::Bracket))?;
|
this.expect(&token::OpenDelim(Delimiter::Bracket))?;
|
||||||
let item = this.parse_attr_item(false)?;
|
let item = this.parse_attr_item(ForceCollect::No)?;
|
||||||
this.expect(&token::CloseDelim(Delimiter::Bracket))?;
|
this.expect(&token::CloseDelim(Delimiter::Bracket))?;
|
||||||
let attr_sp = lo.to(this.prev_token.span);
|
let attr_sp = lo.to(this.prev_token.span);
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ impl<'a> Parser<'a> {
|
||||||
/// PATH
|
/// PATH
|
||||||
/// PATH `=` UNSUFFIXED_LIT
|
/// PATH `=` UNSUFFIXED_LIT
|
||||||
/// The delimiters or `=` are still put into the resulting token stream.
|
/// 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> {
|
pub fn parse_attr_item(&mut self, force_collect: ForceCollect) -> PResult<'a, ast::AttrItem> {
|
||||||
maybe_whole!(self, NtMeta, |attr| attr.into_inner());
|
maybe_whole!(self, NtMeta, |attr| attr.into_inner());
|
||||||
|
|
||||||
let do_parse = |this: &mut Self| {
|
let do_parse = |this: &mut Self| {
|
||||||
|
@ -271,7 +271,10 @@ impl<'a> Parser<'a> {
|
||||||
Ok(ast::AttrItem { unsafety, path, args, tokens: None })
|
Ok(ast::AttrItem { unsafety, path, args, tokens: None })
|
||||||
};
|
};
|
||||||
// Attr items don't have attributes
|
// Attr items don't have attributes
|
||||||
if capture_tokens { self.collect_tokens_no_attrs(do_parse) } else { do_parse(self) }
|
match force_collect {
|
||||||
|
ForceCollect::Yes => self.collect_tokens_no_attrs(do_parse),
|
||||||
|
ForceCollect::No => do_parse(self),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses attributes that appear after the opening of an item. These should
|
/// Parses attributes that appear after the opening of an item. These should
|
||||||
|
@ -344,7 +347,7 @@ impl<'a> Parser<'a> {
|
||||||
let mut expanded_attrs = Vec::with_capacity(1);
|
let mut expanded_attrs = Vec::with_capacity(1);
|
||||||
while self.token.kind != token::Eof {
|
while self.token.kind != token::Eof {
|
||||||
let lo = self.token.span;
|
let lo = self.token.span;
|
||||||
let item = self.parse_attr_item(true)?;
|
let item = self.parse_attr_item(ForceCollect::Yes)?;
|
||||||
expanded_attrs.push((item, lo.to(self.prev_token.span)));
|
expanded_attrs.push((item, lo.to(self.prev_token.span)));
|
||||||
if !self.eat(&token::Comma) {
|
if !self.eat(&token::Comma) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -171,7 +171,7 @@ impl<'a> Parser<'a> {
|
||||||
NonterminalKind::Path => {
|
NonterminalKind::Path => {
|
||||||
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
|
NtPath(P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?))
|
||||||
}
|
}
|
||||||
NonterminalKind::Meta => NtMeta(P(self.parse_attr_item(true)?)),
|
NonterminalKind::Meta => NtMeta(P(self.parse_attr_item(ForceCollect::Yes)?)),
|
||||||
NonterminalKind::Vis => {
|
NonterminalKind::Vis => {
|
||||||
NtVis(P(self
|
NtVis(P(self
|
||||||
.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?))
|
.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue