use errors::Applicability;
use rustc_data_structures::fx::FxHashSet;
use rustc_index::vec::IndexVec;
-use rustc_data_structures::thin_vec::ThinVec;
use rustc_data_structures::sync::Lrc;
use std::collections::BTreeMap;
id: ty.id,
kind: ExprKind::Path(qself.clone(), path.clone()),
span: ty.span,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
};
let ct = self.with_new_scopes(|this| {
/// has no attributes and is not targeted by a `break`.
fn lower_block_expr(&mut self, b: &Block) -> hir::Expr {
let block = self.lower_block(b, false);
- self.expr_block(block, ThinVec::new())
+ self.expr_block(block, AttrVec::new())
}
fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> {
fn stmt_let_pat(
&mut self,
- attrs: ThinVec<Attribute>,
+ attrs: AttrVec,
span: Span,
init: Option<P<hir::Expr>>,
pat: P<hir::Pat>,
&mut self,
span: Span,
expr: P<hir::Expr>,
- attrs: ThinVec<Attribute>
- ) -> hir::Expr {
+ attrs: AttrVec) -> hir::Expr {
self.expr(span, hir::ExprKind::DropTemps(expr), attrs)
}
self.expr(span, hir::ExprKind::Match(arg, arms, source), ThinVec::new())
}
- fn expr_break(&mut self, span: Span, attrs: ThinVec<Attribute>) -> P<hir::Expr> {
+ fn expr_break(&mut self, span: Span, attrs: AttrVec) -> P<hir::Expr> {
let expr_break = hir::ExprKind::Break(self.lower_loop_destination(None), None);
P(self.expr(span, expr_break, attrs))
}
span: Span,
components: &[Symbol],
params: Option<P<hir::GenericArgs>>,
- attrs: ThinVec<Attribute>,
+ attrs: AttrVec,
) -> hir::Expr {
let path = self.std_path(span, components, params, true);
self.expr(
span: Span,
ident: Ident,
binding: hir::HirId,
- attrs: ThinVec<Attribute>,
+ attrs: AttrVec,
) -> hir::Expr {
let expr_path = hir::ExprKind::Path(hir::QPath::Resolved(
None,
self.expr_block(P(blk), ThinVec::new())
}
- pub(super) fn expr_block(&mut self, b: P<hir::Block>, attrs: ThinVec<Attribute>) -> hir::Expr {
+ pub(super) fn expr_block(&mut self, b: P<hir::Block>, attrs: AttrVec) -> hir::Expr {
self.expr(b.span, hir::ExprKind::Block(b, None), attrs)
}
- pub(super) fn expr(
- &mut self,
- span: Span,
- kind: hir::ExprKind,
- attrs: ThinVec<Attribute>
- ) -> hir::Expr {
+ pub(super) fn expr(&mut self, span: Span, kind: hir::ExprKind, attrs: AttrVec) -> hir::Expr {
hir::Expr { hir_id: self.next_id(), kind, span, attrs }
}
use crate::hir::def::{Res, DefKind};
use crate::util::nodemap::NodeMap;
-use rustc_data_structures::thin_vec::ThinVec;
use rustc_target::spec::abi;
use std::collections::BTreeSet;
/// Construct `ExprKind::Err` for the given `span`.
fn expr_err(&mut self, span: Span) -> hir::Expr {
- self.expr(span, hir::ExprKind::Err, ThinVec::new())
+ self.expr(span, hir::ExprKind::Err, AttrVec::new())
}
fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem {
//
// If this is the simple case, this parameter will end up being the same as the
// original parameter, but with a different pattern id.
- let mut stmt_attrs = ThinVec::new();
+ let mut stmt_attrs = AttrVec::new();
stmt_attrs.extend(parameter.attrs.iter().cloned());
let (new_parameter_pat, new_parameter_id) = this.pat_ident(desugared_span, ident);
let new_parameter = hir::Param {
desugared_span, ident, hir::BindingAnnotation::Mutable);
let move_expr = this.expr_ident(desugared_span, ident, new_parameter_id);
let move_stmt = this.stmt_let_pat(
- ThinVec::new(),
+ AttrVec::new(),
desugared_span,
Some(P(move_expr)),
move_pat,
let user_body = this.expr_drop_temps(
desugared_span,
P(user_body),
- ThinVec::new(),
+ AttrVec::new(),
);
// As noted above, create the final block like
statements.into(),
Some(P(user_body)),
);
- this.expr_block(P(body), ThinVec::new())
+ this.expr_block(P(body), AttrVec::new())
});
- (HirVec::from(parameters), this.expr(body_span, async_expr, ThinVec::new()))
+ (HirVec::from(parameters), this.expr(body_span, async_expr, AttrVec::new()))
})
}
use syntax_pos::{Span, DUMMY_SP, MultiSpan};
use syntax::source_map::Spanned;
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
-use syntax::ast::{Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
+use syntax::ast::{AttrVec, Attribute, Label, LitKind, StrStyle, FloatTy, IntTy, UintTy};
pub use syntax::ast::{Mutability, Constness, Unsafety, Movability, CaptureBy};
pub use syntax::ast::{IsAuto, ImplPolarity, BorrowKind};
use syntax::attr::{InlineAttr, OptimizeAttr};
use syntax::util::parser::ExprPrecedence;
use rustc_target::spec::abi::Abi;
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
-use rustc_data_structures::thin_vec::ThinVec;
use rustc_macros::HashStable;
use rustc_serialize::{self, Encoder, Encodable, Decoder, Decodable};
use std::collections::{BTreeSet, BTreeMap};
pub init: Option<P<Expr>>,
pub hir_id: HirId,
pub span: Span,
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
/// desugaring. Otherwise will be `Normal`.
pub source: LocalSource,
pub struct Expr {
pub hir_id: HirId,
pub kind: ExprKind,
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
pub span: Span,
}
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_data_structures::fingerprint::Fingerprint;
-use rustc_data_structures::thin_vec::ThinVec;
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
use rustc_errors::registry::Registry;
use rustc_metadata::dynamic_lib::DynamicLibrary;
use smallvec::SmallVec;
use syntax::ptr::P;
use syntax::mut_visit::{*, MutVisitor, visit_clobber};
-use syntax::ast::BlockCheckMode;
+use syntax::ast::{AttrVec, BlockCheckMode};
use syntax::util::lev_distance::find_best_match_for_name;
use syntax::source_map::{FileLoader, RealFileLoader, SourceMap};
use syntax::symbol::{Symbol, sym};
id: resolver.next_node_id(),
kind: ast::ExprKind::Block(P(b), None),
span: syntax_pos::DUMMY_SP,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
});
ast::Stmt {
kind: ast::ExprKind::Loop(P(empty_block), None),
id: self.resolver.next_node_id(),
span: syntax_pos::DUMMY_SP,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
});
let loop_stmt = ast::Stmt {
use rustc_errors::{self, PResult, Applicability, DiagnosticBuilder, Handler, pluralize};
use rustc_error_codes::*;
use syntax::ast::{self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item};
-use syntax::ast::{ItemKind, Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind, Attribute};
+use syntax::ast::{ItemKind, Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind, AttrVec};
use syntax::token::{self, TokenKind, token_can_begin_expr};
use syntax::print::pprust;
use syntax::ptr::P;
-use syntax::ThinVec;
use syntax::util::parser::AssocOp;
use syntax::struct_span_err;
use syntax_pos::symbol::kw;
id: ast::DUMMY_NODE_ID
};
Param {
- attrs: ThinVec::default(),
+ attrs: AttrVec::default(),
id: ast::DUMMY_NODE_ID,
pat,
span: ident.span,
Self {
span: path.span,
kind: ExprKind::Path(qself, path),
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
id: ast::DUMMY_NODE_ID,
}
}
);
let mk_err_expr = |this: &Self, span| {
- Ok(Some(this.mk_expr(span, ExprKind::Err, ThinVec::new())))
+ Ok(Some(this.mk_expr(span, ExprKind::Err, AttrVec::new())))
};
match lhs.kind {
&mut self,
lo: Span,
await_sp: Span,
- attrs: ThinVec<Attribute>,
+ attrs: AttrVec,
) -> PResult<'a, P<Expr>> {
let (hi, expr, is_question) = if self.token == token::Not {
// Handle `await!(<expr>)`.
None,
self.token.span,
BlockCheckMode::Default,
- ThinVec::new(),
+ AttrVec::new(),
)
} else {
self.parse_expr()
err.emit();
// Recover from parse error, callers expect the closing delim to be consumed.
self.consume_block(delim, ConsumeClosingDelim::Yes);
- self.mk_expr(lo.to(self.prev_span), ExprKind::Err, ThinVec::new())
+ self.mk_expr(lo.to(self.prev_span), ExprKind::Err, AttrVec::new())
}
}
}
use super::diagnostics::Error;
use crate::maybe_recover_from_interpolated_ty_qpath;
-use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::{PResult, Applicability};
-use syntax::ast::{self, DUMMY_NODE_ID, Attribute, AttrStyle, Ident, CaptureBy, BlockCheckMode};
-use syntax::ast::{Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm, Ty, TyKind};
-use syntax::ast::{FunctionRetTy, Param, FnDecl, BinOpKind, BinOp, UnOp, Mac, AnonConst, Field, Lit};
+use syntax::ast::{self, DUMMY_NODE_ID, AttrVec, AttrStyle, Ident, CaptureBy, Field, Lit};
+use syntax::ast::{BlockCheckMode, Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm};
+use syntax::ast::{Ty, TyKind, FunctionRetTy, Param, FnDecl, BinOpKind, BinOp, UnOp, Mac, AnonConst};
use syntax::token::{self, Token, TokenKind};
use syntax::print::pprust;
use syntax::ptr::P;
let path = path.clone();
$p.bump();
return Ok($p.mk_expr(
- $p.token.span, ExprKind::Path(None, path), ThinVec::new()
+ $p.token.span, ExprKind::Path(None, path), AttrVec::new()
));
}
token::NtBlock(block) => {
let block = block.clone();
$p.bump();
return Ok($p.mk_expr(
- $p.token.span, ExprKind::Block(block, None), ThinVec::new()
+ $p.token.span, ExprKind::Block(block, None), AttrVec::new()
));
}
// N.B., `NtIdent(ident)` is normalized to `Ident` in `fn bump`.
#[derive(Debug)]
pub(super) enum LhsExpr {
NotYetParsed,
- AttributesParsed(ThinVec<Attribute>),
+ AttributesParsed(AttrVec),
AlreadyParsed(P<Expr>),
}
-impl From<Option<ThinVec<Attribute>>> for LhsExpr {
+impl From<Option<AttrVec>> for LhsExpr {
/// Converts `Some(attrs)` into `LhsExpr::AttributesParsed(attrs)`
/// and `None` into `LhsExpr::NotYetParsed`.
///
/// This conversion does not allocate.
- fn from(o: Option<ThinVec<Attribute>>) -> Self {
+ fn from(o: Option<AttrVec>) -> Self {
if let Some(attrs) = o {
LhsExpr::AttributesParsed(attrs)
} else {
err.emit();
let sp = self.token.span;
self.bump();
- Ok(self.mk_expr(sp, ExprKind::Err, ThinVec::new()))
+ Ok(self.mk_expr(sp, ExprKind::Err, AttrVec::new()))
}
_ => Err(err),
},
pub(super) fn parse_expr_res(
&mut self,
r: Restrictions,
- already_parsed_attrs: Option<ThinVec<Attribute>>
+ already_parsed_attrs: Option<AttrVec>
) -> PResult<'a, P<Expr>> {
self.with_res(r, |this| this.parse_assoc_expr(already_parsed_attrs))
}
#[inline]
fn parse_assoc_expr(
&mut self,
- already_parsed_attrs: Option<ThinVec<Attribute>>,
+ already_parsed_attrs: Option<AttrVec>,
) -> PResult<'a, P<Expr>> {
self.parse_assoc_expr_with(0, already_parsed_attrs.into())
}
};
let r = self.mk_range(Some(lhs), rhs, limits)?;
- lhs = self.mk_expr(lhs_span.to(rhs_span), r, ThinVec::new());
+ lhs = self.mk_expr(lhs_span.to(rhs_span), r, AttrVec::new());
break
}
AssocOp::Greater | AssocOp::GreaterEqual => {
let ast_op = op.to_ast_binop().unwrap();
let binary = self.mk_binary(source_map::respan(cur_op_span, ast_op), lhs, rhs);
- self.mk_expr(span, binary, ThinVec::new())
+ self.mk_expr(span, binary, AttrVec::new())
}
- AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs), ThinVec::new()),
+ AssocOp::Assign => self.mk_expr(span, ExprKind::Assign(lhs, rhs), AttrVec::new()),
AssocOp::AssignOp(k) => {
let aop = match k {
token::Plus => BinOpKind::Add,
token::Shr => BinOpKind::Shr,
};
let aopexpr = self.mk_assign_op(source_map::respan(cur_op_span, aop), lhs, rhs);
- self.mk_expr(span, aopexpr, ThinVec::new())
+ self.mk_expr(span, aopexpr, AttrVec::new())
}
AssocOp::As | AssocOp::Colon | AssocOp::DotDot | AssocOp::DotDotEq => {
self.bug("AssocOp should have been handled by special case")
/// Parses prefix-forms of range notation: `..expr`, `..`, `..=expr`.
fn parse_prefix_range_expr(
&mut self,
- already_parsed_attrs: Option<ThinVec<Attribute>>
+ already_parsed_attrs: Option<AttrVec>
) -> PResult<'a, P<Expr>> {
// Check for deprecated `...` syntax.
if self.token == token::DotDotDot {
}
/// Parses a prefix-unary-operator expr.
- fn parse_prefix_expr(
- &mut self,
- already_parsed_attrs: Option<ThinVec<Attribute>>
- ) -> PResult<'a, P<Expr>> {
+ fn parse_prefix_expr(&mut self, already_parsed_attrs: Option<AttrVec>) -> PResult<'a, P<Expr>> {
let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?;
let lo = self.token.span;
// Note: when adding new unary operators, don't forget to adjust TokenKind::can_begin_expr()
expr_kind: fn(P<Expr>, P<Ty>) -> ExprKind)
-> PResult<'a, P<Expr>> {
let mk_expr = |this: &mut Self, rhs: P<Ty>| {
- this.mk_expr(lhs_span.to(rhs.span), expr_kind(lhs, rhs), ThinVec::new())
+ this.mk_expr(lhs_span.to(rhs.span), expr_kind(lhs, rhs), AttrVec::new())
};
// Save the state of the parser before parsing type normally, in case there is a
/// Parses `a.b` or `a(13)` or `a[4]` or just `a`.
fn parse_dot_or_call_expr(
&mut self,
- already_parsed_attrs: Option<ThinVec<Attribute>>,
+ already_parsed_attrs: Option<AttrVec>,
) -> PResult<'a, P<Expr>> {
let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?;
&mut self,
e0: P<Expr>,
lo: Span,
- mut attrs: ThinVec<Attribute>,
+ mut attrs: 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
// expr?
while self.eat(&token::Question) {
let hi = self.prev_span;
- e = self.mk_expr(lo.to(hi), ExprKind::Try(e), ThinVec::new());
+ e = self.mk_expr(lo.to(hi), ExprKind::Try(e), AttrVec::new());
}
// expr.f
let span = self.token.span;
self.bump();
let field = ExprKind::Field(e, Ident::new(symbol, span));
- e = self.mk_expr(lo.to(span), field, ThinVec::new());
+ e = self.mk_expr(lo.to(span), field, AttrVec::new());
self.expect_no_suffix(span, "a tuple index", suffix);
}
let seq = self.parse_paren_expr_seq().map(|es| {
let nd = self.mk_call(e, es);
let hi = self.prev_span;
- self.mk_expr(lo.to(hi), nd, ThinVec::new())
+ self.mk_expr(lo.to(hi), nd, AttrVec::new())
});
e = self.recover_seq_parse_error(token::Paren, lo, seq);
}
hi = self.token.span;
self.expect(&token::CloseDelim(token::Bracket))?;
let index = self.mk_index(e, ix);
- e = self.mk_expr(lo.to(hi), index, ThinVec::new())
+ e = self.mk_expr(lo.to(hi), index, AttrVec::new())
}
_ => return Ok(e)
}
args.insert(0, self_arg);
let span = lo.to(self.prev_span);
- self.mk_expr(span, ExprKind::MethodCall(segment, args), ThinVec::new())
+ self.mk_expr(span, ExprKind::MethodCall(segment, args), AttrVec::new())
}
_ => {
// Field access `expr.f`
}
let span = lo.to(self.prev_span);
- self.mk_expr(span, ExprKind::Field(self_arg, segment.ident), ThinVec::new())
+ self.mk_expr(span, ExprKind::Field(self_arg, segment.ident), AttrVec::new())
}
})
}
//
// Therefore, prevent sub-parser from parsing
// attributes by giving them a empty "already-parsed" list.
- let attrs = ThinVec::new();
+ let attrs = AttrVec::new();
// Note: when adding new syntax here, don't forget to adjust `TokenKind::can_begin_expr()`.
let lo = self.token.span;
}
}
- fn parse_lit_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_lit_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.token.span;
match self.parse_opt_lit() {
Some(literal) => {
}
}
- fn parse_tuple_parens_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_tuple_parens_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.token.span;
let mut first = true;
let parse_leading_attr_expr = |p: &mut Self| {
self.maybe_recover_from_bad_qpath(expr, true)
}
- fn parse_array_or_repeat_expr(
- &mut self,
- mut attrs: ThinVec<Attribute>,
- ) -> PResult<'a, P<Expr>> {
+ fn parse_array_or_repeat_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.token.span;
self.bump(); // `[`
self.maybe_recover_from_bad_qpath(expr, true)
}
- fn parse_path_start_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_path_start_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.token.span;
let path = self.parse_path(PathStyle::Expr)?;
self.maybe_recover_from_bad_qpath(expr, true)
}
- fn parse_labeled_expr(
- &mut self,
- label: Label,
- attrs: ThinVec<Attribute>,
- ) -> PResult<'a, P<Expr>> {
+ fn parse_labeled_expr(&mut self, label: Label, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = label.ident.span;
self.expect(&token::Colon)?;
if self.eat_keyword(kw::While) {
}
/// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead.
- fn recover_do_catch(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn recover_do_catch(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.token.span;
self.bump(); // `do`
}
/// Parse `"return" expr?`.
- fn parse_return_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_return_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.prev_span;
let kind = ExprKind::Ret(self.parse_expr_opt()?);
let expr = self.mk_expr(lo.to(self.prev_span), kind, attrs);
}
/// Parse `"('label ":")? break expr?`.
- fn parse_break_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_break_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.prev_span;
let label = self.eat_label();
let kind = if self.token != token::OpenDelim(token::Brace)
}
/// Parse `"yield" expr?`.
- fn parse_yield_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_yield_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.prev_span;
let kind = ExprKind::Yield(self.parse_expr_opt()?);
let span = lo.to(self.prev_span);
let lo = self.token.span;
let literal = self.parse_lit()?;
let hi = self.prev_span;
- let expr = self.mk_expr(lo.to(hi), ExprKind::Lit(literal), ThinVec::new());
+ let expr = self.mk_expr(lo.to(hi), ExprKind::Lit(literal), AttrVec::new());
if minus_present {
let minus_hi = self.prev_span;
let unary = self.mk_unary(UnOp::Neg, expr);
- Ok(self.mk_expr(minus_lo.to(minus_hi), unary, ThinVec::new()))
+ Ok(self.mk_expr(minus_lo.to(minus_hi), unary, AttrVec::new()))
} else {
Ok(expr)
}
opt_label: Option<Label>,
lo: Span,
blk_mode: BlockCheckMode,
- outer_attrs: ThinVec<Attribute>,
+ outer_attrs: AttrVec,
) -> PResult<'a, P<Expr>> {
if let Some(label) = opt_label {
self.sess.gated_spans.gate(sym::label_break_value, label.ident.span);
}
/// Parses a closure expression (e.g., `move |args| expr`).
- fn parse_closure_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_closure_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.token.span;
let movability = if self.eat_keyword(kw::Static) {
_ => {
// If an explicit return type is given, require a block to appear (RFC 968).
let body_lo = self.token.span;
- self.parse_block_expr(None, body_lo, BlockCheckMode::Default, ThinVec::new())?
+ self.parse_block_expr(None, body_lo, BlockCheckMode::Default, AttrVec::new())?
}
};
}
/// Parses an `if` expression (`if` token already eaten).
- fn parse_if_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_if_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.prev_span;
let cond = self.parse_cond_expr()?;
/// Parses a `let $pat = $expr` pseudo-expression.
/// The `let` token has already been eaten.
- fn parse_let_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_let_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
let lo = self.prev_span;
let pat = self.parse_top_pat(GateOr::No)?;
self.expect(&token::Eq)?;
/// Parses an `else { ... }` expression (`else` token already eaten).
fn parse_else_expr(&mut self) -> PResult<'a, P<Expr>> {
if self.eat_keyword(kw::If) {
- return self.parse_if_expr(ThinVec::new());
+ return self.parse_if_expr(AttrVec::new());
} else {
let blk = self.parse_block()?;
- return Ok(self.mk_expr(blk.span, ExprKind::Block(blk, None), ThinVec::new()));
+ return Ok(self.mk_expr(blk.span, ExprKind::Block(blk, None), AttrVec::new()));
}
}
&mut self,
opt_label: Option<Label>,
span_lo: Span,
- mut attrs: ThinVec<Attribute>
+ mut attrs: AttrVec
) -> PResult<'a, P<Expr>> {
// Parse: `for <src_pat> in <src_expr> <src_loop_block>`
&mut self,
opt_label: Option<Label>,
span_lo: Span,
- mut attrs: ThinVec<Attribute>
+ mut attrs: AttrVec
) -> PResult<'a, P<Expr>> {
let cond = self.parse_cond_expr()?;
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
&mut self,
opt_label: Option<Label>,
span_lo: Span,
- mut attrs: ThinVec<Attribute>
+ mut attrs: AttrVec
) -> PResult<'a, P<Expr>> {
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
attrs.extend(iattrs);
}
/// Parses a `match ... { ... }` expression (`match` token already eaten).
- fn parse_match_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_match_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
let match_span = self.prev_span;
let lo = self.prev_span;
let discriminant = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
}
/// Parses a `try {...}` expression (`try` token already eaten).
- fn parse_try_block(
- &mut self,
- span_lo: Span,
- mut attrs: ThinVec<Attribute>
- ) -> PResult<'a, P<Expr>> {
+ fn parse_try_block(&mut self, span_lo: Span, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
attrs.extend(iattrs);
if self.eat_keyword(kw::Catch) {
}
/// Parses an `async move? {...}` expression.
- fn parse_async_block(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_async_block(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
let span_lo = self.token.span;
self.expect_keyword(kw::Async)?;
let capture_clause = self.parse_capture_clause();
&mut self,
lo: Span,
path: &ast::Path,
- attrs: &ThinVec<Attribute>,
+ attrs: &AttrVec,
) -> Option<PResult<'a, P<Expr>>> {
let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL);
let certainly_not_a_block = || self.look_ahead(1, |t| t.is_ident()) && (
&mut self,
lo: Span,
pth: ast::Path,
- mut attrs: ThinVec<Attribute>
+ mut attrs: AttrVec
) -> PResult<'a, P<Expr>> {
let struct_sp = lo.to(self.prev_span);
self.bump();
recovery_field = Some(ast::Field {
ident: Ident::new(name, self.token.span),
span: self.token.span,
- expr: self.mk_expr(self.token.span, ExprKind::Err, ThinVec::new()),
+ expr: self.mk_expr(self.token.span, ExprKind::Err, AttrVec::new()),
is_shorthand: false,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
id: DUMMY_NODE_ID,
is_placeholder: false,
});
// Mimic `x: x` for the `x` field shorthand.
let path = ast::Path::from_ident(fieldname);
- let expr = self.mk_expr(fieldname.span, ExprKind::Path(None, path), ThinVec::new());
+ let expr = self.mk_expr(fieldname.span, ExprKind::Path(None, path), AttrVec::new());
(fieldname, expr, true)
};
Ok(ast::Field {
fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
let span = lo.to(self.prev_span);
- let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), ThinVec::new());
+ let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), AttrVec::new());
self.recover_from_await_method_call();
Ok(await_expr)
}
- crate fn mk_expr(&self, span: Span, kind: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
+ crate fn mk_expr(&self, span: Span, kind: ExprKind, attrs: AttrVec) -> P<Expr> {
P(Expr { kind, span, attrs, id: DUMMY_NODE_ID })
}
pub(super) fn mk_expr_err(&self, span: Span) -> P<Expr> {
- self.mk_expr(span, ExprKind::Err, ThinVec::new())
+ self.mk_expr(span, ExprKind::Err, AttrVec::new())
}
}
use rustc_errors::{PResult, Applicability, DiagnosticBuilder, StashKey};
use rustc_error_codes::*;
-use syntax::ast::{self, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, AnonConst, Item};
-use syntax::ast::{AssocItem, AssocItemKind, ItemKind, UseTree, UseTreeKind};
+use syntax::ast::{self, DUMMY_NODE_ID, Ident, AttrVec, Attribute, AttrKind, AttrStyle, AnonConst};
+use syntax::ast::{AssocItem, AssocItemKind, Item, ItemKind, UseTree, UseTreeKind};
use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness, Extern, StrLit};
use syntax::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind};
use syntax::ast::{Ty, TyKind, Generics, TraitRef, EnumDef, Variant, VariantData, StructField};
use syntax::ast::{Mac, MacArgs, MacDelimiter, Block, BindingMode, FnDecl, FnSig, SelfKind, Param};
use syntax::print::pprust;
use syntax::ptr::P;
-use syntax::ThinVec;
use syntax::token;
use syntax::tokenstream::{DelimSpan, TokenTree, TokenStream};
use syntax::struct_span_err;
};
let eself = source_map::respan(eself_lo.to(eself_hi), eself);
- Ok(Some(Param::from_self(ThinVec::default(), eself, eself_ident)))
+ Ok(Some(Param::from_self(AttrVec::default(), eself, eself_ident)))
}
fn is_named_param(&self) -> bool {
use crate::lexer::UnmatchedBrace;
use rustc_errors::{PResult, Applicability, DiagnosticBuilder, FatalError};
-use rustc_data_structures::thin_vec::ThinVec;
-use syntax::ast::{self, DUMMY_NODE_ID, AttrStyle, Attribute, CrateSugar, Extern, Ident, StrLit};
-use syntax::ast::{IsAsync, MacArgs, MacDelimiter, Mutability, Visibility, VisibilityKind, Unsafety};
+use syntax::ast::{self, DUMMY_NODE_ID, AttrVec, AttrStyle, CrateSugar, Extern, Ident, Unsafety};
+use syntax::ast::{StrLit, IsAsync, MacArgs, MacDelimiter, Mutability, Visibility, VisibilityKind};
use syntax::print::pprust;
use syntax::ptr::P;
use syntax::token::{self, Token, TokenKind, DelimToken};
fn parse_or_use_outer_attributes(
&mut self,
- already_parsed_attrs: Option<ThinVec<Attribute>>,
- ) -> PResult<'a, ThinVec<Attribute>> {
+ already_parsed_attrs: Option<AttrVec>,
+ ) -> PResult<'a, AttrVec> {
if let Some(attrs) = already_parsed_attrs {
Ok(attrs)
} else {
use super::{Parser, PathStyle};
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
use rustc_errors::{PResult, Applicability, DiagnosticBuilder};
-use syntax::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
+use syntax::ast::{self, AttrVec, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
use syntax::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
use syntax::mut_visit::{noop_visit_pat, noop_visit_mac, MutVisitor};
use syntax::ptr::P;
use syntax::print::pprust;
-use syntax::ThinVec;
use syntax::token;
use syntax_pos::source_map::{respan, Span, Spanned};
use syntax_pos::symbol::{kw, sym};
let op_span = self.token.span;
// Parse range
let span = lo.to(self.prev_span);
- let begin = self.mk_expr(span, ExprKind::Path(qself, path), ThinVec::new());
+ let begin = self.mk_expr(span, ExprKind::Path(qself, path), AttrVec::new());
self.bump();
let end = self.parse_pat_range_end_opt(&begin, form)?;
Ok(PatKind::Range(begin, end, respan(op_span, end_kind)))
let lo = self.prev_span;
let end = self.parse_pat_range_end()?;
let range_span = lo.to(end.span);
- let begin = self.mk_expr(range_span, ExprKind::Err, ThinVec::new());
+ let begin = self.mk_expr(range_span, ExprKind::Err, AttrVec::new());
self.diagnostic()
.struct_span_err(range_span, &format!("`{}X` range patterns are not supported", form))
)
.emit();
- Ok(self.mk_expr(range_span, ExprKind::Err, ThinVec::new()))
+ Ok(self.mk_expr(range_span, ExprKind::Err, AttrVec::new()))
}
}
(None, self.parse_path(PathStyle::Expr)?)
};
let hi = self.prev_span;
- Ok(self.mk_expr(lo.to(hi), ExprKind::Path(qself, path), ThinVec::new()))
+ Ok(self.mk_expr(lo.to(hi), ExprKind::Path(qself, path), AttrVec::new()))
} else {
self.parse_literal_maybe_minus()
}
use rustc_errors::{PResult, Applicability, pluralize};
use syntax::ast::{self, QSelf, Path, PathSegment, Ident, ParenthesizedArgs, AngleBracketedArgs};
use syntax::ast::{AnonConst, GenericArg, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode};
-use syntax::ThinVec;
use syntax::token::{self, Token};
use syntax_pos::source_map::{Span, BytePos};
use syntax_pos::symbol::{kw, sym};
// Parse const argument.
let expr = if let token::OpenDelim(token::Brace) = self.token.kind {
self.parse_block_expr(
- None, self.token.span, BlockCheckMode::Default, ThinVec::new()
+ None, self.token.span, BlockCheckMode::Default, ast::AttrVec::new()
)?
} else if self.token.is_ident() {
// FIXME(const_generics): to distinguish between idents for types and consts,
use crate::DirectoryOwnership;
use rustc_errors::{PResult, Applicability};
-use syntax::ThinVec;
use syntax::ptr::P;
use syntax::ast;
use syntax::ast::{DUMMY_NODE_ID, Stmt, StmtKind, Local, Block, BlockCheckMode, Expr, ExprKind};
-use syntax::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac};
+use syntax::ast::{AttrVec, Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac};
use syntax::util::classify;
use syntax::token;
use syntax_pos::source_map::{respan, Span};
}
let expr = if self.check(&token::OpenDelim(token::Brace)) {
- self.parse_struct_expr(lo, path, ThinVec::new())?
+ self.parse_struct_expr(lo, path, AttrVec::new())?
} else {
let hi = self.prev_span;
- self.mk_expr(lo.to(hi), ExprKind::Path(None, path), ThinVec::new())
+ self.mk_expr(lo.to(hi), ExprKind::Path(None, path), AttrVec::new())
};
let expr = self.with_res(Restrictions::STMT_EXPR, |this| {
let kind = StmtKind::Semi(self.mk_expr(
lo.to(last_semi),
ExprKind::Tup(Vec::new()),
- ThinVec::new()
+ AttrVec::new()
));
return Ok(Some(self.mk_stmt(lo.to(last_semi), kind)));
}
fn parse_stmt_mac(
&mut self,
lo: Span,
- attrs: ThinVec<Attribute>,
+ attrs: AttrVec,
path: ast::Path,
legacy_warnings: bool,
) -> PResult<'a, Option<Stmt>> {
StmtKind::Mac(P((mac, style, attrs)))
} else {
// Since none of the above applied, this is an expression statement macro.
- let e = self.mk_expr(lo.to(hi), ExprKind::Mac(mac), ThinVec::new());
+ let e = self.mk_expr(lo.to(hi), ExprKind::Mac(mac), AttrVec::new());
let e = self.maybe_recover_from_bad_qpath(e, true)?;
let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?;
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
}
/// Parses a local variable declaration.
- fn parse_local(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Local>> {
+ fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> {
let lo = self.prev_span;
let pat = self.parse_top_pat(GateOr::Yes)?;
pub struct GenericParam {
pub id: NodeId,
pub ident: Ident,
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
pub bounds: GenericBounds,
pub is_placeholder: bool,
pub kind: GenericParamKind,
/// The pattern the field is destructured to
pub pat: P<Pat>,
pub is_shorthand: bool,
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub is_placeholder: bool,
/// Expr with a trailing semi-colon.
Semi(P<Expr>),
/// Macro.
- Mac(P<(Mac, MacStmtStyle, ThinVec<Attribute>)>),
+ Mac(P<(Mac, MacStmtStyle, AttrVec)>),
}
#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
/// Initializer expression to set the value, if any.
pub init: Option<P<Expr>>,
pub span: Span,
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
}
/// An arm of a 'match'.
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Field {
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
pub id: NodeId,
pub span: Span,
pub ident: Ident,
pub id: NodeId,
pub kind: ExprKind,
pub span: Span,
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
}
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
/// E.g., `bar: usize` as in `fn foo(bar: usize)`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Param {
- pub attrs: ThinVec<Attribute>,
+ pub attrs: AttrVec,
pub ty: P<Ty>,
pub pat: P<Pat>,
pub id: NodeId,
}
/// Builds a `Param` object from `ExplicitSelf`.
- pub fn from_self(attrs: ThinVec<Attribute>, eself: ExplicitSelf, eself_ident: Ident) -> Param {
+ pub fn from_self(attrs: AttrVec, eself: ExplicitSelf, eself_ident: Ident) -> Param {
let span = eself.span.to(eself_ident.span);
let infer_ty = P(Ty {
id: DUMMY_NODE_ID,
pub args: MacArgs,
}
+/// A list of attributes.
+pub type AttrVec = ThinVec<Attribute>;
+
/// Metadata associated with an item.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Attribute {
pub use crate::ast::Attribute;
use crate::ast;
-use crate::ast::{AttrItem, AttrId, AttrKind, AttrStyle, Name, Ident, Path, PathSegment};
+use crate::ast::{AttrVec, AttrItem, AttrId, AttrKind, AttrStyle, Name, Ident, Path, PathSegment};
use crate::ast::{MacArgs, MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem};
use crate::ast::{Lit, LitKind, Expr, Item, Local, Stmt, StmtKind, GenericParam};
use crate::mut_visit::visit_clobber;
use crate::token::{self, Token};
use crate::ptr::P;
use crate::symbol::{sym, Symbol};
-use crate::ThinVec;
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
use crate::GLOBALS;
}
}
-impl HasAttrs for ThinVec<Attribute> {
+impl HasAttrs for AttrVec {
fn attrs(&self) -> &[Attribute] {
self
}
pub use errors;
use rustc_data_structures::sync::Lock;
use rustc_index::bit_set::GrowableBitSet;
-pub use rustc_data_structures::thin_vec::ThinVec;
use ast::AttrId;
use syntax_pos::edition::Edition;
use crate::source_map::{Spanned, respan};
use crate::token::{self, Token};
use crate::ptr::P;
-use crate::ThinVec;
use crate::tokenstream::*;
use crate::util::map_in_place::MapInPlace;
}
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
-pub fn visit_thin_attrs<T: MutVisitor>(attrs: &mut ThinVec<Attribute>, vis: &mut T) {
+pub fn visit_thin_attrs<T: MutVisitor>(attrs: &mut AttrVec, vis: &mut T) {
for attr in attrs.iter_mut() {
vis.visit_attribute(attr);
}
use syntax::ptr::P;
use syntax::sess::ParseSess;
use syntax::symbol::{kw, sym, Ident, Symbol};
-use syntax::ThinVec;
use syntax::token;
use syntax::tokenstream::{self, TokenStream};
use syntax::visit::Visitor;
id: ast::DUMMY_NODE_ID,
kind: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(Vec::new()) },
span: sp,
- attrs: ThinVec::new(),
+ attrs: ast::AttrVec::new(),
})
}
use crate::base::ExtCtxt;
-use syntax::ast::{self, Ident, Expr, BlockCheckMode, UnOp, PatKind};
+use syntax::ast::{self, AttrVec, Ident, Expr, BlockCheckMode, UnOp, PatKind};
use syntax::attr;
use syntax::source_map::{respan, Spanned};
use syntax::ptr::P;
use syntax::symbol::{kw, sym, Symbol};
-use syntax::ThinVec;
use syntax_pos::{Pos, Span};
id: ast::DUMMY_NODE_ID,
kind,
span,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
})
}
}
init: Some(ex),
id: ast::DUMMY_NODE_ID,
span: sp,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
});
ast::Stmt {
id: ast::DUMMY_NODE_ID,
init: None,
id: ast::DUMMY_NODE_ID,
span,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
});
ast::Stmt {
id: ast::DUMMY_NODE_ID,
id: ast::DUMMY_NODE_ID,
kind,
span,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
})
}
expr: e,
span,
is_shorthand: false,
- attrs: ThinVec::new(),
+ attrs: AttrVec::new(),
id: ast::DUMMY_NODE_ID,
is_placeholder: false,
}
pub fn param(&self, span: Span, ident: ast::Ident, ty: P<ast::Ty>) -> ast::Param {
let arg_pat = self.pat_ident(span, ident);
ast::Param {
- attrs: ThinVec::default(),
+ attrs: AttrVec::default(),
id: ast::DUMMY_NODE_ID,
pat: arg_pat,
span,
use syntax::source_map::{DUMMY_SP, dummy_spanned};
use syntax::mut_visit::*;
use syntax::ptr::P;
-use syntax::ThinVec;
use smallvec::{smallvec, SmallVec};
let span = DUMMY_SP;
let expr_placeholder = || P(ast::Expr {
id, span,
- attrs: ThinVec::new(),
+ attrs: ast::AttrVec::new(),
kind: ast::ExprKind::Mac(mac_placeholder()),
});
let ty = || P(ast::Ty {
id, span, kind: ast::TyKind::Mac(mac_placeholder()),
})),
AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{
- let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ThinVec::new()));
+ let mac = P((mac_placeholder(), ast::MacStmtStyle::Braces, ast::AttrVec::new()));
ast::Stmt { id, span, kind: ast::StmtKind::Mac(mac) }
}]),
AstFragmentKind::Arms => AstFragment::Arms(smallvec![
use State::*;
use errors::{DiagnosticBuilder, PResult};
-use rustc_data_structures::thin_vec::ThinVec;
use rustc_parse::parser::Parser;
use syntax_expand::base::*;
use syntax_pos::Span;
id: ast::DUMMY_NODE_ID,
kind: ast::ExprKind::InlineAsm(P(inline_asm)),
span: cx.with_def_site_ctxt(sp),
- attrs: ThinVec::new(),
+ attrs: ast::AttrVec::new(),
}))
}
-use rustc_data_structures::thin_vec::ThinVec;
-
use syntax::ast;
use syntax_expand::base::{self, *};
use syntax::token::{self, Token};
id: ast::DUMMY_NODE_ID,
kind: ast::ExprKind::Path(None, ast::Path::from_ident(self.ident)),
span: self.ident.span,
- attrs: ThinVec::new(),
+ attrs: ast::AttrVec::new(),
}))
}
use crate::deriving::generic::*;
use crate::deriving::generic::ty::*;
-use rustc_data_structures::thin_vec::ThinVec;
-
use syntax::ast::{self, Ident};
use syntax::ast::{Expr, MetaItem};
use syntax_expand::base::{Annotatable, ExtCtxt};
init: Some(expr),
id: ast::DUMMY_NODE_ID,
span: sp,
- attrs: ThinVec::new(),
+ attrs: ast::AttrVec::new(),
});
ast::Stmt {
id: ast::DUMMY_NODE_ID,
use std::iter;
use std::vec;
-use rustc_data_structures::thin_vec::ThinVec;
use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
use syntax::ast::{VariantData, GenericParamKind, GenericArg};
use syntax::attr;
let args = {
let self_args = explicit_self.map(|explicit_self| {
let ident = Ident::with_dummy_span(kw::SelfLower).with_span_pos(trait_.span);
- ast::Param::from_self(ThinVec::default(), explicit_self, ident)
+ ast::Param::from_self(ast::AttrVec::default(), explicit_self, ident)
});
let nonself_args = arg_types.into_iter()
.map(|(name, ty)| cx.param(trait_.span, name, ty));
ast::FieldPat {
ident: ident.unwrap(),
is_shorthand: false,
- attrs: ThinVec::new(),
+ attrs: ast::AttrVec::new(),
id: ast::DUMMY_NODE_ID,
span: pat.span.with_ctxt(self.span.ctxt()),
pat,