diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-01-30 14:13:27 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-02-21 11:51:56 +1100 |
| commit | b14b7ba5dd13c76834a6a3bcab3f600a1d1b198d (patch) | |
| tree | 9bf5ece6c9b1d0cd6e6f7bbc16f6929c747d4233 /compiler/rustc_builtin_macros/src | |
| parent | 4143b101f9b0949c4bc6db1124f86ef02b1ef7aa (diff) | |
| download | rust-b14b7ba5dd13c76834a6a3bcab3f600a1d1b198d.tar.gz rust-b14b7ba5dd13c76834a6a3bcab3f600a1d1b198d.zip | |
Use `ThinVec` in `ast::Block`.
Diffstat (limited to 'compiler/rustc_builtin_macros/src')
11 files changed, 28 insertions, 28 deletions
diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index df28d75f1d5..ac6697232cb 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -39,7 +39,7 @@ pub fn expand( let span = ecx.with_def_site_ctxt(item.span); // Generate item statements for the allocator methods. - let stmts = vec![generate_handler(ecx, item.ident, span, sig_span)]; + let stmts = thin_vec![generate_handler(ecx, item.ident, span, sig_span)]; // Generate anonymous constant serving as container for the allocator methods. let const_ty = ecx.ty(sig_span, TyKind::Tup(ThinVec::new())); diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index e0c6d7f42d1..b0b4dda16af 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -83,12 +83,12 @@ impl<'cx, 'a> Context<'cx, 'a> { let Self { best_case_captures, capture_decls, cx, local_bind_decls, span, .. } = self; - let mut assert_then_stmts = Vec::with_capacity(2); + let mut assert_then_stmts = ThinVec::with_capacity(2); assert_then_stmts.extend(best_case_captures); assert_then_stmts.push(self.cx.stmt_expr(panic)); let assert_then = self.cx.block(span, assert_then_stmts); - let mut stmts = Vec::with_capacity(4); + let mut stmts = ThinVec::with_capacity(4); stmts.push(initial_imports); stmts.extend(capture_decls.into_iter().map(|c| c.decl)); stmts.extend(local_bind_decls); @@ -389,7 +389,7 @@ impl<'cx, 'a> Context<'cx, 'a> { let local_bind_path = self.cx.expr_path(Path::from_ident(local_bind)); let rslt = if self.is_consumed { let ret = self.cx.stmt_expr(local_bind_path); - self.cx.expr_block(self.cx.block(self.span, vec![try_capture_call, ret])) + self.cx.expr_block(self.cx.block(self.span, thin_vec![try_capture_call, ret])) } else { self.best_case_captures.push(try_capture_call); local_bind_path diff --git a/compiler/rustc_builtin_macros/src/deriving/clone.rs b/compiler/rustc_builtin_macros/src/deriving/clone.rs index bb4d8edfb47..3c1abe02036 100644 --- a/compiler/rustc_builtin_macros/src/deriving/clone.rs +++ b/compiler/rustc_builtin_macros/src/deriving/clone.rs @@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Span; -use thin_vec::thin_vec; +use thin_vec::{thin_vec, ThinVec}; pub fn expand_deriving_clone( cx: &mut ExtCtxt<'_>, @@ -100,7 +100,7 @@ fn cs_clone_simple( substr: &Substructure<'_>, is_union: bool, ) -> BlockOrExpr { - let mut stmts = Vec::new(); + let mut stmts = ThinVec::new(); let mut seen_type_names = FxHashSet::default(); let mut process_variant = |variant: &VariantData| { for field in variant.fields() { diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs index 424719f9795..af971958680 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs @@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_span::symbol::sym; use rustc_span::Span; -use thin_vec::thin_vec; +use thin_vec::{thin_vec, ThinVec}; pub fn expand_deriving_eq( cx: &mut ExtCtxt<'_>, @@ -56,7 +56,7 @@ fn cs_total_eq_assert( trait_span: Span, substr: &Substructure<'_>, ) -> BlockOrExpr { - let mut stmts = Vec::new(); + let mut stmts = ThinVec::new(); let mut seen_type_names = FxHashSet::default(); let mut process_variant = |variant: &ast::VariantData| { for field in variant.fields() { diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index 69f9bf55060..8a341c959ed 100644 --- a/compiler/rustc_builtin_macros/src/deriving/debug.rs +++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs @@ -187,7 +187,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> args.push(cx.expr_ident(span, Ident::new(sym::values, span))); let expr = cx.expr_call_global(span, fn_path_debug_internal, args); - let mut stmts = Vec::with_capacity(3); + let mut stmts = ThinVec::with_capacity(2); if is_struct { stmts.push(names_let.unwrap()); } diff --git a/compiler/rustc_builtin_macros/src/deriving/encodable.rs b/compiler/rustc_builtin_macros/src/deriving/encodable.rs index fe69fa06018..a3b11309d0c 100644 --- a/compiler/rustc_builtin_macros/src/deriving/encodable.rs +++ b/compiler/rustc_builtin_macros/src/deriving/encodable.rs @@ -169,7 +169,7 @@ fn encodable_substructure( Struct(_, fields) => { let fn_emit_struct_field_path = cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct_field]); - let mut stmts = Vec::new(); + let mut stmts = ThinVec::new(); for (i, &FieldInfo { name, ref self_expr, span, .. }) in fields.iter().enumerate() { let name = match name { Some(id) => id.name, @@ -237,7 +237,7 @@ fn encodable_substructure( let fn_emit_enum_variant_arg_path: Vec<_> = cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant_arg]); - let mut stmts = Vec::new(); + let mut stmts = ThinVec::new(); if !fields.is_empty() { let last = fields.len() - 1; for (i, &FieldInfo { ref self_expr, span, .. }) in fields.iter().enumerate() { @@ -293,7 +293,7 @@ fn encodable_substructure( fn_emit_enum_path, thin_vec![encoder, cx.expr_str(trait_span, substr.type_ident.name), blk], ); - BlockOrExpr::new_mixed(vec![me], Some(expr)) + BlockOrExpr::new_mixed(thin_vec![me], Some(expr)) } _ => cx.bug("expected Struct or EnumMatching in derive(Encodable)"), diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index fcd7d7dc08d..31921a0c864 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -328,18 +328,18 @@ struct TypeParameter { /// avoiding the insertion of any unnecessary blocks. /// /// The statements come before the expression. -pub struct BlockOrExpr(Vec<ast::Stmt>, Option<P<Expr>>); +pub struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>); impl BlockOrExpr { - pub fn new_stmts(stmts: Vec<ast::Stmt>) -> BlockOrExpr { + pub fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr { BlockOrExpr(stmts, None) } pub fn new_expr(expr: P<Expr>) -> BlockOrExpr { - BlockOrExpr(vec![], Some(expr)) + BlockOrExpr(ThinVec::new(), Some(expr)) } - pub fn new_mixed(stmts: Vec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr { + pub fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr { BlockOrExpr(stmts, expr) } @@ -355,7 +355,7 @@ impl BlockOrExpr { fn into_expr(self, cx: &ExtCtxt<'_>, span: Span) -> P<Expr> { if self.0.is_empty() { match self.1 { - None => cx.expr_block(cx.block(span, vec![])), + None => cx.expr_block(cx.block(span, ThinVec::new())), Some(expr) => expr, } } else if self.0.len() == 1 @@ -1146,7 +1146,7 @@ impl<'a> MethodDef<'a> { // There is no sensible code to be generated for *any* deriving on a // zero-variant enum. So we just generate a failing expression. if variants.is_empty() { - return BlockOrExpr(vec![], Some(deriving::call_unreachable(cx, span))); + return BlockOrExpr(ThinVec::new(), Some(deriving::call_unreachable(cx, span))); } let prefixes = iter::once("__self".to_string()) @@ -1182,7 +1182,7 @@ impl<'a> MethodDef<'a> { let other_selflike_exprs = tag_exprs; let tag_field = FieldInfo { span, name: None, self_expr, other_selflike_exprs }; - let tag_let_stmts: Vec<_> = iter::zip(&tag_idents, &selflike_args) + let tag_let_stmts: ThinVec<_> = iter::zip(&tag_idents, &selflike_args) .map(|(&ident, selflike_arg)| { let variant_value = deriving::call_intrinsic( cx, @@ -1362,7 +1362,7 @@ impl<'a> MethodDef<'a> { tag_let_stmts.append(&mut tag_check_plus_match.0); BlockOrExpr(tag_let_stmts, tag_check_plus_match.1) } else { - BlockOrExpr(vec![], Some(get_match_expr(selflike_args))) + BlockOrExpr(ThinVec::new(), Some(get_match_expr(selflike_args))) } } @@ -1599,7 +1599,7 @@ impl<'a> TraitDef<'a> { } else { // Wrap the expression in `{...}`, causing a copy. field_expr = cx.expr_block( - cx.block(struct_field.span, vec![cx.stmt_expr(field_expr)]), + cx.block(struct_field.span, thin_vec![cx.stmt_expr(field_expr)]), ); } } diff --git a/compiler/rustc_builtin_macros/src/deriving/hash.rs b/compiler/rustc_builtin_macros/src/deriving/hash.rs index 7660ca6ffd5..4eee573db42 100644 --- a/compiler/rustc_builtin_macros/src/deriving/hash.rs +++ b/compiler/rustc_builtin_macros/src/deriving/hash.rs @@ -72,7 +72,7 @@ fn hash_substructure( } EnumTag(tag_field, match_expr) => { assert!(tag_field.other_selflike_exprs.is_empty()); - let stmts = vec![call_hash(tag_field.span, tag_field.self_expr.clone())]; + let stmts = thin_vec![call_hash(tag_field.span, tag_field.self_expr.clone())]; (stmts, match_expr.clone()) } _ => cx.span_bug(trait_span, "impossible substructure in `derive(Hash)`"), diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index f0fa344d830..d34336e7679 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -6,7 +6,7 @@ use rustc_ast::{GenericArg, Impl, ItemKind, MetaItem}; use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier}; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::Span; -use thin_vec::ThinVec; +use thin_vec::{thin_vec, ThinVec}; macro path_local($x:ident) { generic::ty::Path::new_local(sym::$x) @@ -107,7 +107,7 @@ fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P<ast::Expr> { let call = cx.expr_call_global(span, path, ThinVec::new()); cx.expr_block(P(ast::Block { - stmts: vec![cx.stmt_expr(call)], + stmts: thin_vec![cx.stmt_expr(call)], id: ast::DUMMY_NODE_ID, rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated), span, @@ -212,7 +212,7 @@ fn inject_impl_of_structural_trait( fn assert_ty_bounds( cx: &mut ExtCtxt<'_>, - stmts: &mut Vec<ast::Stmt>, + stmts: &mut ThinVec<ast::Stmt>, ty: P<ast::Ty>, span: Span, assert_path: &[Symbol], diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index 33b238e2c16..bc513607ddd 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -375,7 +375,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> { }); let block = cx.expr_block( - cx.block(span, vec![cx.stmt_item(span, krate), cx.stmt_item(span, decls_static)]), + cx.block(span, thin_vec![cx.stmt_item(span, krate), cx.stmt_item(span, decls_static)]), ); let anon_constant = cx.item_const( diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 9d4233607b7..d8e3db9e8ee 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -317,9 +317,9 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> { // If no test runner is provided we need to import the test crate let main_body = if cx.test_runner.is_none() { - ecx.block(sp, vec![test_extern_stmt, call_test_main]) + ecx.block(sp, thin_vec![test_extern_stmt, call_test_main]) } else { - ecx.block(sp, vec![call_test_main]) + ecx.block(sp, thin_vec![call_test_main]) }; let decl = ecx.fn_decl(ThinVec::new(), ast::FnRetTy::Ty(main_ret_ty)); |
