Use ThinVec
in various AST types.
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
This commit is contained in:
parent
6a56c3a930
commit
4143b101f9
52 changed files with 355 additions and 292 deletions
|
@ -253,7 +253,7 @@ pub struct ParenthesizedArgs {
|
|||
pub span: Span,
|
||||
|
||||
/// `(A, B)`
|
||||
pub inputs: Vec<P<Ty>>,
|
||||
pub inputs: ThinVec<P<Ty>>,
|
||||
|
||||
/// ```text
|
||||
/// Foo(A, B) -> C
|
||||
|
@ -503,7 +503,7 @@ pub enum MetaItemKind {
|
|||
/// List meta item.
|
||||
///
|
||||
/// E.g., `#[derive(..)]`, where the field represents the `..`.
|
||||
List(Vec<NestedMetaItem>),
|
||||
List(ThinVec<NestedMetaItem>),
|
||||
|
||||
/// Name value meta item.
|
||||
///
|
||||
|
@ -581,7 +581,7 @@ impl Pat {
|
|||
// A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)`
|
||||
// assuming `T0` to `Tn` are all syntactically valid as types.
|
||||
PatKind::Tuple(pats) => {
|
||||
let mut tys = Vec::with_capacity(pats.len());
|
||||
let mut tys = ThinVec::with_capacity(pats.len());
|
||||
// FIXME(#48994) - could just be collected into an Option<Vec>
|
||||
for pat in pats {
|
||||
tys.push(pat.to_ty()?);
|
||||
|
@ -725,11 +725,11 @@ pub enum PatKind {
|
|||
Struct(Option<P<QSelf>>, Path, Vec<PatField>, /* recovered */ bool),
|
||||
|
||||
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
|
||||
TupleStruct(Option<P<QSelf>>, Path, Vec<P<Pat>>),
|
||||
TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>),
|
||||
|
||||
/// An or-pattern `A | B | C`.
|
||||
/// Invariant: `pats.len() >= 2`.
|
||||
Or(Vec<P<Pat>>),
|
||||
Or(ThinVec<P<Pat>>),
|
||||
|
||||
/// A possibly qualified path pattern.
|
||||
/// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants
|
||||
|
@ -738,7 +738,7 @@ pub enum PatKind {
|
|||
Path(Option<P<QSelf>>, Path),
|
||||
|
||||
/// A tuple pattern (`(a, b)`).
|
||||
Tuple(Vec<P<Pat>>),
|
||||
Tuple(ThinVec<P<Pat>>),
|
||||
|
||||
/// A `box` pattern.
|
||||
Box(P<Pat>),
|
||||
|
@ -753,7 +753,7 @@ pub enum PatKind {
|
|||
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),
|
||||
|
||||
/// A slice pattern `[a, b, c]`.
|
||||
Slice(Vec<P<Pat>>),
|
||||
Slice(ThinVec<P<Pat>>),
|
||||
|
||||
/// A rest pattern `..`.
|
||||
///
|
||||
|
@ -1204,7 +1204,7 @@ impl Expr {
|
|||
ExprKind::Array(exprs) if exprs.len() == 1 => exprs[0].to_ty().map(TyKind::Slice)?,
|
||||
|
||||
ExprKind::Tup(exprs) => {
|
||||
let tys = exprs.iter().map(|expr| expr.to_ty()).collect::<Option<Vec<_>>>()?;
|
||||
let tys = exprs.iter().map(|expr| expr.to_ty()).collect::<Option<ThinVec<_>>>()?;
|
||||
TyKind::Tup(tys)
|
||||
}
|
||||
|
||||
|
@ -1337,7 +1337,7 @@ pub struct MethodCall {
|
|||
/// The receiver, e.g. `x`.
|
||||
pub receiver: P<Expr>,
|
||||
/// The arguments, e.g. `a, b, c`.
|
||||
pub args: Vec<P<Expr>>,
|
||||
pub args: ThinVec<P<Expr>>,
|
||||
/// The span of the function, without the dot and receiver e.g. `foo::<Bar,
|
||||
/// Baz>(a, b, c)`.
|
||||
pub span: Span,
|
||||
|
@ -1366,7 +1366,7 @@ pub enum ExprKind {
|
|||
/// A `box x` expression.
|
||||
Box(P<Expr>),
|
||||
/// An array (`[a, b, c, d]`)
|
||||
Array(Vec<P<Expr>>),
|
||||
Array(ThinVec<P<Expr>>),
|
||||
/// Allow anonymous constants from an inline `const` block
|
||||
ConstBlock(AnonConst),
|
||||
/// A function call
|
||||
|
@ -1375,11 +1375,11 @@ pub enum ExprKind {
|
|||
/// and the second field is the list of arguments.
|
||||
/// This also represents calling the constructor of
|
||||
/// tuple-like ADTs such as tuple structs and enum variants.
|
||||
Call(P<Expr>, Vec<P<Expr>>),
|
||||
Call(P<Expr>, ThinVec<P<Expr>>),
|
||||
/// A method call (e.g. `x.foo::<Bar, Baz>(a, b, c)`).
|
||||
MethodCall(Box<MethodCall>),
|
||||
/// A tuple (e.g., `(a, b, c, d)`).
|
||||
Tup(Vec<P<Expr>>),
|
||||
Tup(ThinVec<P<Expr>>),
|
||||
/// A binary operation (e.g., `a + b`, `a * b`).
|
||||
Binary(BinOp, P<Expr>, P<Expr>),
|
||||
/// A unary operation (e.g., `!x`, `*x`).
|
||||
|
@ -2078,7 +2078,7 @@ pub enum TyKind {
|
|||
/// The never type (`!`).
|
||||
Never,
|
||||
/// A tuple (`(A, B, C, D,...)`).
|
||||
Tup(Vec<P<Ty>>),
|
||||
Tup(ThinVec<P<Ty>>),
|
||||
/// A path (`module::module::...::Type`), optionally
|
||||
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
|
||||
///
|
||||
|
@ -2363,7 +2363,7 @@ impl Param {
|
|||
/// which contains metadata about function safety, asyncness, constness and ABI.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct FnDecl {
|
||||
pub inputs: Vec<Param>,
|
||||
pub inputs: ThinVec<Param>,
|
||||
pub output: FnRetTy,
|
||||
}
|
||||
|
||||
|
@ -2532,7 +2532,7 @@ pub enum UseTreeKind {
|
|||
/// `use prefix` or `use prefix as rename`
|
||||
Simple(Option<Ident>),
|
||||
/// `use prefix::{...}`
|
||||
Nested(Vec<(UseTree, NodeId)>),
|
||||
Nested(ThinVec<(UseTree, NodeId)>),
|
||||
/// `use prefix::*`
|
||||
Glob,
|
||||
}
|
||||
|
@ -2695,11 +2695,11 @@ pub enum VariantData {
|
|||
/// Struct variant.
|
||||
///
|
||||
/// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`.
|
||||
Struct(Vec<FieldDef>, bool),
|
||||
Struct(ThinVec<FieldDef>, bool),
|
||||
/// Tuple variant.
|
||||
///
|
||||
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
|
||||
Tuple(Vec<FieldDef>, NodeId),
|
||||
Tuple(ThinVec<FieldDef>, NodeId),
|
||||
/// Unit variant.
|
||||
///
|
||||
/// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`.
|
||||
|
@ -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, 152);
|
||||
static_assert_size!(ItemKind, 80);
|
||||
static_assert_size!(Item, 144);
|
||||
static_assert_size!(ItemKind, 72);
|
||||
static_assert_size!(LitKind, 24);
|
||||
static_assert_size!(Local, 72);
|
||||
static_assert_size!(MetaItemLit, 40);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue