diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-11-23 11:55:16 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-02-21 11:51:56 +1100 |
| commit | 4143b101f9b0949c4bc6db1124f86ef02b1ef7aa (patch) | |
| tree | ccec1e793829bc4ce4095fc02cc647ba8b6f63f2 /compiler/rustc_expand/src | |
| parent | 6a56c3a930733b7e000cc3ec54844b0522a8bd16 (diff) | |
| download | rust-4143b101f9b0949c4bc6db1124f86ef02b1ef7aa.tar.gz rust-4143b101f9b0949c4bc6db1124f86ef02b1ef7aa.zip | |
Use `ThinVec` in various AST types.
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
Diffstat (limited to 'compiler/rustc_expand/src')
| -rw-r--r-- | compiler/rustc_expand/src/base.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/build.rs | 39 |
2 files changed, 26 insertions, 20 deletions
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 00c5fe791f9..22bc90f5cac 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -29,10 +29,11 @@ use rustc_span::source_map::SourceMap; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{BytePos, FileName, Span, DUMMY_SP}; use smallvec::{smallvec, SmallVec}; - +use std::default::Default; use std::iter; use std::path::{Path, PathBuf}; use std::rc::Rc; +use thin_vec::ThinVec; pub(crate) use rustc_span::hygiene::MacroKind; @@ -554,7 +555,7 @@ impl DummyResult { pub fn raw_expr(sp: Span, is_error: bool) -> P<ast::Expr> { P(ast::Expr { id: ast::DUMMY_NODE_ID, - kind: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(Vec::new()) }, + kind: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(ThinVec::new()) }, span: sp, attrs: ast::AttrVec::new(), tokens: None, @@ -570,7 +571,7 @@ impl DummyResult { pub fn raw_ty(sp: Span, is_error: bool) -> P<ast::Ty> { P(ast::Ty { id: ast::DUMMY_NODE_ID, - kind: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(Vec::new()) }, + kind: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(ThinVec::new()) }, span: sp, tokens: None, }) diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 3b73576d184..d1c4102d579 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -5,7 +5,7 @@ use rustc_ast::{attr, token, util::literal}; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::Span; -use thin_vec::ThinVec; +use thin_vec::{thin_vec, ThinVec}; impl<'a> ExtCtxt<'a> { pub fn path(&self, span: Span, strs: Vec<Ident>) -> ast::Path { @@ -284,18 +284,23 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, expr: P<ast::Expr>, - args: Vec<P<ast::Expr>>, + args: ThinVec<P<ast::Expr>>, ) -> P<ast::Expr> { self.expr(span, ast::ExprKind::Call(expr, args)) } - pub fn expr_call_ident(&self, span: Span, id: Ident, args: Vec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_call_ident( + &self, + span: Span, + id: Ident, + args: ThinVec<P<ast::Expr>>, + ) -> P<ast::Expr> { self.expr(span, ast::ExprKind::Call(self.expr_ident(span, id), args)) } pub fn expr_call_global( &self, sp: Span, fn_path: Vec<Ident>, - args: Vec<P<ast::Expr>>, + args: ThinVec<P<ast::Expr>>, ) -> P<ast::Expr> { let pathexpr = self.expr_path(self.path_global(sp, fn_path)); self.expr_call(sp, pathexpr, args) @@ -372,12 +377,12 @@ impl<'a> ExtCtxt<'a> { } /// `[expr1, expr2, ...]` - pub fn expr_array(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_array(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { self.expr(sp, ast::ExprKind::Array(exprs)) } /// `&[expr1, expr2, ...]` - pub fn expr_array_ref(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_array_ref(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { self.expr_addr_of(sp, self.expr_array(sp, exprs)) } @@ -387,14 +392,14 @@ impl<'a> ExtCtxt<'a> { pub fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { let some = self.std_path(&[sym::option, sym::Option, sym::Some]); - self.expr_call_global(sp, some, vec![expr]) + self.expr_call_global(sp, some, thin_vec![expr]) } pub fn expr_none(&self, sp: Span) -> P<ast::Expr> { let none = self.std_path(&[sym::option, sym::Option, sym::None]); self.expr_path(self.path_global(sp, none)) } - pub fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_tuple(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { self.expr(sp, ast::ExprKind::Tup(exprs)) } @@ -402,7 +407,7 @@ impl<'a> ExtCtxt<'a> { self.expr_call_global( span, [sym::std, sym::rt, sym::begin_panic].iter().map(|s| Ident::new(*s, span)).collect(), - vec![self.expr_str(span, msg)], + thin_vec![self.expr_str(span, msg)], ) } @@ -412,7 +417,7 @@ impl<'a> ExtCtxt<'a> { pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); - self.expr_call_global(sp, ok, vec![expr]) + self.expr_call_global(sp, ok, thin_vec![expr]) } pub fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> { @@ -426,12 +431,12 @@ impl<'a> ExtCtxt<'a> { let binding_expr = self.expr_ident(sp, binding_variable); // `Ok(__try_var)` pattern - let ok_pat = self.pat_tuple_struct(sp, ok_path, vec![binding_pat.clone()]); + let ok_pat = self.pat_tuple_struct(sp, ok_path, thin_vec![binding_pat.clone()]); // `Err(__try_var)` (pattern and expression respectively) - let err_pat = self.pat_tuple_struct(sp, err_path.clone(), vec![binding_pat]); + let err_pat = self.pat_tuple_struct(sp, err_path.clone(), thin_vec![binding_pat]); let err_inner_expr = - self.expr_call(sp, self.expr_path(err_path), vec![binding_expr.clone()]); + self.expr_call(sp, self.expr_path(err_path), thin_vec![binding_expr.clone()]); // `return Err(__try_var)` let err_expr = self.expr(sp, ast::ExprKind::Ret(Some(err_inner_expr))); @@ -473,7 +478,7 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, path: ast::Path, - subpats: Vec<P<ast::Pat>>, + subpats: ThinVec<P<ast::Pat>>, ) -> P<ast::Pat> { self.pat(span, PatKind::TupleStruct(None, path, subpats)) } @@ -485,14 +490,14 @@ impl<'a> ExtCtxt<'a> { ) -> P<ast::Pat> { self.pat(span, PatKind::Struct(None, path, field_pats, false)) } - pub fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> { + pub fn pat_tuple(&self, span: Span, pats: ThinVec<P<ast::Pat>>) -> P<ast::Pat> { self.pat(span, PatKind::Tuple(pats)) } pub fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> { let some = self.std_path(&[sym::option, sym::Option, sym::Some]); let path = self.path_global(span, some); - self.pat_tuple_struct(span, path, vec![pat]) + self.pat_tuple_struct(span, path, thin_vec![pat]) } pub fn arm(&self, span: Span, pat: P<ast::Pat>, expr: P<ast::Expr>) -> ast::Arm { @@ -579,7 +584,7 @@ impl<'a> ExtCtxt<'a> { } // `self` is unused but keep it as method for the convenience use. - pub fn fn_decl(&self, inputs: Vec<ast::Param>, output: ast::FnRetTy) -> P<ast::FnDecl> { + pub fn fn_decl(&self, inputs: ThinVec<ast::Param>, output: ast::FnRetTy) -> P<ast::FnDecl> { P(ast::FnDecl { inputs, output }) } |
