Use ThinVec
in various AST types.
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
This commit is contained in:
parent
6a56c3a930
commit
4143b101f9
52 changed files with 355 additions and 292 deletions
|
@ -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 })
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue