diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-03 16:38:34 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-20 22:53:40 +0100 |
| commit | a0d20935cc7dc9057c683bb62a4ba74475f32aa2 (patch) | |
| tree | 6f15df5680ea57750bfa7680ae19f5aff43ae758 | |
| parent | 3d5dbcb44ad3e023e88959da0b301ee382b2f74f (diff) | |
| download | rust-a0d20935cc7dc9057c683bb62a4ba74475f32aa2.tar.gz rust-a0d20935cc7dc9057c683bb62a4ba74475f32aa2.zip | |
introduce 'type AttrVec'
| -rw-r--r-- | src/librustc/hir/lowering.rs | 7 | ||||
| -rw-r--r-- | src/librustc/hir/lowering/expr.rs | 18 | ||||
| -rw-r--r-- | src/librustc/hir/lowering/item.rs | 13 | ||||
| -rw-r--r-- | src/librustc/hir/mod.rs | 7 | ||||
| -rw-r--r-- | src/librustc_interface/util.rs | 7 | ||||
| -rw-r--r-- | src/librustc_parse/parser/diagnostics.rs | 15 | ||||
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 133 | ||||
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 7 | ||||
| -rw-r--r-- | src/librustc_parse/parser/mod.rs | 9 | ||||
| -rw-r--r-- | src/librustc_parse/parser/pat.rs | 11 | ||||
| -rw-r--r-- | src/librustc_parse/parser/path.rs | 3 | ||||
| -rw-r--r-- | src/librustc_parse/parser/stmt.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/attr/mod.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/mut_visit.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax_expand/base.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax_expand/build.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax_expand/placeholders.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax_ext/asm.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax_ext/concat_idents.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/debug.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 5 |
23 files changed, 136 insertions, 176 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 3f8085f2344..6b83788298e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -53,7 +53,6 @@ use crate::util::nodemap::{DefIdMap, NodeMap}; 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; @@ -1205,7 +1204,7 @@ impl<'a> LoweringContext<'a> { 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| { @@ -2751,7 +2750,7 @@ impl<'a> LoweringContext<'a> { /// 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> { @@ -3102,7 +3101,7 @@ impl<'a> LoweringContext<'a> { fn stmt_let_pat( &mut self, - attrs: ThinVec<Attribute>, + attrs: AttrVec, span: Span, init: Option<P<hir::Expr>>, pat: P<hir::Pat>, diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs index f8465baeb13..04031710dc5 100644 --- a/src/librustc/hir/lowering/expr.rs +++ b/src/librustc/hir/lowering/expr.rs @@ -1318,8 +1318,7 @@ impl LoweringContext<'_> { &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) } @@ -1333,7 +1332,7 @@ impl LoweringContext<'_> { 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)) } @@ -1404,7 +1403,7 @@ impl LoweringContext<'_> { 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( @@ -1423,7 +1422,7 @@ impl LoweringContext<'_> { span: Span, ident: Ident, binding: hir::HirId, - attrs: ThinVec<Attribute>, + attrs: AttrVec, ) -> hir::Expr { let expr_path = hir::ExprKind::Path(hir::QPath::Resolved( None, @@ -1459,16 +1458,11 @@ impl LoweringContext<'_> { 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 } } diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs index 46c944fa678..6cae8e2cc04 100644 --- a/src/librustc/hir/lowering/item.rs +++ b/src/librustc/hir/lowering/item.rs @@ -11,7 +11,6 @@ use crate::hir::def_id::DefId; 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; @@ -899,7 +898,7 @@ impl LoweringContext<'_> { /// 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 { @@ -1182,7 +1181,7 @@ impl LoweringContext<'_> { // // 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 { @@ -1226,7 +1225,7 @@ impl LoweringContext<'_> { 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, @@ -1271,7 +1270,7 @@ impl LoweringContext<'_> { let user_body = this.expr_drop_temps( desugared_span, P(user_body), - ThinVec::new(), + AttrVec::new(), ); // As noted above, create the final block like @@ -1288,9 +1287,9 @@ impl LoweringContext<'_> { 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())) }) } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6b354b01518..17f4ec34441 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -20,7 +20,7 @@ use errors::FatalError; 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}; @@ -29,7 +29,6 @@ use syntax::tokenstream::TokenStream; 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}; @@ -1274,7 +1273,7 @@ pub struct Local { 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, @@ -1459,7 +1458,7 @@ pub struct AnonConst { pub struct Expr { pub hir_id: HirId, pub kind: ExprKind, - pub attrs: ThinVec<Attribute>, + pub attrs: AttrVec, pub span: Span, } diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 4d686fc310f..a8800082c9a 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -10,7 +10,6 @@ use rustc_data_structures::jobserver; 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; @@ -24,7 +23,7 @@ use std::ops::DerefMut; 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}; @@ -741,7 +740,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> { 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 { @@ -756,7 +755,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> { 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 { diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index cea17e4d006..16daefd1450 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -4,11 +4,10 @@ use rustc_data_structures::fx::FxHashSet; 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; @@ -32,7 +31,7 @@ pub(super) fn dummy_arg(ident: Ident) -> Param { id: ast::DUMMY_NODE_ID }; Param { - attrs: ThinVec::default(), + attrs: AttrVec::default(), id: ast::DUMMY_NODE_ID, pat, span: ident.span, @@ -164,7 +163,7 @@ impl RecoverQPath for Expr { Self { span: path.span, kind: ExprKind::Path(qself, path), - attrs: ThinVec::new(), + attrs: AttrVec::new(), id: ast::DUMMY_NODE_ID, } } @@ -551,7 +550,7 @@ impl<'a> Parser<'a> { ); 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 { @@ -974,7 +973,7 @@ impl<'a> Parser<'a> { &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>)`. @@ -1005,7 +1004,7 @@ impl<'a> Parser<'a> { None, self.token.span, BlockCheckMode::Default, - ThinVec::new(), + AttrVec::new(), ) } else { self.parse_expr() @@ -1126,7 +1125,7 @@ impl<'a> Parser<'a> { 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()) } } } diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 4edfbc4ec9f..7afa3d665d6 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -4,11 +4,10 @@ use super::pat::{GateOr, PARAM_EXPECTED}; 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; @@ -37,14 +36,14 @@ macro_rules! maybe_whole_expr { 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`. @@ -57,16 +56,16 @@ macro_rules! maybe_whole_expr { #[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 { @@ -103,7 +102,7 @@ impl<'a> Parser<'a> { 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), }, @@ -122,7 +121,7 @@ impl<'a> Parser<'a> { 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)) } @@ -134,7 +133,7 @@ impl<'a> Parser<'a> { #[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()) } @@ -237,7 +236,7 @@ impl<'a> Parser<'a> { }; 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 } @@ -271,9 +270,9 @@ impl<'a> Parser<'a> { 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, @@ -288,7 +287,7 @@ impl<'a> Parser<'a> { 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") @@ -398,7 +397,7 @@ impl<'a> Parser<'a> { /// 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 { @@ -435,10 +434,7 @@ impl<'a> Parser<'a> { } /// 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() @@ -549,7 +545,7 @@ impl<'a> Parser<'a> { 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 @@ -650,7 +646,7 @@ impl<'a> Parser<'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)?; @@ -663,7 +659,7 @@ impl<'a> Parser<'a> { &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 @@ -692,7 +688,7 @@ impl<'a> Parser<'a> { // 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 @@ -705,7 +701,7 @@ impl<'a> Parser<'a> { 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); } @@ -754,7 +750,7 @@ impl<'a> Parser<'a> { 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); } @@ -767,7 +763,7 @@ impl<'a> Parser<'a> { 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) } @@ -791,7 +787,7 @@ impl<'a> Parser<'a> { 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` @@ -801,7 +797,7 @@ impl<'a> Parser<'a> { } 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()) } }) } @@ -820,7 +816,7 @@ impl<'a> Parser<'a> { // // 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; @@ -909,7 +905,7 @@ impl<'a> Parser<'a> { } } - 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) => { @@ -920,7 +916,7 @@ impl<'a> Parser<'a> { } } - 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| { @@ -947,10 +943,7 @@ impl<'a> Parser<'a> { 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(); // `[` @@ -990,7 +983,7 @@ impl<'a> Parser<'a> { 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)?; @@ -1017,11 +1010,7 @@ impl<'a> Parser<'a> { 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) { @@ -1046,7 +1035,7 @@ impl<'a> Parser<'a> { } /// 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` @@ -1076,7 +1065,7 @@ impl<'a> Parser<'a> { } /// 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); @@ -1084,7 +1073,7 @@ impl<'a> Parser<'a> { } /// 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) @@ -1099,7 +1088,7 @@ impl<'a> Parser<'a> { } /// 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); @@ -1307,12 +1296,12 @@ impl<'a> Parser<'a> { 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) } @@ -1324,7 +1313,7 @@ impl<'a> Parser<'a> { 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); @@ -1340,7 +1329,7 @@ impl<'a> Parser<'a> { } /// 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) { @@ -1370,7 +1359,7 @@ impl<'a> Parser<'a> { _ => { // 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())? } }; @@ -1440,7 +1429,7 @@ impl<'a> Parser<'a> { } /// 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()?; @@ -1486,7 +1475,7 @@ impl<'a> Parser<'a> { /// 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)?; @@ -1502,10 +1491,10 @@ impl<'a> Parser<'a> { /// 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())); } } @@ -1514,7 +1503,7 @@ impl<'a> Parser<'a> { &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>` @@ -1556,7 +1545,7 @@ impl<'a> Parser<'a> { &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()?; @@ -1570,7 +1559,7 @@ impl<'a> Parser<'a> { &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); @@ -1589,7 +1578,7 @@ impl<'a> Parser<'a> { } /// 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)?; @@ -1701,11 +1690,7 @@ impl<'a> Parser<'a> { } /// 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) { @@ -1737,7 +1722,7 @@ impl<'a> Parser<'a> { } /// 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(); @@ -1764,7 +1749,7 @@ impl<'a> Parser<'a> { &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()) && ( @@ -1805,7 +1790,7 @@ impl<'a> Parser<'a> { &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(); @@ -1851,9 +1836,9 @@ impl<'a> Parser<'a> { 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, }); @@ -1932,7 +1917,7 @@ impl<'a> Parser<'a> { // 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 { @@ -2009,16 +1994,16 @@ impl<'a> Parser<'a> { 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()) } } diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 0840a1551db..229ca07f13b 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -5,15 +5,14 @@ use crate::maybe_whole; 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; @@ -2095,7 +2094,7 @@ impl<'a> Parser<'a> { }; 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 { diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 07e99cfe012..938c2d89857 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -15,9 +15,8 @@ use crate::{Directory, DirectoryOwnership}; 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}; @@ -1054,8 +1053,8 @@ impl<'a> Parser<'a> { 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 { diff --git a/src/librustc_parse/parser/pat.rs b/src/librustc_parse/parser/pat.rs index 117b92dc9a5..593fb30bb75 100644 --- a/src/librustc_parse/parser/pat.rs +++ b/src/librustc_parse/parser/pat.rs @@ -1,12 +1,11 @@ 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}; @@ -636,7 +635,7 @@ impl<'a> Parser<'a> { 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))) @@ -693,7 +692,7 @@ impl<'a> Parser<'a> { 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)) @@ -731,7 +730,7 @@ impl<'a> Parser<'a> { ) .emit(); - Ok(self.mk_expr(range_span, ExprKind::Err, ThinVec::new())) + Ok(self.mk_expr(range_span, ExprKind::Err, AttrVec::new())) } } @@ -747,7 +746,7 @@ impl<'a> Parser<'a> { (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() } diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs index aeba6dd2f67..802d38e2997 100644 --- a/src/librustc_parse/parser/path.rs +++ b/src/librustc_parse/parser/path.rs @@ -3,7 +3,6 @@ use crate::maybe_whole; 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}; @@ -400,7 +399,7 @@ impl<'a> Parser<'a> { // 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, diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs index 036badfe75d..a0808063116 100644 --- a/src/librustc_parse/parser/stmt.rs +++ b/src/librustc_parse/parser/stmt.rs @@ -7,11 +7,10 @@ use crate::maybe_whole; 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}; @@ -67,10 +66,10 @@ impl<'a> Parser<'a> { } 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| { @@ -104,7 +103,7 @@ impl<'a> Parser<'a> { 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))); } @@ -124,7 +123,7 @@ impl<'a> Parser<'a> { fn parse_stmt_mac( &mut self, lo: Span, - attrs: ThinVec<Attribute>, + attrs: AttrVec, path: ast::Path, legacy_warnings: bool, ) -> PResult<'a, Option<Stmt>> { @@ -169,7 +168,7 @@ impl<'a> Parser<'a> { 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))?; @@ -191,7 +190,7 @@ impl<'a> Parser<'a> { } /// 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)?; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index cf54fd2887a..c1458236788 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -338,7 +338,7 @@ pub enum GenericParamKind { 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, @@ -599,7 +599,7 @@ pub struct FieldPat { /// 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, @@ -911,7 +911,7 @@ pub enum StmtKind { /// 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)] @@ -936,7 +936,7 @@ pub struct Local { /// 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'. @@ -966,7 +966,7 @@ pub struct Arm { /// 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, @@ -1004,7 +1004,7 @@ pub struct Expr { 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. @@ -1961,7 +1961,7 @@ pub struct InlineAsm { /// 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, @@ -2014,7 +2014,7 @@ impl Param { } /// 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, @@ -2332,6 +2332,9 @@ pub struct AttrItem { 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 { diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 13a9ed5f215..ae6d50ba083 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -9,7 +9,7 @@ pub use StabilityLevel::*; 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; @@ -17,7 +17,6 @@ use crate::source_map::{BytePos, Spanned}; 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; @@ -665,7 +664,7 @@ impl HasAttrs for Vec<Attribute> { } } -impl HasAttrs for ThinVec<Attribute> { +impl HasAttrs for AttrVec { fn attrs(&self) -> &[Attribute] { self } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 36173801eae..30fd23ea909 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -24,7 +24,6 @@ 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; diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 2a6cff5971c..1d27f70f5a5 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -11,7 +11,6 @@ use crate::ast::*; 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; @@ -337,7 +336,7 @@ pub fn visit_attrs<T: MutVisitor>(attrs: &mut Vec<Attribute>, vis: &mut T) { } // 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); } diff --git a/src/libsyntax_expand/base.rs b/src/libsyntax_expand/base.rs index 75066a006bf..2ad327e872e 100644 --- a/src/libsyntax_expand/base.rs +++ b/src/libsyntax_expand/base.rs @@ -9,7 +9,6 @@ use syntax::mut_visit::{self, MutVisitor}; 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; @@ -552,7 +551,7 @@ impl DummyResult { 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(), }) } diff --git a/src/libsyntax_expand/build.rs b/src/libsyntax_expand/build.rs index 3d082101c41..4c539cad111 100644 --- a/src/libsyntax_expand/build.rs +++ b/src/libsyntax_expand/build.rs @@ -1,11 +1,10 @@ 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}; @@ -81,7 +80,7 @@ impl<'a> ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, kind, span, - attrs: ThinVec::new(), + attrs: AttrVec::new(), }) } } @@ -190,7 +189,7 @@ impl<'a> ExtCtxt<'a> { init: Some(ex), id: ast::DUMMY_NODE_ID, span: sp, - attrs: ThinVec::new(), + attrs: AttrVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -207,7 +206,7 @@ impl<'a> ExtCtxt<'a> { init: None, id: ast::DUMMY_NODE_ID, span, - attrs: ThinVec::new(), + attrs: AttrVec::new(), }); ast::Stmt { id: ast::DUMMY_NODE_ID, @@ -245,7 +244,7 @@ impl<'a> ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, kind, span, - attrs: ThinVec::new(), + attrs: AttrVec::new(), }) } @@ -304,7 +303,7 @@ impl<'a> ExtCtxt<'a> { expr: e, span, is_shorthand: false, - attrs: ThinVec::new(), + attrs: AttrVec::new(), id: ast::DUMMY_NODE_ID, is_placeholder: false, } @@ -549,7 +548,7 @@ impl<'a> ExtCtxt<'a> { 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, diff --git a/src/libsyntax_expand/placeholders.rs b/src/libsyntax_expand/placeholders.rs index 22e99baae5b..4298e0e74b6 100644 --- a/src/libsyntax_expand/placeholders.rs +++ b/src/libsyntax_expand/placeholders.rs @@ -5,7 +5,6 @@ use syntax::ast; use syntax::source_map::{DUMMY_SP, dummy_spanned}; use syntax::mut_visit::*; use syntax::ptr::P; -use syntax::ThinVec; use smallvec::{smallvec, SmallVec}; @@ -28,7 +27,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId, vis: Option<ast::Visi 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 { @@ -75,7 +74,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId, vis: Option<ast::Visi 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