Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7e855d5

Browse files
committed
Use ThinVec in a few more AST types.
1 parent 549f1c6 commit 7e855d5

File tree

11 files changed

+72
-69
lines changed

11 files changed

+72
-69
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ pub struct WhereEqPredicate {
471471
#[derive(Clone, Encodable, Decodable, Debug)]
472472
pub struct Crate {
473473
pub attrs: AttrVec,
474-
pub items: Vec<P<Item>>,
474+
pub items: ThinVec<P<Item>>,
475475
pub spans: ModSpans,
476476
/// Must be equal to `CRATE_NODE_ID` after the crate root is expanded, but may hold
477477
/// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that.
@@ -1357,7 +1357,7 @@ pub enum StructRest {
13571357
pub struct StructExpr {
13581358
pub qself: Option<P<QSelf>>,
13591359
pub path: Path,
1360-
pub fields: Vec<ExprField>,
1360+
pub fields: ThinVec<ExprField>,
13611361
pub rest: StructRest,
13621362
}
13631363

@@ -2475,7 +2475,7 @@ pub enum ModKind {
24752475
/// or with definition outlined to a separate file `mod foo;` and already loaded from it.
24762476
/// The inner span is from the first token past `{` to the last token until `}`,
24772477
/// or from the first to the last token in the loaded file.
2478-
Loaded(Vec<P<Item>>, Inline, ModSpans),
2478+
Loaded(ThinVec<P<Item>>, Inline, ModSpans),
24792479
/// Module with definition outlined to a separate file `mod foo;` but not yet loaded from it.
24802480
Unloaded,
24812481
}
@@ -2502,7 +2502,7 @@ pub struct ForeignMod {
25022502

25032503
#[derive(Clone, Encodable, Decodable, Debug)]
25042504
pub struct EnumDef {
2505-
pub variants: Vec<Variant>,
2505+
pub variants: ThinVec<Variant>,
25062506
}
25072507
/// Enum variant.
25082508
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -3122,8 +3122,8 @@ mod size_asserts {
31223122
static_assert_size!(GenericBound, 56);
31233123
static_assert_size!(Generics, 40);
31243124
static_assert_size!(Impl, 136);
3125-
static_assert_size!(Item, 144);
3126-
static_assert_size!(ItemKind, 72);
3125+
static_assert_size!(Item, 136);
3126+
static_assert_size!(ItemKind, 64);
31273127
static_assert_size!(LitKind, 24);
31283128
static_assert_size!(Local, 72);
31293129
static_assert_size!(MetaItemLit, 40);

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn cs_clone(
200200
let call = subcall(cx, field);
201201
cx.field_imm(field.span, ident, call)
202202
})
203-
.collect::<Vec<_>>();
203+
.collect::<ThinVec<_>>();
204204

205205
cx.expr_struct(trait_span, ctor_path, fields)
206206
}

compiler/rustc_builtin_macros/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,14 @@ pub fn expand_test_or_bench(
249249
cx.expr_struct(
250250
sp,
251251
test_path("TestDescAndFn"),
252-
vec![
252+
thin_vec![
253253
// desc: test::TestDesc {
254254
field(
255255
"desc",
256256
cx.expr_struct(
257257
sp,
258258
test_path("TestDesc"),
259-
vec![
259+
thin_vec![
260260
// name: "path::to::test"
261261
field(
262262
"name",

compiler/rustc_expand/src/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'a> ExtCtxt<'a> {
323323
&self,
324324
span: Span,
325325
path: ast::Path,
326-
fields: Vec<ast::ExprField>,
326+
fields: ThinVec<ast::ExprField>,
327327
) -> P<ast::Expr> {
328328
self.expr(
329329
span,
@@ -339,7 +339,7 @@ impl<'a> ExtCtxt<'a> {
339339
&self,
340340
span: Span,
341341
id: Ident,
342-
fields: Vec<ast::ExprField>,
342+
fields: ThinVec<ast::ExprField>,
343343
) -> P<ast::Expr> {
344344
self.expr_struct(span, self.path_ident(span, id), fields)
345345
}

compiler/rustc_expand/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_session::Session;
2424
use rustc_span::edition::{Edition, ALL_EDITIONS};
2525
use rustc_span::symbol::{sym, Symbol};
2626
use rustc_span::{Span, DUMMY_SP};
27+
use thin_vec::ThinVec;
2728

2829
/// A folder that strips out items that do not belong in the current configuration.
2930
pub struct StripUnconfigured<'a> {
@@ -206,7 +207,7 @@ pub fn features(
206207
None => {
207208
// The entire crate is unconfigured.
208209
krate.attrs = ast::AttrVec::new();
209-
krate.items = Vec::new();
210+
krate.items = ThinVec::new();
210211
Features::default()
211212
}
212213
Some(attrs) => {

compiler/rustc_expand/src/module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use rustc_session::Session;
1212
use rustc_span::symbol::{sym, Ident};
1313
use rustc_span::Span;
1414
use std::iter::once;
15-
1615
use std::path::{self, Path, PathBuf};
16+
use thin_vec::ThinVec;
1717

1818
#[derive(Copy, Clone)]
1919
pub enum DirOwnership {
@@ -31,7 +31,7 @@ pub struct ModulePathSuccess {
3131
}
3232

3333
pub(crate) struct ParsedExternalMod {
34-
pub items: Vec<P<Item>>,
34+
pub items: ThinVec<P<Item>>,
3535
pub spans: ModSpans,
3636
pub file_path: PathBuf,
3737
pub dir_path: PathBuf,

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,8 +2935,8 @@ impl<'a> Parser<'a> {
29352935
pth: ast::Path,
29362936
recover: bool,
29372937
close_delim: Delimiter,
2938-
) -> PResult<'a, (Vec<ExprField>, ast::StructRest, bool)> {
2939-
let mut fields = Vec::new();
2938+
) -> PResult<'a, (ThinVec<ExprField>, ast::StructRest, bool)> {
2939+
let mut fields = ThinVec::new();
29402940
let mut base = ast::StructRest::None;
29412941
let mut recover_async = false;
29422942

compiler/rustc_parse/src/parser/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ impl<'a> Parser<'a> {
5656
pub fn parse_mod(
5757
&mut self,
5858
term: &TokenKind,
59-
) -> PResult<'a, (AttrVec, Vec<P<Item>>, ModSpans)> {
59+
) -> PResult<'a, (AttrVec, ThinVec<P<Item>>, ModSpans)> {
6060
let lo = self.token.span;
6161
let attrs = self.parse_inner_attributes()?;
6262

6363
let post_attr_lo = self.token.span;
64-
let mut items = vec![];
64+
let mut items = ThinVec::new();
6565
while let Some(item) = self.parse_item(ForceCollect::No)? {
6666
items.push(item);
6767
self.maybe_consume_incorrect_semicolon(&items);

src/tools/rustfmt/src/modules.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::ast;
66
use rustc_ast::visit::Visitor;
77
use rustc_span::symbol::{self, sym, Symbol};
88
use rustc_span::Span;
9+
use thin_vec::ThinVec;
910
use thiserror::Error;
1011

1112
use crate::attr::MetaVisitor;
@@ -25,7 +26,7 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
2526
#[derive(Debug, Clone)]
2627
pub(crate) struct Module<'a> {
2728
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
28-
pub(crate) items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
29+
pub(crate) items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
2930
inner_attr: ast::AttrVec,
3031
pub(crate) span: Span,
3132
}
@@ -34,7 +35,7 @@ impl<'a> Module<'a> {
3435
pub(crate) fn new(
3536
mod_span: Span,
3637
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
37-
mod_items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
38+
mod_items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
3839
mod_attrs: Cow<'a, ast::AttrVec>,
3940
) -> Self {
4041
let inner_attr = mod_attrs
@@ -157,7 +158,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
157158
Module::new(
158159
module_item.item.span,
159160
Some(Cow::Owned(sub_mod_kind.clone())),
160-
Cow::Owned(vec![]),
161+
Cow::Owned(ThinVec::new()),
161162
Cow::Owned(ast::AttrVec::new()),
162163
),
163164
)?;
@@ -169,7 +170,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
169170
/// Visit modules defined inside macro calls.
170171
fn visit_mod_outside_ast(
171172
&mut self,
172-
items: Vec<rustc_ast::ptr::P<ast::Item>>,
173+
items: ThinVec<rustc_ast::ptr::P<ast::Item>>,
173174
) -> Result<(), ModuleResolutionError> {
174175
for item in items {
175176
if is_cfg_if(&item) {
@@ -184,7 +185,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
184185
Module::new(
185186
span,
186187
Some(Cow::Owned(sub_mod_kind.clone())),
187-
Cow::Owned(vec![]),
188+
Cow::Owned(ThinVec::new()),
188189
Cow::Owned(ast::AttrVec::new()),
189190
),
190191
)?;
@@ -210,7 +211,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
210211
Module::new(
211212
span,
212213
Some(Cow::Borrowed(sub_mod_kind)),
213-
Cow::Owned(vec![]),
214+
Cow::Owned(ThinVec::new()),
214215
Cow::Borrowed(&item.attrs),
215216
),
216217
)?;

src/tools/rustfmt/src/parse/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::{ast, ptr};
66
use rustc_errors::Diagnostic;
77
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
88
use rustc_span::{sym, Span};
9+
use thin_vec::ThinVec;
910

1011
use crate::attr::first_attr_value_str_by_name;
1112
use crate::parse::session::ParseSess;
@@ -109,7 +110,7 @@ impl<'a> Parser<'a> {
109110
sess: &'a ParseSess,
110111
path: &Path,
111112
span: Span,
112-
) -> Result<(ast::AttrVec, Vec<ptr::P<ast::Item>>, Span), ParserError> {
113+
) -> Result<(ast::AttrVec, ThinVec<ptr::P<ast::Item>>, Span), ParserError> {
113114
let result = catch_unwind(AssertUnwindSafe(|| {
114115
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
115116
match parser.parse_mod(&TokenKind::Eof) {

0 commit comments

Comments
 (0)