Use AttrVec
in more places.
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
This commit is contained in:
parent
650bff80a6
commit
619b8abaa6
49 changed files with 352 additions and 392 deletions
|
@ -62,7 +62,7 @@ pub fn parse_crate_from_file<'a>(input: &Path, sess: &'a ParseSess) -> PResult<'
|
|||
pub fn parse_crate_attrs_from_file<'a>(
|
||||
input: &Path,
|
||||
sess: &'a ParseSess,
|
||||
) -> PResult<'a, Vec<ast::Attribute>> {
|
||||
) -> PResult<'a, ast::AttrVec> {
|
||||
let mut parser = new_parser_from_file(sess, input, None);
|
||||
parser.parse_inner_attributes()
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ pub fn parse_crate_attrs_from_source_str(
|
|||
name: FileName,
|
||||
source: String,
|
||||
sess: &ParseSess,
|
||||
) -> PResult<'_, Vec<ast::Attribute>> {
|
||||
) -> PResult<'_, ast::AttrVec> {
|
||||
new_parser_from_source_str(sess, name, source).parse_inner_attributes()
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ enum OuterAttributeType {
|
|||
impl<'a> Parser<'a> {
|
||||
/// Parses attributes that appear before an item.
|
||||
pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper> {
|
||||
let mut outer_attrs: Vec<ast::Attribute> = Vec::new();
|
||||
let mut outer_attrs = ast::AttrVec::new();
|
||||
let mut just_parsed_doc_comment = false;
|
||||
let start_pos = self.token_cursor.num_next_calls;
|
||||
loop {
|
||||
|
@ -106,7 +106,7 @@ impl<'a> Parser<'a> {
|
|||
break;
|
||||
}
|
||||
}
|
||||
Ok(AttrWrapper::new(outer_attrs.into(), start_pos))
|
||||
Ok(AttrWrapper::new(outer_attrs, start_pos))
|
||||
}
|
||||
|
||||
/// Matches `attribute = # ! [ meta_item ]`.
|
||||
|
@ -283,8 +283,8 @@ impl<'a> Parser<'a> {
|
|||
/// terminated by a semicolon.
|
||||
///
|
||||
/// Matches `inner_attrs*`.
|
||||
pub(crate) fn parse_inner_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
|
||||
let mut attrs: Vec<ast::Attribute> = vec![];
|
||||
pub(crate) fn parse_inner_attributes(&mut self) -> PResult<'a, ast::AttrVec> {
|
||||
let mut attrs = ast::AttrVec::new();
|
||||
loop {
|
||||
let start_pos: u32 = self.token_cursor.num_next_calls.try_into().unwrap();
|
||||
// Only try to parse if it is an inner attribute (has `!`).
|
||||
|
|
|
@ -15,11 +15,11 @@ use std::ops::Range;
|
|||
/// for the attribute target. This allows us to perform cfg-expansion on
|
||||
/// a token stream before we invoke a derive proc-macro.
|
||||
///
|
||||
/// This wrapper prevents direct access to the underlying `Vec<ast::Attribute>`.
|
||||
/// This wrapper prevents direct access to the underlying `ast::AttrVec>`.
|
||||
/// Parsing code can only get access to the underlying attributes
|
||||
/// by passing an `AttrWrapper` to `collect_tokens_trailing_tokens`.
|
||||
/// This makes it difficult to accidentally construct an AST node
|
||||
/// (which stores a `Vec<ast::Attribute>`) without first collecting tokens.
|
||||
/// (which stores an `ast::AttrVec`) without first collecting tokens.
|
||||
///
|
||||
/// This struct has its own module, to ensure that the parser code
|
||||
/// cannot directly access the `attrs` field
|
||||
|
@ -49,9 +49,10 @@ impl AttrWrapper {
|
|||
self.attrs
|
||||
}
|
||||
|
||||
// Prepend `self.attrs` to `attrs`.
|
||||
// FIXME: require passing an NT to prevent misuse of this method
|
||||
pub(crate) fn prepend_to_nt_inner(self, attrs: &mut Vec<Attribute>) {
|
||||
let mut self_attrs: Vec<_> = self.attrs.into();
|
||||
pub(crate) fn prepend_to_nt_inner(self, attrs: &mut AttrVec) {
|
||||
let mut self_attrs = self.attrs.clone();
|
||||
std::mem::swap(attrs, &mut self_attrs);
|
||||
attrs.extend(self_attrs);
|
||||
}
|
||||
|
@ -196,7 +197,7 @@ impl<'a> Parser<'a> {
|
|||
&mut self,
|
||||
attrs: AttrWrapper,
|
||||
force_collect: ForceCollect,
|
||||
f: impl FnOnce(&mut Self, Vec<ast::Attribute>) -> PResult<'a, (R, TrailingToken)>,
|
||||
f: impl FnOnce(&mut Self, ast::AttrVec) -> PResult<'a, (R, TrailingToken)>,
|
||||
) -> PResult<'a, R> {
|
||||
// We only bail out when nothing could possibly observe the collected tokens:
|
||||
// 1. We cannot be force collecting tokens (since force-collecting requires tokens
|
||||
|
@ -212,7 +213,7 @@ impl<'a> Parser<'a> {
|
|||
// or `#[cfg_attr]` attributes.
|
||||
&& !self.capture_cfg
|
||||
{
|
||||
return Ok(f(self, attrs.attrs.into())?.0);
|
||||
return Ok(f(self, attrs.attrs)?.0);
|
||||
}
|
||||
|
||||
let start_token = (self.token.clone(), self.token_spacing);
|
||||
|
@ -222,7 +223,7 @@ impl<'a> Parser<'a> {
|
|||
let prev_capturing = std::mem::replace(&mut self.capture_state.capturing, Capturing::Yes);
|
||||
let replace_ranges_start = self.capture_state.replace_ranges.len();
|
||||
|
||||
let ret = f(self, attrs.attrs.into());
|
||||
let ret = f(self, attrs.attrs);
|
||||
|
||||
self.capture_state.capturing = prev_capturing;
|
||||
|
||||
|
@ -352,7 +353,7 @@ impl<'a> Parser<'a> {
|
|||
// on the captured token stream.
|
||||
if self.capture_cfg
|
||||
&& matches!(self.capture_state.capturing, Capturing::Yes)
|
||||
&& has_cfg_or_cfg_attr(&final_attrs)
|
||||
&& has_cfg_or_cfg_attr(final_attrs)
|
||||
{
|
||||
let attr_data = AttributesData { attrs: final_attrs.to_vec().into(), tokens };
|
||||
|
||||
|
|
|
@ -2370,7 +2370,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
fn recover_const_param_decl(&mut self, ty_generics: Option<&Generics>) -> Option<GenericArg> {
|
||||
let snapshot = self.create_snapshot_for_diagnostic();
|
||||
let param = match self.parse_const_param(vec![]) {
|
||||
let param = match self.parse_const_param(AttrVec::new()) {
|
||||
Ok(param) => param,
|
||||
Err(err) => {
|
||||
err.cancel();
|
||||
|
|
|
@ -950,15 +950,15 @@ impl<'a> Parser<'a> {
|
|||
&mut self,
|
||||
e0: P<Expr>,
|
||||
lo: Span,
|
||||
mut attrs: Vec<ast::Attribute>,
|
||||
mut attrs: ast::AttrVec,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
// Stitch the list of outer attributes onto the return value.
|
||||
// A little bit ugly, but the best way given the current code
|
||||
// structure
|
||||
self.parse_dot_or_call_expr_with_(e0, lo).map(|expr| {
|
||||
expr.map(|mut expr| {
|
||||
attrs.extend::<Vec<_>>(expr.attrs.into());
|
||||
expr.attrs = attrs.into();
|
||||
attrs.extend(expr.attrs);
|
||||
expr.attrs = attrs;
|
||||
expr
|
||||
})
|
||||
})
|
||||
|
@ -2224,7 +2224,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
Ok((
|
||||
Param {
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
ty,
|
||||
pat,
|
||||
span: lo.to(this.prev_token.span),
|
||||
|
@ -2732,7 +2732,7 @@ impl<'a> Parser<'a> {
|
|||
let span = body.span;
|
||||
return Ok((
|
||||
ast::Arm {
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
pat,
|
||||
guard,
|
||||
body,
|
||||
|
@ -2810,7 +2810,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
Ok((
|
||||
ast::Arm {
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
pat,
|
||||
guard,
|
||||
body: expr,
|
||||
|
@ -3123,7 +3123,7 @@ impl<'a> Parser<'a> {
|
|||
span: lo.to(expr.span),
|
||||
expr,
|
||||
is_shorthand,
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
id: DUMMY_NODE_ID,
|
||||
is_placeholder: false,
|
||||
},
|
||||
|
@ -3219,14 +3219,10 @@ impl<'a> Parser<'a> {
|
|||
await_expr
|
||||
}
|
||||
|
||||
pub(crate) fn mk_expr_with_attrs<A>(&self, span: Span, kind: ExprKind, attrs: A) -> P<Expr>
|
||||
where
|
||||
A: Into<AttrVec>,
|
||||
{
|
||||
P(Expr { kind, span, attrs: attrs.into(), id: DUMMY_NODE_ID, tokens: None })
|
||||
pub(crate) fn mk_expr_with_attrs(&self, span: Span, kind: ExprKind, attrs: AttrVec) -> P<Expr> {
|
||||
P(Expr { kind, span, attrs, id: DUMMY_NODE_ID, tokens: None })
|
||||
}
|
||||
|
||||
// njn: rename
|
||||
pub(crate) fn mk_expr(&self, span: Span, kind: ExprKind) -> P<Expr> {
|
||||
P(Expr { kind, span, attrs: AttrVec::new(), id: DUMMY_NODE_ID, tokens: None })
|
||||
}
|
||||
|
@ -3248,7 +3244,7 @@ impl<'a> Parser<'a> {
|
|||
fn collect_tokens_for_expr(
|
||||
&mut self,
|
||||
attrs: AttrWrapper,
|
||||
f: impl FnOnce(&mut Self, Vec<ast::Attribute>) -> PResult<'a, P<Expr>>,
|
||||
f: impl FnOnce(&mut Self, ast::AttrVec) -> PResult<'a, P<Expr>>,
|
||||
) -> PResult<'a, P<Expr>> {
|
||||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
let res = f(this, attrs)?;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use super::{ForceCollect, Parser, TrailingToken};
|
||||
|
||||
use rustc_ast::token;
|
||||
use rustc_ast::{
|
||||
self as ast, Attribute, GenericBounds, GenericParam, GenericParamKind, WhereClause,
|
||||
};
|
||||
use rustc_ast::{self as ast, AttrVec, GenericBounds, GenericParam, GenericParamKind, WhereClause};
|
||||
use rustc_errors::{Applicability, PResult};
|
||||
use rustc_span::symbol::kw;
|
||||
|
||||
|
@ -26,7 +24,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Matches `typaram = IDENT (`?` unbound)? optbounds ( EQ ty )?`.
|
||||
fn parse_ty_param(&mut self, preceding_attrs: Vec<Attribute>) -> PResult<'a, GenericParam> {
|
||||
fn parse_ty_param(&mut self, preceding_attrs: AttrVec) -> PResult<'a, GenericParam> {
|
||||
let ident = self.parse_ident()?;
|
||||
|
||||
// Parse optional colon and param bounds.
|
||||
|
@ -43,7 +41,7 @@ impl<'a> Parser<'a> {
|
|||
Ok(GenericParam {
|
||||
ident,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
attrs: preceding_attrs.into(),
|
||||
attrs: preceding_attrs,
|
||||
bounds,
|
||||
kind: GenericParamKind::Type { default },
|
||||
is_placeholder: false,
|
||||
|
@ -53,7 +51,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
pub(crate) fn parse_const_param(
|
||||
&mut self,
|
||||
preceding_attrs: Vec<Attribute>,
|
||||
preceding_attrs: AttrVec,
|
||||
) -> PResult<'a, GenericParam> {
|
||||
let const_span = self.token.span;
|
||||
|
||||
|
@ -68,7 +66,7 @@ impl<'a> Parser<'a> {
|
|||
Ok(GenericParam {
|
||||
ident,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
attrs: preceding_attrs.into(),
|
||||
attrs: preceding_attrs,
|
||||
bounds: Vec::new(),
|
||||
kind: GenericParamKind::Const { ty, kw_span: const_span, default },
|
||||
is_placeholder: false,
|
||||
|
@ -109,7 +107,7 @@ impl<'a> Parser<'a> {
|
|||
Some(ast::GenericParam {
|
||||
ident: lifetime.ident,
|
||||
id: lifetime.id,
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
bounds,
|
||||
kind: ast::GenericParamKind::Lifetime,
|
||||
is_placeholder: false,
|
||||
|
|
|
@ -32,7 +32,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
|
||||
fn parse_item_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> {
|
||||
fn parse_item_mod(&mut self, attrs: &mut AttrVec) -> PResult<'a, ItemInfo> {
|
||||
let unsafety = self.parse_unsafety();
|
||||
self.expect_keyword(kw::Mod)?;
|
||||
let id = self.parse_ident()?;
|
||||
|
@ -40,9 +40,9 @@ impl<'a> Parser<'a> {
|
|||
ModKind::Unloaded
|
||||
} else {
|
||||
self.expect(&token::OpenDelim(Delimiter::Brace))?;
|
||||
let (mut inner_attrs, items, inner_span) =
|
||||
let (inner_attrs, items, inner_span) =
|
||||
self.parse_mod(&token::CloseDelim(Delimiter::Brace))?;
|
||||
attrs.append(&mut inner_attrs);
|
||||
attrs.extend(inner_attrs);
|
||||
ModKind::Loaded(items, Inline::Yes, inner_span)
|
||||
};
|
||||
Ok((id, ItemKind::Mod(unsafety, mod_kind)))
|
||||
|
@ -52,7 +52,7 @@ impl<'a> Parser<'a> {
|
|||
pub fn parse_mod(
|
||||
&mut self,
|
||||
term: &TokenKind,
|
||||
) -> PResult<'a, (Vec<Attribute>, Vec<P<Item>>, ModSpans)> {
|
||||
) -> PResult<'a, (AttrVec, Vec<P<Item>>, ModSpans)> {
|
||||
let lo = self.token.span;
|
||||
let attrs = self.parse_inner_attributes()?;
|
||||
|
||||
|
@ -134,7 +134,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
fn parse_item_common_(
|
||||
&mut self,
|
||||
mut attrs: Vec<Attribute>,
|
||||
mut attrs: AttrVec,
|
||||
mac_allowed: bool,
|
||||
attrs_allowed: bool,
|
||||
fn_parse_mode: FnParseMode,
|
||||
|
@ -198,7 +198,7 @@ impl<'a> Parser<'a> {
|
|||
/// Parses one of the items allowed by the flags.
|
||||
fn parse_item_kind(
|
||||
&mut self,
|
||||
attrs: &mut Vec<Attribute>,
|
||||
attrs: &mut AttrVec,
|
||||
macros_allowed: bool,
|
||||
lo: Span,
|
||||
vis: &Visibility,
|
||||
|
@ -534,7 +534,7 @@ impl<'a> Parser<'a> {
|
|||
/// ```
|
||||
fn parse_item_impl(
|
||||
&mut self,
|
||||
attrs: &mut Vec<Attribute>,
|
||||
attrs: &mut AttrVec,
|
||||
defaultness: Defaultness,
|
||||
) -> PResult<'a, ItemInfo> {
|
||||
let unsafety = self.parse_unsafety();
|
||||
|
@ -661,12 +661,12 @@ impl<'a> Parser<'a> {
|
|||
|
||||
fn parse_item_list<T>(
|
||||
&mut self,
|
||||
attrs: &mut Vec<Attribute>,
|
||||
attrs: &mut AttrVec,
|
||||
mut parse_item: impl FnMut(&mut Parser<'a>) -> PResult<'a, Option<Option<T>>>,
|
||||
) -> PResult<'a, Vec<T>> {
|
||||
let open_brace_span = self.token.span;
|
||||
self.expect(&token::OpenDelim(Delimiter::Brace))?;
|
||||
attrs.append(&mut self.parse_inner_attributes()?);
|
||||
attrs.extend(self.parse_inner_attributes()?);
|
||||
|
||||
let mut items = Vec::new();
|
||||
while !self.eat(&token::CloseDelim(Delimiter::Brace)) {
|
||||
|
@ -775,7 +775,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses `unsafe? auto? trait Foo { ... }` or `trait Foo = Bar;`.
|
||||
fn parse_item_trait(&mut self, attrs: &mut Vec<Attribute>, lo: Span) -> PResult<'a, ItemInfo> {
|
||||
fn parse_item_trait(&mut self, attrs: &mut AttrVec, lo: Span) -> PResult<'a, ItemInfo> {
|
||||
let unsafety = self.parse_unsafety();
|
||||
// Parse optional `auto` prefix.
|
||||
let is_auto = if self.eat_keyword(kw::Auto) { IsAuto::Yes } else { IsAuto::No };
|
||||
|
@ -1061,7 +1061,7 @@ impl<'a> Parser<'a> {
|
|||
/// ```
|
||||
fn parse_item_foreign_mod(
|
||||
&mut self,
|
||||
attrs: &mut Vec<Attribute>,
|
||||
attrs: &mut AttrVec,
|
||||
mut unsafety: Unsafe,
|
||||
) -> PResult<'a, ItemInfo> {
|
||||
let abi = self.parse_abi(); // ABI?
|
||||
|
@ -1179,7 +1179,7 @@ impl<'a> Parser<'a> {
|
|||
fn recover_const_impl(
|
||||
&mut self,
|
||||
const_span: Span,
|
||||
attrs: &mut Vec<Attribute>,
|
||||
attrs: &mut AttrVec,
|
||||
defaultness: Defaultness,
|
||||
) -> PResult<'a, ItemInfo> {
|
||||
let impl_span = self.token.span;
|
||||
|
@ -1337,7 +1337,7 @@ impl<'a> Parser<'a> {
|
|||
ident,
|
||||
vis,
|
||||
id: DUMMY_NODE_ID,
|
||||
attrs: variant_attrs.into(),
|
||||
attrs: variant_attrs,
|
||||
data: struct_def,
|
||||
disr_expr,
|
||||
span: vlo.to(this.prev_token.span),
|
||||
|
@ -1494,7 +1494,7 @@ impl<'a> Parser<'a> {
|
|||
ident: None,
|
||||
id: DUMMY_NODE_ID,
|
||||
ty,
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
is_placeholder: false,
|
||||
},
|
||||
TrailingToken::MaybeComma,
|
||||
|
@ -1520,7 +1520,7 @@ impl<'a> Parser<'a> {
|
|||
adt_ty: &str,
|
||||
lo: Span,
|
||||
vis: Visibility,
|
||||
attrs: Vec<Attribute>,
|
||||
attrs: AttrVec,
|
||||
) -> PResult<'a, FieldDef> {
|
||||
let mut seen_comma: bool = false;
|
||||
let a_var = self.parse_name_and_ty(adt_ty, lo, vis, attrs)?;
|
||||
|
@ -1650,7 +1650,7 @@ impl<'a> Parser<'a> {
|
|||
adt_ty: &str,
|
||||
lo: Span,
|
||||
vis: Visibility,
|
||||
attrs: Vec<Attribute>,
|
||||
attrs: AttrVec,
|
||||
) -> PResult<'a, FieldDef> {
|
||||
let name = self.parse_field_ident(adt_ty, lo)?;
|
||||
self.expect_field_ty_separator()?;
|
||||
|
@ -1684,7 +1684,7 @@ impl<'a> Parser<'a> {
|
|||
vis,
|
||||
id: DUMMY_NODE_ID,
|
||||
ty,
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
is_placeholder: false,
|
||||
})
|
||||
}
|
||||
|
@ -1703,7 +1703,7 @@ impl<'a> Parser<'a> {
|
|||
// We use `parse_fn` to get a span for the function
|
||||
let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true };
|
||||
if let Err(mut db) =
|
||||
self.parse_fn(&mut Vec::new(), fn_parse_mode, lo, &inherited_vis)
|
||||
self.parse_fn(&mut AttrVec::new(), fn_parse_mode, lo, &inherited_vis)
|
||||
{
|
||||
db.delay_as_bug();
|
||||
}
|
||||
|
@ -1979,7 +1979,7 @@ impl<'a> Parser<'a> {
|
|||
/// Parse a function starting from the front matter (`const ...`) to the body `{ ... }` or `;`.
|
||||
fn parse_fn(
|
||||
&mut self,
|
||||
attrs: &mut Vec<Attribute>,
|
||||
attrs: &mut AttrVec,
|
||||
fn_parse_mode: FnParseMode,
|
||||
sig_lo: Span,
|
||||
vis: &Visibility,
|
||||
|
@ -2002,7 +2002,7 @@ impl<'a> Parser<'a> {
|
|||
/// or e.g. a block when the function is a provided one.
|
||||
fn parse_fn_body(
|
||||
&mut self,
|
||||
attrs: &mut Vec<Attribute>,
|
||||
attrs: &mut AttrVec,
|
||||
ident: &Ident,
|
||||
sig_hi: &mut Span,
|
||||
req_body: bool,
|
||||
|
@ -2017,7 +2017,7 @@ impl<'a> Parser<'a> {
|
|||
// Include the trailing semicolon in the span of the signature
|
||||
self.expect_semi()?;
|
||||
*sig_hi = self.prev_token.span;
|
||||
(Vec::new(), None)
|
||||
(AttrVec::new(), None)
|
||||
} else if self.check(&token::OpenDelim(Delimiter::Brace)) || self.token.is_whole_block() {
|
||||
self.parse_inner_attrs_and_block().map(|(attrs, body)| (attrs, Some(body)))?
|
||||
} else if self.token.kind == token::Eq {
|
||||
|
@ -2034,7 +2034,7 @@ impl<'a> Parser<'a> {
|
|||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
(Vec::new(), Some(self.mk_block_err(span)))
|
||||
(AttrVec::new(), Some(self.mk_block_err(span)))
|
||||
} else {
|
||||
let expected = if req_body {
|
||||
&[token::OpenDelim(Delimiter::Brace)][..]
|
||||
|
@ -2051,7 +2051,7 @@ impl<'a> Parser<'a> {
|
|||
return Err(err);
|
||||
}
|
||||
}
|
||||
(Vec::new(), None)
|
||||
(AttrVec::new(), None)
|
||||
};
|
||||
attrs.extend(inner_attrs);
|
||||
Ok(body)
|
||||
|
@ -2280,7 +2280,7 @@ impl<'a> Parser<'a> {
|
|||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
// Possibly parse `self`. Recover if we parsed it and it wasn't allowed here.
|
||||
if let Some(mut param) = this.parse_self_param()? {
|
||||
param.attrs = attrs.into();
|
||||
param.attrs = attrs;
|
||||
let res = if first_param { Ok(param) } else { this.recover_bad_self_param(param) };
|
||||
return Ok((res?, TrailingToken::None));
|
||||
}
|
||||
|
@ -2341,14 +2341,7 @@ impl<'a> Parser<'a> {
|
|||
let span = lo.to(this.prev_token.span);
|
||||
|
||||
Ok((
|
||||
Param {
|
||||
attrs: attrs.into(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
is_placeholder: false,
|
||||
pat,
|
||||
span,
|
||||
ty,
|
||||
},
|
||||
Param { attrs, id: ast::DUMMY_NODE_ID, is_placeholder: false, pat, span, ty },
|
||||
TrailingToken::None,
|
||||
))
|
||||
})
|
||||
|
|
|
@ -4,8 +4,8 @@ use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter};
|
||||
use rustc_ast::{
|
||||
self as ast, Attribute, BindingMode, Expr, ExprKind, MacCall, Mutability, Pat, PatField,
|
||||
PatKind, Path, QSelf, RangeEnd, RangeSyntax,
|
||||
self as ast, AttrVec, BindingMode, Expr, ExprKind, MacCall, Mutability, Pat, PatField, PatKind,
|
||||
Path, QSelf, RangeEnd, RangeSyntax,
|
||||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed, PResult};
|
||||
|
@ -1093,7 +1093,7 @@ impl<'a> Parser<'a> {
|
|||
.emit();
|
||||
}
|
||||
|
||||
fn parse_pat_field(&mut self, lo: Span, attrs: Vec<Attribute>) -> PResult<'a, PatField> {
|
||||
fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> {
|
||||
// Check if a colon exists one ahead. This means we're parsing a fieldname.
|
||||
let hi;
|
||||
let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) {
|
||||
|
@ -1134,7 +1134,7 @@ impl<'a> Parser<'a> {
|
|||
ident: fieldname,
|
||||
pat: subpat,
|
||||
is_shorthand,
|
||||
attrs: attrs.into(),
|
||||
attrs,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: lo.to(hi),
|
||||
is_placeholder: false,
|
||||
|
|
|
@ -130,7 +130,7 @@ impl<'a> Parser<'a> {
|
|||
let path = this.parse_path(PathStyle::Expr)?;
|
||||
|
||||
if this.eat(&token::Not) {
|
||||
let stmt_mac = this.parse_stmt_mac(lo, attrs.into(), path)?;
|
||||
let stmt_mac = this.parse_stmt_mac(lo, attrs, path)?;
|
||||
if this.token == token::Semi {
|
||||
return Ok((stmt_mac, TrailingToken::Semi));
|
||||
} else {
|
||||
|
@ -190,7 +190,7 @@ impl<'a> Parser<'a> {
|
|||
// Since none of the above applied, this is an expression statement macro.
|
||||
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac));
|
||||
let e = self.maybe_recover_from_bad_qpath(e)?;
|
||||
let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?;
|
||||
let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?;
|
||||
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
|
||||
StmtKind::Expr(e)
|
||||
};
|
||||
|
@ -229,7 +229,7 @@ impl<'a> Parser<'a> {
|
|||
) -> PResult<'a, Stmt> {
|
||||
self.collect_tokens_trailing_token(attrs, force_collect, |this, attrs| {
|
||||
this.expect_keyword(kw::Let)?;
|
||||
let local = this.parse_local(attrs.into())?;
|
||||
let local = this.parse_local(attrs)?;
|
||||
let trailing = if capture_semi && this.token.kind == token::Semi {
|
||||
TrailingToken::Semi
|
||||
} else {
|
||||
|
@ -241,7 +241,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
fn recover_local_after_let(&mut self, lo: Span, attrs: AttrWrapper) -> PResult<'a, Stmt> {
|
||||
self.collect_tokens_trailing_token(attrs, ForceCollect::No, |this, attrs| {
|
||||
let local = this.parse_local(attrs.into())?;
|
||||
let local = this.parse_local(attrs)?;
|
||||
// FIXME - maybe capture semicolon in recovery?
|
||||
Ok((
|
||||
this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Local(local)),
|
||||
|
@ -509,9 +509,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses a block. Inner attributes are allowed.
|
||||
pub(super) fn parse_inner_attrs_and_block(
|
||||
&mut self,
|
||||
) -> PResult<'a, (Vec<Attribute>, P<Block>)> {
|
||||
pub(super) fn parse_inner_attrs_and_block(&mut self) -> PResult<'a, (AttrVec, P<Block>)> {
|
||||
self.parse_block_common(self.token.span, BlockCheckMode::Default)
|
||||
}
|
||||
|
||||
|
@ -520,8 +518,8 @@ impl<'a> Parser<'a> {
|
|||
&mut self,
|
||||
lo: Span,
|
||||
blk_mode: BlockCheckMode,
|
||||
) -> PResult<'a, (Vec<Attribute>, P<Block>)> {
|
||||
maybe_whole!(self, NtBlock, |x| (Vec::new(), x));
|
||||
) -> PResult<'a, (AttrVec, P<Block>)> {
|
||||
maybe_whole!(self, NtBlock, |x| (AttrVec::new(), x));
|
||||
|
||||
self.maybe_recover_unexpected_block_label();
|
||||
if !self.eat(&token::OpenDelim(Delimiter::Brace)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue