Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl GenericBound {
}
}

pub type GenericBounds = Vec<GenericBound>;
pub type GenericBounds = ThinVec<GenericBound>;

/// Specifies the enforced ordering for generic parameters. In the future,
/// if we wanted to relax this order, we could override `PartialEq` and
Expand Down Expand Up @@ -1534,7 +1534,7 @@ impl Expr {
let (Some(lhs), Some(rhs)) = (lhs.to_bound(), rhs.to_bound()) else {
return None;
};
TyKind::TraitObject(vec![lhs, rhs], TraitObjectSyntax::None)
TyKind::TraitObject(thin_vec![lhs, rhs], TraitObjectSyntax::None)
}

ExprKind::Underscore => TyKind::Infer,
Expand Down Expand Up @@ -1868,7 +1868,7 @@ pub enum ExprKind {
///
/// Usually not written directly in user code but
/// indirectly via the macro `core::mem::offset_of!(...)`.
OffsetOf(Box<Ty>, Vec<Ident>),
OffsetOf(Box<Ty>, ThinVec<Ident>),

/// A macro invocation; pre-expansion.
MacCall(Box<MacCall>),
Expand Down Expand Up @@ -4391,27 +4391,37 @@ mod size_asserts {
// tidy-alphabetical-start
static_assert_size!(AssocItem, 80);
static_assert_size!(AssocItemKind, 16);
static_assert_size!(AttrKind, 16);
static_assert_size!(Attribute, 32);
static_assert_size!(Block, 32);
static_assert_size!(Expr, 72);
static_assert_size!(ExprKind, 40);
static_assert_size!(Fn, 192);
static_assert_size!(FnDecl, 24);
static_assert_size!(FnHeader, 76);
static_assert_size!(FnSig, 96);
static_assert_size!(ForeignItem, 80);
static_assert_size!(ForeignItemKind, 16);
static_assert_size!(GenericArg, 24);
static_assert_size!(GenericArgs, 40);
static_assert_size!(GenericBound, 88);
static_assert_size!(GenericParam, 80);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 80);
static_assert_size!(Item, 152);
static_assert_size!(ItemKind, 88);
static_assert_size!(Lifetime, 16);
static_assert_size!(LitKind, 24);
static_assert_size!(Local, 96);
static_assert_size!(MetaItem, 88);
static_assert_size!(MetaItemKind, 40);
static_assert_size!(MetaItemLit, 40);
static_assert_size!(Param, 40);
static_assert_size!(Pat, 80);
static_assert_size!(PatKind, 56);
static_assert_size!(Path, 24);
static_assert_size!(PathSegment, 24);
static_assert_size!(QSelf, 24);
static_assert_size!(Stmt, 32);
static_assert_size!(StmtKind, 16);
static_assert_size!(TraitImplHeader, 72);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ macro_rules! common_visitor_and_walkers {
impl_visitable_list!(<$($lt)? $($mut)?>
ThinVec<AngleBracketedArg>,
ThinVec<Attribute>,
ThinVec<GenericBound>,
ThinVec<Ident>,
ThinVec<(Ident, Option<Ident>)>,
ThinVec<(NodeId, Path)>,
ThinVec<PathSegment>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) ->
let ty_dyn_debug = cx.ty(
span,
ast::TyKind::TraitObject(
vec![cx.trait_bound(path_debug, false)],
thin_vec![cx.trait_bound(path_debug, false)],
ast::TraitObjectSyntax::Dyn,
),
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ impl<'a> TraitDef<'a> {
ident,
generics: Generics::default(),
after_where_clause: ast::WhereClause::default(),
bounds: Vec::new(),
bounds: ThinVec::new(),
ty: Some(type_def.to_ty(cx, self.span, type_ident, generics)),
})),
tokens: None,
Expand All @@ -639,7 +639,7 @@ impl<'a> TraitDef<'a> {
// Extra restrictions on the generics parameters to the
// type being derived upon.
let span = param.ident.span.with_ctxt(ctxt);
let bounds: Vec<_> = self
let bounds: ThinVec<_> = self
.additional_bounds
.iter()
.map(|p| {
Expand Down Expand Up @@ -723,7 +723,7 @@ impl<'a> TraitDef<'a> {
{
continue;
}
let mut bounds: Vec<_> = self
let mut bounds: ThinVec<_> = self
.additional_bounds
.iter()
.map(|p| {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,8 @@ impl<'a> Parser<'a> {
/// Parse the field access used in offset_of, matched by `$(e:expr)+`.
/// Currently returns a list of idents. However, it should be possible in
/// future to also do array indices, which might be arbitrary expressions.
pub(crate) fn parse_floating_field_access(&mut self) -> PResult<'a, Vec<Ident>> {
let mut fields = Vec::new();
pub(crate) fn parse_floating_field_access(&mut self) -> PResult<'a, ThinVec<Ident>> {
let mut fields = ThinVec::new();
let mut trailing_dot = None;

loop {
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_parse/src/parser/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> Parser<'a> {
/// BOUND = LT_BOUND (e.g., `'a`)
/// ```
fn parse_lt_param_bounds(&mut self) -> GenericBounds {
let mut lifetimes = Vec::new();
let mut lifetimes = ThinVec::new();
while self.check_lifetime() {
lifetimes.push(ast::GenericBound::Outlives(self.expect_lifetime()));

Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'a> Parser<'a> {
}
self.parse_generic_bounds()?
} else {
Vec::new()
ThinVec::new()
};

let default = if self.eat(exp!(Eq)) { Some(self.parse_ty()?) } else { None };
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'a> Parser<'a> {
ident,
id: ast::DUMMY_NODE_ID,
attrs: preceding_attrs,
bounds: Vec::new(),
bounds: ThinVec::new(),
kind: GenericParamKind::Const { ty, span, default: None },
is_placeholder: false,
colon_span: None,
Expand All @@ -148,7 +148,7 @@ impl<'a> Parser<'a> {
ident,
id: ast::DUMMY_NODE_ID,
attrs: preceding_attrs,
bounds: Vec::new(),
bounds: ThinVec::new(),
kind: GenericParamKind::Const { ty, span, default },
is_placeholder: false,
colon_span: None,
Expand Down Expand Up @@ -189,7 +189,7 @@ impl<'a> Parser<'a> {
ident,
id: ast::DUMMY_NODE_ID,
attrs: preceding_attrs,
bounds: Vec::new(),
bounds: ThinVec::new(),
kind: GenericParamKind::Const { ty, span, default },
is_placeholder: false,
colon_span: None,
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<'a> Parser<'a> {
let (colon_span, bounds) = if this.eat(exp!(Colon)) {
(Some(this.prev_token.span), this.parse_lt_param_bounds())
} else {
(None, Vec::new())
(None, ThinVec::new())
};

if this.check_noexpect(&token::Eq) && this.look_ahead(1, |t| t.is_lifetime()) {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ impl<'a> Parser<'a> {
// Parse optional colon and supertrait bounds.
let had_colon = self.eat(exp!(Colon));
let span_at_colon = self.prev_token.span;
let bounds = if had_colon { self.parse_generic_bounds()? } else { Vec::new() };
let bounds = if had_colon { self.parse_generic_bounds()? } else { ThinVec::new() };

let span_before_eq = self.prev_token.span;
if self.eat(exp!(Eq)) {
Expand Down Expand Up @@ -1253,7 +1253,8 @@ impl<'a> Parser<'a> {
let mut generics = self.parse_generics()?;

// Parse optional colon and param bounds.
let bounds = if self.eat(exp!(Colon)) { self.parse_generic_bounds()? } else { Vec::new() };
let bounds =
if self.eat(exp!(Colon)) { self.parse_generic_bounds()? } else { ThinVec::new() };
generics.where_clause = self.parse_where_clause()?;

let ty = if self.eat(exp!(Eq)) { Some(self.parse_ty()?) } else { None };
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl<'a> Parser<'a> {
lo.to(self.prev_token.span),
parens,
);
let bounds = vec![GenericBound::Trait(poly_trait_ref)];
let bounds = thin_vec![GenericBound::Trait(poly_trait_ref)];
self.parse_remaining_bounds(bounds, parse_plus)
}

Expand Down Expand Up @@ -1080,7 +1080,7 @@ impl<'a> Parser<'a> {
/// Only if `allow_plus` this parses a `+`-separated list of bounds (trailing `+` is admitted).
/// Otherwise, this only parses a single bound or none.
fn parse_generic_bounds_common(&mut self, allow_plus: AllowPlus) -> PResult<'a, GenericBounds> {
let mut bounds = Vec::new();
let mut bounds = ThinVec::new();

// In addition to looping while we find generic bounds:
// We continue even if we find a keyword. This is necessary for error recovery on,
Expand Down Expand Up @@ -1432,7 +1432,7 @@ impl<'a> Parser<'a> {
// Someone has written something like `&dyn (Trait + Other)`. The correct code
// would be `&(dyn Trait + Other)`
if self.token.is_like_plus() && leading_token.is_keyword(kw::Dyn) {
let bounds = vec![];
let bounds = thin_vec![];
self.parse_remaining_bounds(bounds, true)?;
self.expect(exp!(CloseParen))?;
self.dcx().emit_err(errors::IncorrectParensTraitBounds {
Expand Down Expand Up @@ -1617,7 +1617,7 @@ impl<'a> Parser<'a> {
id: lt.id,
ident: lt.ident,
attrs: ast::AttrVec::new(),
bounds: Vec::new(),
bounds: ThinVec::new(),
is_placeholder: false,
kind: ast::GenericParamKind::Lifetime,
colon_span: None,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rustc_session::{Session, lint};
use rustc_span::edit_distance::{edit_distance, find_best_match_for_name};
use rustc_span::edition::Edition;
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, kw, sym};
use thin_vec::ThinVec;
use thin_vec::{ThinVec, thin_vec};
use tracing::debug;

use super::NoConstantGenericsReason;
Expand Down Expand Up @@ -4522,7 +4522,7 @@ fn mk_where_bound_predicate(
let new_where_bound_predicate = ast::WhereBoundPredicate {
bound_generic_params: ThinVec::new(),
bounded_ty: Box::new(ty.clone()),
bounds: vec![ast::GenericBound::Trait(ast::PolyTraitRef {
bounds: thin_vec![ast::GenericBound::Trait(ast::PolyTraitRef {
bound_generic_params: ThinVec::new(),
modifiers: ast::TraitBoundModifiers::NONE,
trait_ref: ast::TraitRef {
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/stats/input-stats.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ast-stats Pat 560 (NN.N%) 7 80
ast-stats - Struct 80 (NN.N%) 1
ast-stats - Wild 80 (NN.N%) 1
ast-stats - Ident 400 (NN.N%) 5
ast-stats GenericParam 480 (NN.N%) 5 96
ast-stats GenericParam 400 (NN.N%) 5 80
ast-stats GenericBound 352 (NN.N%) 4 88
ast-stats - Trait 352 (NN.N%) 4
ast-stats AssocItem 320 (NN.N%) 4 80
Expand All @@ -50,14 +50,14 @@ ast-stats Local 96 (NN.N%) 1 96
ast-stats Arm 96 (NN.N%) 2 48
ast-stats ForeignItem 80 (NN.N%) 1 80
ast-stats - Fn 80 (NN.N%) 1
ast-stats WherePredicate 72 (NN.N%) 1 72
ast-stats - BoundPredicate 72 (NN.N%) 1
ast-stats WherePredicate 56 (NN.N%) 1 56
ast-stats - BoundPredicate 56 (NN.N%) 1
ast-stats ExprField 48 (NN.N%) 1 48
ast-stats GenericArgs 40 (NN.N%) 1 40
ast-stats - AngleBracketed 40 (NN.N%) 1
ast-stats Crate 40 (NN.N%) 1 40
ast-stats ----------------------------------------------------------------
ast-stats Total 7_624 127
ast-stats Total 7_528 127
ast-stats ================================================================
hir-stats ================================================================
hir-stats HIR STATS: input_stats
Expand Down
Loading