Skip to content

Commit b14b7ba

Browse files
committed
Use ThinVec in ast::Block.
1 parent 4143b10 commit b14b7ba

File tree

18 files changed

+92
-81
lines changed

18 files changed

+92
-81
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ pub enum NestedMetaItem {
531531
#[derive(Clone, Encodable, Decodable, Debug)]
532532
pub struct Block {
533533
/// The statements in the block.
534-
pub stmts: Vec<Stmt>,
534+
pub stmts: ThinVec<Stmt>,
535535
pub id: NodeId,
536536
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
537537
pub rules: BlockCheckMode,
@@ -3112,7 +3112,7 @@ mod size_asserts {
31123112
static_assert_size!(AssocItem, 104);
31133113
static_assert_size!(AssocItemKind, 32);
31143114
static_assert_size!(Attribute, 32);
3115-
static_assert_size!(Block, 48);
3115+
static_assert_size!(Block, 32);
31163116
static_assert_size!(Expr, 72);
31173117
static_assert_size!(ExprKind, 40);
31183118
static_assert_size!(Fn, 152);

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn expand(
3939
let span = ecx.with_def_site_ctxt(item.span);
4040

4141
// Generate item statements for the allocator methods.
42-
let stmts = vec![generate_handler(ecx, item.ident, span, sig_span)];
42+
let stmts = thin_vec![generate_handler(ecx, item.ident, span, sig_span)];
4343

4444
// Generate anonymous constant serving as container for the allocator methods.
4545
let const_ty = ecx.ty(sig_span, TyKind::Tup(ThinVec::new()));

compiler/rustc_builtin_macros/src/assert/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ impl<'cx, 'a> Context<'cx, 'a> {
8383

8484
let Self { best_case_captures, capture_decls, cx, local_bind_decls, span, .. } = self;
8585

86-
let mut assert_then_stmts = Vec::with_capacity(2);
86+
let mut assert_then_stmts = ThinVec::with_capacity(2);
8787
assert_then_stmts.extend(best_case_captures);
8888
assert_then_stmts.push(self.cx.stmt_expr(panic));
8989
let assert_then = self.cx.block(span, assert_then_stmts);
9090

91-
let mut stmts = Vec::with_capacity(4);
91+
let mut stmts = ThinVec::with_capacity(4);
9292
stmts.push(initial_imports);
9393
stmts.extend(capture_decls.into_iter().map(|c| c.decl));
9494
stmts.extend(local_bind_decls);
@@ -389,7 +389,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
389389
let local_bind_path = self.cx.expr_path(Path::from_ident(local_bind));
390390
let rslt = if self.is_consumed {
391391
let ret = self.cx.stmt_expr(local_bind_path);
392-
self.cx.expr_block(self.cx.block(self.span, vec![try_capture_call, ret]))
392+
self.cx.expr_block(self.cx.block(self.span, thin_vec![try_capture_call, ret]))
393393
} else {
394394
self.best_case_captures.push(try_capture_call);
395395
local_bind_path

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::FxHashSet;
66
use rustc_expand::base::{Annotatable, ExtCtxt};
77
use rustc_span::symbol::{kw, sym, Ident};
88
use rustc_span::Span;
9-
use thin_vec::thin_vec;
9+
use thin_vec::{thin_vec, ThinVec};
1010

1111
pub fn expand_deriving_clone(
1212
cx: &mut ExtCtxt<'_>,
@@ -100,7 +100,7 @@ fn cs_clone_simple(
100100
substr: &Substructure<'_>,
101101
is_union: bool,
102102
) -> BlockOrExpr {
103-
let mut stmts = Vec::new();
103+
let mut stmts = ThinVec::new();
104104
let mut seen_type_names = FxHashSet::default();
105105
let mut process_variant = |variant: &VariantData| {
106106
for field in variant.fields() {

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashSet;
77
use rustc_expand::base::{Annotatable, ExtCtxt};
88
use rustc_span::symbol::sym;
99
use rustc_span::Span;
10-
use thin_vec::thin_vec;
10+
use thin_vec::{thin_vec, ThinVec};
1111

1212
pub fn expand_deriving_eq(
1313
cx: &mut ExtCtxt<'_>,
@@ -56,7 +56,7 @@ fn cs_total_eq_assert(
5656
trait_span: Span,
5757
substr: &Substructure<'_>,
5858
) -> BlockOrExpr {
59-
let mut stmts = Vec::new();
59+
let mut stmts = ThinVec::new();
6060
let mut seen_type_names = FxHashSet::default();
6161
let mut process_variant = |variant: &ast::VariantData| {
6262
for field in variant.fields() {

compiler/rustc_builtin_macros/src/deriving/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
187187
args.push(cx.expr_ident(span, Ident::new(sym::values, span)));
188188
let expr = cx.expr_call_global(span, fn_path_debug_internal, args);
189189

190-
let mut stmts = Vec::with_capacity(3);
190+
let mut stmts = ThinVec::with_capacity(2);
191191
if is_struct {
192192
stmts.push(names_let.unwrap());
193193
}

compiler/rustc_builtin_macros/src/deriving/encodable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn encodable_substructure(
169169
Struct(_, fields) => {
170170
let fn_emit_struct_field_path =
171171
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct_field]);
172-
let mut stmts = Vec::new();
172+
let mut stmts = ThinVec::new();
173173
for (i, &FieldInfo { name, ref self_expr, span, .. }) in fields.iter().enumerate() {
174174
let name = match name {
175175
Some(id) => id.name,
@@ -237,7 +237,7 @@ fn encodable_substructure(
237237
let fn_emit_enum_variant_arg_path: Vec<_> =
238238
cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant_arg]);
239239

240-
let mut stmts = Vec::new();
240+
let mut stmts = ThinVec::new();
241241
if !fields.is_empty() {
242242
let last = fields.len() - 1;
243243
for (i, &FieldInfo { ref self_expr, span, .. }) in fields.iter().enumerate() {
@@ -293,7 +293,7 @@ fn encodable_substructure(
293293
fn_emit_enum_path,
294294
thin_vec![encoder, cx.expr_str(trait_span, substr.type_ident.name), blk],
295295
);
296-
BlockOrExpr::new_mixed(vec![me], Some(expr))
296+
BlockOrExpr::new_mixed(thin_vec![me], Some(expr))
297297
}
298298

299299
_ => cx.bug("expected Struct or EnumMatching in derive(Encodable)"),

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,18 @@ struct TypeParameter {
328328
/// avoiding the insertion of any unnecessary blocks.
329329
///
330330
/// The statements come before the expression.
331-
pub struct BlockOrExpr(Vec<ast::Stmt>, Option<P<Expr>>);
331+
pub struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>);
332332

333333
impl BlockOrExpr {
334-
pub fn new_stmts(stmts: Vec<ast::Stmt>) -> BlockOrExpr {
334+
pub fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr {
335335
BlockOrExpr(stmts, None)
336336
}
337337

338338
pub fn new_expr(expr: P<Expr>) -> BlockOrExpr {
339-
BlockOrExpr(vec![], Some(expr))
339+
BlockOrExpr(ThinVec::new(), Some(expr))
340340
}
341341

342-
pub fn new_mixed(stmts: Vec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr {
342+
pub fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr {
343343
BlockOrExpr(stmts, expr)
344344
}
345345

@@ -355,7 +355,7 @@ impl BlockOrExpr {
355355
fn into_expr(self, cx: &ExtCtxt<'_>, span: Span) -> P<Expr> {
356356
if self.0.is_empty() {
357357
match self.1 {
358-
None => cx.expr_block(cx.block(span, vec![])),
358+
None => cx.expr_block(cx.block(span, ThinVec::new())),
359359
Some(expr) => expr,
360360
}
361361
} else if self.0.len() == 1
@@ -1146,7 +1146,7 @@ impl<'a> MethodDef<'a> {
11461146
// There is no sensible code to be generated for *any* deriving on a
11471147
// zero-variant enum. So we just generate a failing expression.
11481148
if variants.is_empty() {
1149-
return BlockOrExpr(vec![], Some(deriving::call_unreachable(cx, span)));
1149+
return BlockOrExpr(ThinVec::new(), Some(deriving::call_unreachable(cx, span)));
11501150
}
11511151

11521152
let prefixes = iter::once("__self".to_string())
@@ -1182,7 +1182,7 @@ impl<'a> MethodDef<'a> {
11821182
let other_selflike_exprs = tag_exprs;
11831183
let tag_field = FieldInfo { span, name: None, self_expr, other_selflike_exprs };
11841184

1185-
let tag_let_stmts: Vec<_> = iter::zip(&tag_idents, &selflike_args)
1185+
let tag_let_stmts: ThinVec<_> = iter::zip(&tag_idents, &selflike_args)
11861186
.map(|(&ident, selflike_arg)| {
11871187
let variant_value = deriving::call_intrinsic(
11881188
cx,
@@ -1362,7 +1362,7 @@ impl<'a> MethodDef<'a> {
13621362
tag_let_stmts.append(&mut tag_check_plus_match.0);
13631363
BlockOrExpr(tag_let_stmts, tag_check_plus_match.1)
13641364
} else {
1365-
BlockOrExpr(vec![], Some(get_match_expr(selflike_args)))
1365+
BlockOrExpr(ThinVec::new(), Some(get_match_expr(selflike_args)))
13661366
}
13671367
}
13681368

@@ -1599,7 +1599,7 @@ impl<'a> TraitDef<'a> {
15991599
} else {
16001600
// Wrap the expression in `{...}`, causing a copy.
16011601
field_expr = cx.expr_block(
1602-
cx.block(struct_field.span, vec![cx.stmt_expr(field_expr)]),
1602+
cx.block(struct_field.span, thin_vec![cx.stmt_expr(field_expr)]),
16031603
);
16041604
}
16051605
}

compiler/rustc_builtin_macros/src/deriving/hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn hash_substructure(
7272
}
7373
EnumTag(tag_field, match_expr) => {
7474
assert!(tag_field.other_selflike_exprs.is_empty());
75-
let stmts = vec![call_hash(tag_field.span, tag_field.self_expr.clone())];
75+
let stmts = thin_vec![call_hash(tag_field.span, tag_field.self_expr.clone())];
7676
(stmts, match_expr.clone())
7777
}
7878
_ => cx.span_bug(trait_span, "impossible substructure in `derive(Hash)`"),

compiler/rustc_builtin_macros/src/deriving/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::{GenericArg, Impl, ItemKind, MetaItem};
66
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier};
77
use rustc_span::symbol::{sym, Ident, Symbol};
88
use rustc_span::Span;
9-
use thin_vec::ThinVec;
9+
use thin_vec::{thin_vec, ThinVec};
1010

1111
macro path_local($x:ident) {
1212
generic::ty::Path::new_local(sym::$x)
@@ -107,7 +107,7 @@ fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P<ast::Expr> {
107107
let call = cx.expr_call_global(span, path, ThinVec::new());
108108

109109
cx.expr_block(P(ast::Block {
110-
stmts: vec![cx.stmt_expr(call)],
110+
stmts: thin_vec![cx.stmt_expr(call)],
111111
id: ast::DUMMY_NODE_ID,
112112
rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated),
113113
span,
@@ -212,7 +212,7 @@ fn inject_impl_of_structural_trait(
212212

213213
fn assert_ty_bounds(
214214
cx: &mut ExtCtxt<'_>,
215-
stmts: &mut Vec<ast::Stmt>,
215+
stmts: &mut ThinVec<ast::Stmt>,
216216
ty: P<ast::Ty>,
217217
span: Span,
218218
assert_path: &[Symbol],

0 commit comments

Comments
 (0)