diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index de6a0b563eb..03c375c4666 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -471,7 +471,7 @@ pub struct WhereEqPredicate {
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Crate {
pub attrs: AttrVec,
- pub items: Vec
>,
+ pub items: ThinVec
>,
pub spans: ModSpans,
/// Must be equal to `CRATE_NODE_ID` after the crate root is expanded, but may hold
/// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that.
@@ -1357,7 +1357,7 @@ pub enum StructRest {
pub struct StructExpr {
pub qself: Option
>,
pub path: Path,
- pub fields: Vec,
+ pub fields: ThinVec,
pub rest: StructRest,
}
@@ -2475,7 +2475,7 @@ pub enum ModKind {
/// or with definition outlined to a separate file `mod foo;` and already loaded from it.
/// The inner span is from the first token past `{` to the last token until `}`,
/// or from the first to the last token in the loaded file.
- Loaded(Vec>, Inline, ModSpans),
+ Loaded(ThinVec
>, Inline, ModSpans),
/// Module with definition outlined to a separate file `mod foo;` but not yet loaded from it.
Unloaded,
}
@@ -2502,7 +2502,7 @@ pub struct ForeignMod {
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct EnumDef {
- pub variants: Vec,
+ pub variants: ThinVec,
}
/// Enum variant.
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -3122,8 +3122,8 @@ mod size_asserts {
static_assert_size!(GenericBound, 56);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 136);
- static_assert_size!(Item, 144);
- static_assert_size!(ItemKind, 72);
+ static_assert_size!(Item, 136);
+ static_assert_size!(ItemKind, 64);
static_assert_size!(LitKind, 24);
static_assert_size!(Local, 72);
static_assert_size!(MetaItemLit, 40);
diff --git a/compiler/rustc_builtin_macros/src/deriving/clone.rs b/compiler/rustc_builtin_macros/src/deriving/clone.rs
index 3c1abe02036..dfee2d3ce77 100644
--- a/compiler/rustc_builtin_macros/src/deriving/clone.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/clone.rs
@@ -200,7 +200,7 @@ fn cs_clone(
let call = subcall(cx, field);
cx.field_imm(field.span, ident, call)
})
- .collect::>();
+ .collect::>();
cx.expr_struct(trait_span, ctor_path, fields)
}
diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs
index 608d8c96668..e02c7e6c01b 100644
--- a/compiler/rustc_builtin_macros/src/test.rs
+++ b/compiler/rustc_builtin_macros/src/test.rs
@@ -249,14 +249,14 @@ pub fn expand_test_or_bench(
cx.expr_struct(
sp,
test_path("TestDescAndFn"),
- vec![
+ thin_vec![
// desc: test::TestDesc {
field(
"desc",
cx.expr_struct(
sp,
test_path("TestDesc"),
- vec![
+ thin_vec![
// name: "path::to::test"
field(
"name",
diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs
index eaecce91b8a..8a78c3296f9 100644
--- a/compiler/rustc_expand/src/build.rs
+++ b/compiler/rustc_expand/src/build.rs
@@ -323,7 +323,7 @@ pub fn expr_struct(
&self,
span: Span,
path: ast::Path,
- fields: Vec,
+ fields: ThinVec,
) -> P {
self.expr(
span,
@@ -339,7 +339,7 @@ pub fn expr_struct_ident(
&self,
span: Span,
id: Ident,
- fields: Vec,
+ fields: ThinVec,
) -> P {
self.expr_struct(span, self.path_ident(span, id), fields)
}
diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs
index 5c845ae6d0b..01500c2c77c 100644
--- a/compiler/rustc_expand/src/config.rs
+++ b/compiler/rustc_expand/src/config.rs
@@ -24,6 +24,7 @@
use rustc_span::edition::{Edition, ALL_EDITIONS};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP};
+use thin_vec::ThinVec;
/// A folder that strips out items that do not belong in the current configuration.
pub struct StripUnconfigured<'a> {
@@ -206,7 +207,7 @@ pub fn features(
None => {
// The entire crate is unconfigured.
krate.attrs = ast::AttrVec::new();
- krate.items = Vec::new();
+ krate.items = ThinVec::new();
Features::default()
}
Some(attrs) => {
diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs
index 07f47a9c3a4..3779af19e12 100644
--- a/compiler/rustc_expand/src/module.rs
+++ b/compiler/rustc_expand/src/module.rs
@@ -12,8 +12,8 @@
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;
use std::iter::once;
-
use std::path::{self, Path, PathBuf};
+use thin_vec::ThinVec;
#[derive(Copy, Clone)]
pub enum DirOwnership {
@@ -31,7 +31,7 @@ pub struct ModulePathSuccess {
}
pub(crate) struct ParsedExternalMod {
- pub items: Vec>,
+ pub items: ThinVec
>,
pub spans: ModSpans,
pub file_path: PathBuf,
pub dir_path: PathBuf,
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index c92379754bf..12f65a436e3 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2935,8 +2935,8 @@ pub(super) fn parse_struct_fields(
pth: ast::Path,
recover: bool,
close_delim: Delimiter,
- ) -> PResult<'a, (Vec, ast::StructRest, bool)> {
- let mut fields = Vec::new();
+ ) -> PResult<'a, (ThinVec, ast::StructRest, bool)> {
+ let mut fields = ThinVec::new();
let mut base = ast::StructRest::None;
let mut recover_async = false;
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index 4e338f52f57..c0aed6a3789 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -56,12 +56,12 @@ fn parse_item_mod(&mut self, attrs: &mut AttrVec) -> PResult<'a, ItemInfo> {
pub fn parse_mod(
&mut self,
term: &TokenKind,
- ) -> PResult<'a, (AttrVec, Vec>, ModSpans)> {
+ ) -> PResult<'a, (AttrVec, ThinVec
>, ModSpans)> {
let lo = self.token.span;
let attrs = self.parse_inner_attributes()?;
let post_attr_lo = self.token.span;
- let mut items = vec![];
+ let mut items = ThinVec::new();
while let Some(item) = self.parse_item(ForceCollect::No)? {
items.push(item);
self.maybe_consume_incorrect_semicolon(&items);
diff --git a/src/tools/rustfmt/src/modules.rs b/src/tools/rustfmt/src/modules.rs
index 7a0d1736c59..af9a154a6ae 100644
--- a/src/tools/rustfmt/src/modules.rs
+++ b/src/tools/rustfmt/src/modules.rs
@@ -6,6 +6,7 @@
use rustc_ast::visit::Visitor;
use rustc_span::symbol::{self, sym, Symbol};
use rustc_span::Span;
+use thin_vec::ThinVec;
use thiserror::Error;
use crate::attr::MetaVisitor;
@@ -25,7 +26,7 @@
#[derive(Debug, Clone)]
pub(crate) struct Module<'a> {
ast_mod_kind: Option>,
- pub(crate) items: Cow<'a, Vec>>,
+ pub(crate) items: Cow<'a, ThinVec>>,
inner_attr: ast::AttrVec,
pub(crate) span: Span,
}
@@ -34,7 +35,7 @@ impl<'a> Module<'a> {
pub(crate) fn new(
mod_span: Span,
ast_mod_kind: Option>,
- mod_items: Cow<'a, Vec>>,
+ mod_items: Cow<'a, ThinVec>>,
mod_attrs: Cow<'a, ast::AttrVec>,
) -> Self {
let inner_attr = mod_attrs
@@ -157,7 +158,7 @@ fn visit_cfg_if(&mut self, item: Cow<'ast, ast::Item>) -> Result<(), ModuleResol
Module::new(
module_item.item.span,
Some(Cow::Owned(sub_mod_kind.clone())),
- Cow::Owned(vec![]),
+ Cow::Owned(ThinVec::new()),
Cow::Owned(ast::AttrVec::new()),
),
)?;
@@ -169,7 +170,7 @@ fn visit_cfg_if(&mut self, item: Cow<'ast, ast::Item>) -> Result<(), ModuleResol
/// Visit modules defined inside macro calls.
fn visit_mod_outside_ast(
&mut self,
- items: Vec>,
+ items: ThinVec>,
) -> Result<(), ModuleResolutionError> {
for item in items {
if is_cfg_if(&item) {
@@ -184,7 +185,7 @@ fn visit_mod_outside_ast(
Module::new(
span,
Some(Cow::Owned(sub_mod_kind.clone())),
- Cow::Owned(vec![]),
+ Cow::Owned(ThinVec::new()),
Cow::Owned(ast::AttrVec::new()),
),
)?;
@@ -210,7 +211,7 @@ fn visit_mod_from_ast(
Module::new(
span,
Some(Cow::Borrowed(sub_mod_kind)),
- Cow::Owned(vec![]),
+ Cow::Owned(ThinVec::new()),
Cow::Borrowed(&item.attrs),
),
)?;
diff --git a/src/tools/rustfmt/src/parse/parser.rs b/src/tools/rustfmt/src/parse/parser.rs
index e0bd065518b..7ab042506bd 100644
--- a/src/tools/rustfmt/src/parse/parser.rs
+++ b/src/tools/rustfmt/src/parse/parser.rs
@@ -6,6 +6,7 @@
use rustc_errors::Diagnostic;
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
use rustc_span::{sym, Span};
+use thin_vec::ThinVec;
use crate::attr::first_attr_value_str_by_name;
use crate::parse::session::ParseSess;
@@ -109,7 +110,7 @@ pub(crate) fn parse_file_as_module(
sess: &'a ParseSess,
path: &Path,
span: Span,
- ) -> Result<(ast::AttrVec, Vec>, Span), ParserError> {
+ ) -> Result<(ast::AttrVec, ThinVec>, Span), ParserError> {
let result = catch_unwind(AssertUnwindSafe(|| {
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
match parser.parse_mod(&TokenKind::Eof) {
diff --git a/tests/ui/stats/hir-stats.stderr b/tests/ui/stats/hir-stats.stderr
index 4e53070798f..ee62d8f2d25 100644
--- a/tests/ui/stats/hir-stats.stderr
+++ b/tests/ui/stats/hir-stats.stderr
@@ -3,67 +3,67 @@ ast-stats-1 Name Accumulated Size Count Item Size
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 GenericArgs 40 ( 0.6%) 1 40
ast-stats-1 - AngleBracketed 40 ( 0.6%) 1
+ast-stats-1 Crate 40 ( 0.6%) 1 40
ast-stats-1 ExprField 48 ( 0.7%) 1 48
-ast-stats-1 WherePredicate 56 ( 0.8%) 1 56
-ast-stats-1 - BoundPredicate 56 ( 0.8%) 1
-ast-stats-1 Crate 56 ( 0.8%) 1 56
+ast-stats-1 WherePredicate 56 ( 0.9%) 1 56
+ast-stats-1 - BoundPredicate 56 ( 0.9%) 1
ast-stats-1 Attribute 64 ( 1.0%) 2 32
ast-stats-1 - Normal 32 ( 0.5%) 1
ast-stats-1 - DocComment 32 ( 0.5%) 1
ast-stats-1 Local 72 ( 1.1%) 1 72
-ast-stats-1 Arm 96 ( 1.4%) 2 48
-ast-stats-1 ForeignItem 96 ( 1.4%) 1 96
-ast-stats-1 - Fn 96 ( 1.4%) 1
+ast-stats-1 Arm 96 ( 1.5%) 2 48
+ast-stats-1 ForeignItem 96 ( 1.5%) 1 96
+ast-stats-1 - Fn 96 ( 1.5%) 1
ast-stats-1 FnDecl 120 ( 1.8%) 5 24
ast-stats-1 FieldDef 160 ( 2.4%) 2 80
ast-stats-1 Stmt 160 ( 2.4%) 5 32
ast-stats-1 - Local 32 ( 0.5%) 1
ast-stats-1 - MacCall 32 ( 0.5%) 1
-ast-stats-1 - Expr 96 ( 1.4%) 3
+ast-stats-1 - Expr 96 ( 1.5%) 3
ast-stats-1 Param 160 ( 2.4%) 4 40
ast-stats-1 Block 192 ( 2.9%) 6 32
-ast-stats-1 Variant 208 ( 3.1%) 2 104
+ast-stats-1 Variant 208 ( 3.2%) 2 104
ast-stats-1 GenericBound 224 ( 3.4%) 4 56
ast-stats-1 - Trait 224 ( 3.4%) 4
ast-stats-1 AssocItem 416 ( 6.3%) 4 104
-ast-stats-1 - Type 208 ( 3.1%) 2
-ast-stats-1 - Fn 208 ( 3.1%) 2
-ast-stats-1 GenericParam 480 ( 7.2%) 5 96
-ast-stats-1 Pat 504 ( 7.6%) 7 72
+ast-stats-1 - Type 208 ( 3.2%) 2
+ast-stats-1 - Fn 208 ( 3.2%) 2
+ast-stats-1 GenericParam 480 ( 7.3%) 5 96
+ast-stats-1 Pat 504 ( 7.7%) 7 72
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Wild 72 ( 1.1%) 1
-ast-stats-1 - Ident 360 ( 5.4%) 5
-ast-stats-1 Expr 576 ( 8.7%) 8 72
+ast-stats-1 - Ident 360 ( 5.5%) 5
+ast-stats-1 Expr 576 ( 8.8%) 8 72
ast-stats-1 - Path 72 ( 1.1%) 1
ast-stats-1 - Match 72 ( 1.1%) 1
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Lit 144 ( 2.2%) 2
ast-stats-1 - Block 216 ( 3.3%) 3
-ast-stats-1 PathSegment 720 (10.8%) 30 24
-ast-stats-1 Ty 896 (13.5%) 14 64
+ast-stats-1 PathSegment 720 (11.0%) 30 24
+ast-stats-1 Ty 896 (13.7%) 14 64
ast-stats-1 - Ptr 64 ( 1.0%) 1
ast-stats-1 - Ref 64 ( 1.0%) 1
-ast-stats-1 - ImplicitSelf 128 ( 1.9%) 2
-ast-stats-1 - Path 640 ( 9.6%) 10
-ast-stats-1 Item 1_296 (19.5%) 9 144
-ast-stats-1 - Trait 144 ( 2.2%) 1
-ast-stats-1 - Enum 144 ( 2.2%) 1
-ast-stats-1 - ForeignMod 144 ( 2.2%) 1
-ast-stats-1 - Impl 144 ( 2.2%) 1
-ast-stats-1 - Fn 288 ( 4.3%) 2
-ast-stats-1 - Use 432 ( 6.5%) 3
+ast-stats-1 - ImplicitSelf 128 ( 2.0%) 2
+ast-stats-1 - Path 640 ( 9.8%) 10
+ast-stats-1 Item 1_224 (18.7%) 9 136
+ast-stats-1 - Trait 136 ( 2.1%) 1
+ast-stats-1 - Enum 136 ( 2.1%) 1
+ast-stats-1 - ForeignMod 136 ( 2.1%) 1
+ast-stats-1 - Impl 136 ( 2.1%) 1
+ast-stats-1 - Fn 272 ( 4.2%) 2
+ast-stats-1 - Use 408 ( 6.2%) 3
ast-stats-1 ----------------------------------------------------------------
-ast-stats-1 Total 6_640
+ast-stats-1 Total 6_552
ast-stats-1
ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name Accumulated Size Count Item Size
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 GenericArgs 40 ( 0.6%) 1 40
ast-stats-2 - AngleBracketed 40 ( 0.6%) 1
+ast-stats-2 Crate 40 ( 0.6%) 1 40
ast-stats-2 ExprField 48 ( 0.7%) 1 48
ast-stats-2 WherePredicate 56 ( 0.8%) 1 56
ast-stats-2 - BoundPredicate 56 ( 0.8%) 1
-ast-stats-2 Crate 56 ( 0.8%) 1 56
ast-stats-2 Local 72 ( 1.0%) 1 72
ast-stats-2 Arm 96 ( 1.3%) 2 48
ast-stats-2 ForeignItem 96 ( 1.3%) 1 96
@@ -79,41 +79,41 @@ ast-stats-2 - Local 32 ( 0.4%) 1
ast-stats-2 - Semi 32 ( 0.4%) 1
ast-stats-2 - Expr 96 ( 1.3%) 3
ast-stats-2 Param 160 ( 2.2%) 4 40
-ast-stats-2 Block 192 ( 2.6%) 6 32
+ast-stats-2 Block 192 ( 2.7%) 6 32
ast-stats-2 Variant 208 ( 2.9%) 2 104
ast-stats-2 GenericBound 224 ( 3.1%) 4 56
ast-stats-2 - Trait 224 ( 3.1%) 4
-ast-stats-2 AssocItem 416 ( 5.7%) 4 104
+ast-stats-2 AssocItem 416 ( 5.8%) 4 104
ast-stats-2 - Type 208 ( 2.9%) 2
ast-stats-2 - Fn 208 ( 2.9%) 2
-ast-stats-2 GenericParam 480 ( 6.6%) 5 96
-ast-stats-2 Pat 504 ( 6.9%) 7 72
+ast-stats-2 GenericParam 480 ( 6.7%) 5 96
+ast-stats-2 Pat 504 ( 7.0%) 7 72
ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - Wild 72 ( 1.0%) 1
ast-stats-2 - Ident 360 ( 5.0%) 5
-ast-stats-2 Expr 648 ( 8.9%) 9 72
+ast-stats-2 Expr 648 ( 9.1%) 9 72
ast-stats-2 - Path 72 ( 1.0%) 1
ast-stats-2 - Match 72 ( 1.0%) 1
ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - InlineAsm 72 ( 1.0%) 1
ast-stats-2 - Lit 144 ( 2.0%) 2
ast-stats-2 - Block 216 ( 3.0%) 3
-ast-stats-2 PathSegment 792 (10.9%) 33 24
-ast-stats-2 Ty 896 (12.3%) 14 64
+ast-stats-2 PathSegment 792 (11.1%) 33 24
+ast-stats-2 Ty 896 (12.5%) 14 64
ast-stats-2 - Ptr 64 ( 0.9%) 1
ast-stats-2 - Ref 64 ( 0.9%) 1
ast-stats-2 - ImplicitSelf 128 ( 1.8%) 2
-ast-stats-2 - Path 640 ( 8.8%) 10
-ast-stats-2 Item 1_584 (21.8%) 11 144
-ast-stats-2 - Trait 144 ( 2.0%) 1
-ast-stats-2 - Enum 144 ( 2.0%) 1
-ast-stats-2 - ExternCrate 144 ( 2.0%) 1
-ast-stats-2 - ForeignMod 144 ( 2.0%) 1
-ast-stats-2 - Impl 144 ( 2.0%) 1
-ast-stats-2 - Fn 288 ( 4.0%) 2
-ast-stats-2 - Use 576 ( 7.9%) 4
+ast-stats-2 - Path 640 ( 8.9%) 10
+ast-stats-2 Item 1_496 (20.9%) 11 136
+ast-stats-2 - Trait 136 ( 1.9%) 1
+ast-stats-2 - Enum 136 ( 1.9%) 1
+ast-stats-2 - ExternCrate 136 ( 1.9%) 1
+ast-stats-2 - ForeignMod 136 ( 1.9%) 1
+ast-stats-2 - Impl 136 ( 1.9%) 1
+ast-stats-2 - Fn 272 ( 3.8%) 2
+ast-stats-2 - Use 544 ( 7.6%) 4
ast-stats-2 ----------------------------------------------------------------
-ast-stats-2 Total 7_256
+ast-stats-2 Total 7_152
ast-stats-2
hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size