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
|
@ -6,7 +6,7 @@ use rustc_ast::{Fn, ItemKind, Stmt, TyKind, Unsafe};
|
|||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::thin_vec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand(
|
||||
ecx: &mut ExtCtxt<'_>,
|
||||
|
@ -42,7 +42,7 @@ pub fn expand(
|
|||
let stmts = vec![generate_handler(ecx, item.ident, span, sig_span)];
|
||||
|
||||
// Generate anonymous constant serving as container for the allocator methods.
|
||||
let const_ty = ecx.ty(sig_span, TyKind::Tup(Vec::new()));
|
||||
let const_ty = ecx.ty(sig_span, TyKind::Tup(ThinVec::new()));
|
||||
let const_body = ecx.expr_block(ecx.block(span, stmts));
|
||||
let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body);
|
||||
let const_item = if is_stmt {
|
||||
|
@ -67,13 +67,16 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span
|
|||
|
||||
let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]);
|
||||
let layout_new = cx.expr_path(cx.path(span, layout_new));
|
||||
let layout =
|
||||
cx.expr_call(span, layout_new, vec![cx.expr_ident(span, size), cx.expr_ident(span, align)]);
|
||||
let layout = cx.expr_call(
|
||||
span,
|
||||
layout_new,
|
||||
thin_vec![cx.expr_ident(span, size), cx.expr_ident(span, align)],
|
||||
);
|
||||
|
||||
let call = cx.expr_call_ident(sig_span, handler, vec![layout]);
|
||||
let call = cx.expr_call_ident(sig_span, handler, thin_vec![layout]);
|
||||
|
||||
let never = ast::FnRetTy::Ty(cx.ty(span, TyKind::Never));
|
||||
let params = vec![cx.param(span, size, ty_usize.clone()), cx.param(span, align, ty_usize)];
|
||||
let params = thin_vec![cx.param(span, size, ty_usize.clone()), cx.param(span, align, ty_usize)];
|
||||
let decl = cx.fn_decl(params, never);
|
||||
let header = FnHeader { unsafety: Unsafe::Yes(span), ..FnHeader::default() };
|
||||
let sig = FnSig { decl, header, span: span };
|
||||
|
|
|
@ -11,6 +11,7 @@ use rustc_expand::base::{DummyResult, ExtCtxt, MacEager, MacResult};
|
|||
use rustc_parse::parser::Parser;
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_assert<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
|
@ -79,7 +80,7 @@ pub fn expand_assert<'cx>(
|
|||
let then = cx.expr_call_global(
|
||||
call_site_span,
|
||||
cx.std_path(&[sym::panicking, sym::panic]),
|
||||
vec![cx.expr_str(
|
||||
thin_vec![cx.expr_str(
|
||||
DUMMY_SP,
|
||||
Symbol::intern(&format!(
|
||||
"assertion failed: {}",
|
||||
|
|
|
@ -12,7 +12,7 @@ use rustc_span::{
|
|||
symbol::{sym, Ident, Symbol},
|
||||
Span,
|
||||
};
|
||||
use thin_vec::thin_vec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub(super) struct Context<'cx, 'a> {
|
||||
// An optimization.
|
||||
|
@ -120,7 +120,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
|
|||
thin_vec![self.cx.attr_nested_word(sym::allow, sym::unused_imports, self.span)],
|
||||
ItemKind::Use(UseTree {
|
||||
prefix: self.cx.path(self.span, self.cx.std_path(&[sym::asserting])),
|
||||
kind: UseTreeKind::Nested(vec![
|
||||
kind: UseTreeKind::Nested(thin_vec![
|
||||
nested_tree(self, sym::TryCaptureGeneric),
|
||||
nested_tree(self, sym::TryCapturePrintable),
|
||||
]),
|
||||
|
@ -136,7 +136,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
|
|||
self.cx.expr_call(
|
||||
self.span,
|
||||
self.cx.expr_path(self.cx.path(self.span, unlikely_path)),
|
||||
vec![self.cx.expr(self.span, ExprKind::Unary(UnOp::Not, cond_expr))],
|
||||
thin_vec![self.cx.expr(self.span, ExprKind::Unary(UnOp::Not, cond_expr))],
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
|
|||
let init = self.cx.expr_call(
|
||||
self.span,
|
||||
self.cx.expr_path(self.cx.path(self.span, init_std_path)),
|
||||
vec![],
|
||||
ThinVec::new(),
|
||||
);
|
||||
let capture = Capture { decl: self.cx.stmt_let(self.span, true, ident, init), ident };
|
||||
self.capture_decls.push(capture);
|
||||
|
@ -366,7 +366,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
|
|||
self.cx.expr_path(
|
||||
self.cx.path(self.span, self.cx.std_path(&[sym::asserting, sym::Wrapper])),
|
||||
),
|
||||
vec![self.cx.expr_path(Path::from_ident(local_bind))],
|
||||
thin_vec![self.cx.expr_path(Path::from_ident(local_bind))],
|
||||
);
|
||||
let try_capture_call = self
|
||||
.cx
|
||||
|
@ -378,7 +378,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
|
|||
ident: Ident::new(sym::try_capture, self.span),
|
||||
},
|
||||
expr_paren(self.cx, self.span, self.cx.expr_addr_of(self.span, wrapper)),
|
||||
vec![expr_addr_of_mut(
|
||||
thin_vec![expr_addr_of_mut(
|
||||
self.cx,
|
||||
self.span,
|
||||
self.cx.expr_path(Path::from_ident(capture)),
|
||||
|
@ -441,7 +441,7 @@ fn expr_method_call(
|
|||
cx: &ExtCtxt<'_>,
|
||||
seg: PathSegment,
|
||||
receiver: P<Expr>,
|
||||
args: Vec<P<Expr>>,
|
||||
args: ThinVec<P<Expr>>,
|
||||
span: Span,
|
||||
) -> P<Expr> {
|
||||
cx.expr(span, ExprKind::MethodCall(Box::new(MethodCall { seg, receiver, args, span })))
|
||||
|
|
|
@ -162,7 +162,7 @@ fn cs_clone(
|
|||
let all_fields;
|
||||
let fn_path = cx.std_path(&[sym::clone, sym::Clone, sym::clone]);
|
||||
let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo| {
|
||||
let args = vec![field.self_expr.clone()];
|
||||
let args = thin_vec![field.self_expr.clone()];
|
||||
cx.expr_call_global(field.span, fn_path.clone(), args)
|
||||
};
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
|
|||
let [other_expr] = &field.other_selflike_exprs[..] else {
|
||||
cx.span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
|
||||
};
|
||||
let args = vec![field.self_expr.clone(), other_expr.clone()];
|
||||
let args = thin_vec![field.self_expr.clone(), other_expr.clone()];
|
||||
cx.expr_call_global(field.span, cmp_path.clone(), args)
|
||||
}
|
||||
CsFold::Combine(span, expr1, expr2) => {
|
||||
|
|
|
@ -98,7 +98,7 @@ fn cs_partial_cmp(
|
|||
let [other_expr] = &field.other_selflike_exprs[..] else {
|
||||
cx.span_bug(field.span, "not exactly 2 arguments in `derive(Ord)`");
|
||||
};
|
||||
let args = vec![field.self_expr.clone(), other_expr.clone()];
|
||||
let args = thin_vec![field.self_expr.clone(), other_expr.clone()];
|
||||
cx.expr_call_global(field.span, partial_cmp_path.clone(), args)
|
||||
}
|
||||
CsFold::Combine(span, mut expr1, expr2) => {
|
||||
|
|
|
@ -7,6 +7,7 @@ use rustc_ast::{self as ast, MetaItem};
|
|||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_debug(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
|
@ -94,7 +95,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
|
|||
if fields.is_empty() {
|
||||
// Special case for no fields.
|
||||
let fn_path_write_str = cx.std_path(&[sym::fmt, sym::Formatter, sym::write_str]);
|
||||
let expr = cx.expr_call_global(span, fn_path_write_str, vec![fmt, name]);
|
||||
let expr = cx.expr_call_global(span, fn_path_write_str, thin_vec![fmt, name]);
|
||||
BlockOrExpr::new_expr(expr)
|
||||
} else if fields.len() <= CUTOFF {
|
||||
// Few enough fields that we can use a specific-length method.
|
||||
|
@ -105,7 +106,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
|
|||
};
|
||||
let fn_path_debug = cx.std_path(&[sym::fmt, sym::Formatter, Symbol::intern(&debug)]);
|
||||
|
||||
let mut args = Vec::with_capacity(2 + fields.len() * args_per_field);
|
||||
let mut args = ThinVec::with_capacity(2 + fields.len() * args_per_field);
|
||||
args.extend([fmt, name]);
|
||||
for i in 0..fields.len() {
|
||||
let field = &fields[i];
|
||||
|
@ -121,8 +122,8 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
|
|||
BlockOrExpr::new_expr(expr)
|
||||
} else {
|
||||
// Enough fields that we must use the any-length method.
|
||||
let mut name_exprs = Vec::with_capacity(fields.len());
|
||||
let mut value_exprs = Vec::with_capacity(fields.len());
|
||||
let mut name_exprs = ThinVec::with_capacity(fields.len());
|
||||
let mut value_exprs = ThinVec::with_capacity(fields.len());
|
||||
|
||||
for i in 0..fields.len() {
|
||||
let field = &fields[i];
|
||||
|
@ -177,7 +178,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
|
|||
};
|
||||
let fn_path_debug_internal = cx.std_path(&[sym::fmt, sym::Formatter, sym_debug]);
|
||||
|
||||
let mut args = Vec::with_capacity(4);
|
||||
let mut args = ThinVec::with_capacity(4);
|
||||
args.push(fmt);
|
||||
args.push(name);
|
||||
if is_struct {
|
||||
|
@ -223,7 +224,7 @@ fn show_fieldless_enum(
|
|||
let pat = match &v.data {
|
||||
ast::VariantData::Tuple(fields, _) => {
|
||||
debug_assert!(fields.is_empty());
|
||||
cx.pat_tuple_struct(span, variant_path, vec![])
|
||||
cx.pat_tuple_struct(span, variant_path, thin_vec![])
|
||||
}
|
||||
ast::VariantData::Struct(fields, _) => {
|
||||
debug_assert!(fields.is_empty());
|
||||
|
@ -236,5 +237,5 @@ fn show_fieldless_enum(
|
|||
.collect::<Vec<_>>();
|
||||
let name = cx.expr_match(span, cx.expr_self(span), arms);
|
||||
let fn_path_write_str = cx.std_path(&[sym::fmt, sym::Formatter, sym::write_str]);
|
||||
BlockOrExpr::new_expr(cx.expr_call_global(span, fn_path_write_str, vec![fmt, name]))
|
||||
BlockOrExpr::new_expr(cx.expr_call_global(span, fn_path_write_str, thin_vec![fmt, name]))
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
use crate::deriving::pathvec_std;
|
||||
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, Expr, MetaItem, Mutability};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_rustc_decodable(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
|
@ -96,7 +96,7 @@ fn decodable_substructure(
|
|||
cx.expr_call_global(
|
||||
span,
|
||||
fn_read_struct_field_path.clone(),
|
||||
vec![
|
||||
thin_vec![
|
||||
blkdecoder.clone(),
|
||||
cx.expr_str(span, name),
|
||||
cx.expr_usize(span, field),
|
||||
|
@ -112,7 +112,7 @@ fn decodable_substructure(
|
|||
cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_read_struct_path,
|
||||
vec![
|
||||
thin_vec![
|
||||
decoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.expr_usize(trait_span, nfields),
|
||||
|
@ -124,7 +124,7 @@ fn decodable_substructure(
|
|||
let variant = Ident::new(sym::i, trait_span);
|
||||
|
||||
let mut arms = Vec::with_capacity(fields.len() + 1);
|
||||
let mut variants = Vec::with_capacity(fields.len());
|
||||
let mut variants = ThinVec::with_capacity(fields.len());
|
||||
|
||||
let fn_read_enum_variant_arg_path: Vec<_> =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum_variant_arg]);
|
||||
|
@ -141,7 +141,7 @@ fn decodable_substructure(
|
|||
cx.expr_call_global(
|
||||
span,
|
||||
fn_read_enum_variant_arg_path.clone(),
|
||||
vec![blkdecoder.clone(), idx, exprdecode.clone()],
|
||||
thin_vec![blkdecoder.clone(), idx, exprdecode.clone()],
|
||||
),
|
||||
)
|
||||
});
|
||||
|
@ -162,7 +162,7 @@ fn decodable_substructure(
|
|||
let result = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_read_enum_variant_path,
|
||||
vec![blkdecoder, variant_array_ref, lambda],
|
||||
thin_vec![blkdecoder, variant_array_ref, lambda],
|
||||
);
|
||||
let fn_read_enum_path: Vec<_> =
|
||||
cx.def_site_path(&[sym::rustc_serialize, sym::Decoder, sym::read_enum]);
|
||||
|
@ -170,7 +170,7 @@ fn decodable_substructure(
|
|||
cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_read_enum_path,
|
||||
vec![
|
||||
thin_vec![
|
||||
decoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.lambda1(trait_span, result, blkarg),
|
||||
|
|
|
@ -8,7 +8,7 @@ use rustc_span::symbol::Ident;
|
|||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_span::Span;
|
||||
use smallvec::SmallVec;
|
||||
use thin_vec::thin_vec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_default(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
|
@ -60,7 +60,7 @@ fn default_struct_substructure(
|
|||
) -> BlockOrExpr {
|
||||
// Note that `kw::Default` is "default" and `sym::Default` is "Default"!
|
||||
let default_ident = cx.std_path(&[kw::Default, sym::Default, kw::Default]);
|
||||
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
|
||||
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), ThinVec::new());
|
||||
|
||||
let expr = match summary {
|
||||
Unnamed(_, false) => cx.expr_ident(trait_span, substr.type_ident),
|
||||
|
|
|
@ -88,11 +88,11 @@
|
|||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
use crate::deriving::pathvec_std;
|
||||
|
||||
use rustc_ast::{AttrVec, ExprKind, MetaItem, Mutability};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand_deriving_rustc_encodable(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
|
@ -176,12 +176,13 @@ fn encodable_substructure(
|
|||
None => Symbol::intern(&format!("_field{}", i)),
|
||||
};
|
||||
let self_ref = cx.expr_addr_of(span, self_expr.clone());
|
||||
let enc = cx.expr_call(span, fn_path.clone(), vec![self_ref, blkencoder.clone()]);
|
||||
let enc =
|
||||
cx.expr_call(span, fn_path.clone(), thin_vec![self_ref, blkencoder.clone()]);
|
||||
let lambda = cx.lambda1(span, enc, blkarg);
|
||||
let call = cx.expr_call_global(
|
||||
span,
|
||||
fn_emit_struct_field_path.clone(),
|
||||
vec![
|
||||
thin_vec![
|
||||
blkencoder.clone(),
|
||||
cx.expr_str(span, name),
|
||||
cx.expr_usize(span, i),
|
||||
|
@ -203,7 +204,7 @@ fn encodable_substructure(
|
|||
|
||||
// unit structs have no fields and need to return Ok()
|
||||
let blk = if stmts.is_empty() {
|
||||
let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, vec![]));
|
||||
let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, ThinVec::new()));
|
||||
cx.lambda1(trait_span, ok, blkarg)
|
||||
} else {
|
||||
cx.lambda_stmts_1(trait_span, stmts, blkarg)
|
||||
|
@ -215,7 +216,7 @@ fn encodable_substructure(
|
|||
let expr = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_emit_struct_path,
|
||||
vec![
|
||||
thin_vec![
|
||||
encoder,
|
||||
cx.expr_str(trait_span, substr.type_ident.name),
|
||||
cx.expr_usize(trait_span, fields.len()),
|
||||
|
@ -241,14 +242,17 @@ fn encodable_substructure(
|
|||
let last = fields.len() - 1;
|
||||
for (i, &FieldInfo { ref self_expr, span, .. }) in fields.iter().enumerate() {
|
||||
let self_ref = cx.expr_addr_of(span, self_expr.clone());
|
||||
let enc =
|
||||
cx.expr_call(span, fn_path.clone(), vec![self_ref, blkencoder.clone()]);
|
||||
let enc = cx.expr_call(
|
||||
span,
|
||||
fn_path.clone(),
|
||||
thin_vec![self_ref, blkencoder.clone()],
|
||||
);
|
||||
let lambda = cx.lambda1(span, enc, blkarg);
|
||||
|
||||
let call = cx.expr_call_global(
|
||||
span,
|
||||
fn_emit_enum_variant_arg_path.clone(),
|
||||
vec![blkencoder.clone(), cx.expr_usize(span, i), lambda],
|
||||
thin_vec![blkencoder.clone(), cx.expr_usize(span, i), lambda],
|
||||
);
|
||||
let call = if i != last {
|
||||
cx.expr_try(span, call)
|
||||
|
@ -258,7 +262,7 @@ fn encodable_substructure(
|
|||
stmts.push(cx.stmt_expr(call));
|
||||
}
|
||||
} else {
|
||||
let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, vec![]));
|
||||
let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, ThinVec::new()));
|
||||
let ret_ok = cx.expr(trait_span, ExprKind::Ret(Some(ok)));
|
||||
stmts.push(cx.stmt_expr(ret_ok));
|
||||
}
|
||||
|
@ -272,7 +276,7 @@ fn encodable_substructure(
|
|||
let call = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_emit_enum_variant_path,
|
||||
vec![
|
||||
thin_vec![
|
||||
blkencoder,
|
||||
name,
|
||||
cx.expr_usize(trait_span, *idx),
|
||||
|
@ -287,7 +291,7 @@ fn encodable_substructure(
|
|||
let expr = cx.expr_call_global(
|
||||
trait_span,
|
||||
fn_emit_enum_path,
|
||||
vec![encoder, cx.expr_str(trait_span, substr.type_ident.name), blk],
|
||||
thin_vec![encoder, cx.expr_str(trait_span, substr.type_ident.name), blk],
|
||||
);
|
||||
BlockOrExpr::new_mixed(vec![me], Some(expr))
|
||||
}
|
||||
|
|
|
@ -935,8 +935,8 @@ impl<'a> MethodDef<'a> {
|
|||
trait_: &TraitDef<'_>,
|
||||
type_ident: Ident,
|
||||
generics: &Generics,
|
||||
) -> (Option<ast::ExplicitSelf>, Vec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<ast::Ty>)>) {
|
||||
let mut selflike_args = Vec::new();
|
||||
) -> (Option<ast::ExplicitSelf>, ThinVec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<ast::Ty>)>) {
|
||||
let mut selflike_args = ThinVec::new();
|
||||
let mut nonselflike_args = Vec::new();
|
||||
let mut nonself_arg_tys = Vec::new();
|
||||
let span = trait_.span;
|
||||
|
@ -1133,7 +1133,7 @@ impl<'a> MethodDef<'a> {
|
|||
trait_: &TraitDef<'b>,
|
||||
enum_def: &'b EnumDef,
|
||||
type_ident: Ident,
|
||||
selflike_args: Vec<P<Expr>>,
|
||||
selflike_args: ThinVec<P<Expr>>,
|
||||
nonselflike_args: &[P<Expr>],
|
||||
) -> BlockOrExpr {
|
||||
let span = trait_.span;
|
||||
|
@ -1188,7 +1188,7 @@ impl<'a> MethodDef<'a> {
|
|||
cx,
|
||||
span,
|
||||
sym::discriminant_value,
|
||||
vec![selflike_arg.clone()],
|
||||
thin_vec![selflike_arg.clone()],
|
||||
);
|
||||
cx.stmt_let(span, false, ident, variant_value)
|
||||
})
|
||||
|
@ -1260,7 +1260,7 @@ impl<'a> MethodDef<'a> {
|
|||
let sp = variant.span.with_ctxt(trait_.span.ctxt());
|
||||
let variant_path = cx.path(sp, vec![type_ident, variant.ident]);
|
||||
let by_ref = ByRef::No; // because enums can't be repr(packed)
|
||||
let mut subpats: Vec<_> = trait_.create_struct_patterns(
|
||||
let mut subpats = trait_.create_struct_patterns(
|
||||
cx,
|
||||
variant_path,
|
||||
&variant.data,
|
||||
|
@ -1336,7 +1336,7 @@ impl<'a> MethodDef<'a> {
|
|||
// ...
|
||||
// _ => ::core::intrinsics::unreachable()
|
||||
// }
|
||||
let get_match_expr = |mut selflike_args: Vec<P<Expr>>| {
|
||||
let get_match_expr = |mut selflike_args: ThinVec<P<Expr>>| {
|
||||
let match_arg = if selflike_args.len() == 1 {
|
||||
selflike_args.pop().unwrap()
|
||||
} else {
|
||||
|
@ -1427,7 +1427,7 @@ impl<'a> TraitDef<'a> {
|
|||
struct_def: &'a VariantData,
|
||||
prefixes: &[String],
|
||||
by_ref: ByRef,
|
||||
) -> Vec<P<ast::Pat>> {
|
||||
) -> ThinVec<P<ast::Pat>> {
|
||||
prefixes
|
||||
.iter()
|
||||
.map(|prefix| {
|
||||
|
|
|
@ -103,7 +103,7 @@ impl Ty {
|
|||
Path(p) => p.to_ty(cx, span, self_ty, self_generics),
|
||||
Self_ => cx.ty_path(self.to_path(cx, span, self_ty, self_generics)),
|
||||
Unit => {
|
||||
let ty = ast::TyKind::Tup(vec![]);
|
||||
let ty = ast::TyKind::Tup(ThinVec::new());
|
||||
cx.ty(span, ty)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crate::deriving::generic::ty::*;
|
||||
use crate::deriving::generic::*;
|
||||
use crate::deriving::{path_std, pathvec_std};
|
||||
|
||||
use rustc_ast::{AttrVec, MetaItem, Mutability};
|
||||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_span::Span;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_deriving_hash(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
|
@ -60,7 +60,7 @@ fn hash_substructure(
|
|||
|
||||
cx.expr_path(cx.path_global(span, strs))
|
||||
};
|
||||
let expr = cx.expr_call(span, hash_path, vec![expr, state_expr.clone()]);
|
||||
let expr = cx.expr_call(span, hash_path, thin_vec![expr, state_expr.clone()]);
|
||||
cx.stmt_expr(expr)
|
||||
};
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ fn call_intrinsic(
|
|||
cx: &ExtCtxt<'_>,
|
||||
span: Span,
|
||||
intrinsic: Symbol,
|
||||
args: Vec<P<ast::Expr>>,
|
||||
args: ThinVec<P<ast::Expr>>,
|
||||
) -> P<ast::Expr> {
|
||||
let span = cx.with_def_site_ctxt(span);
|
||||
let path = cx.std_path(&[sym::intrinsics, intrinsic]);
|
||||
|
@ -104,7 +104,7 @@ fn call_intrinsic(
|
|||
fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P<ast::Expr> {
|
||||
let span = cx.with_def_site_ctxt(span);
|
||||
let path = cx.std_path(&[sym::intrinsics, sym::unreachable]);
|
||||
let call = cx.expr_call_global(span, path, vec![]);
|
||||
let call = cx.expr_call_global(span, path, ThinVec::new());
|
||||
|
||||
cx.expr_block(P(ast::Block {
|
||||
stmts: vec![cx.stmt_expr(call)],
|
||||
|
|
|
@ -8,8 +8,8 @@ use rustc_ast::{self as ast, GenericArg};
|
|||
use rustc_expand::base::{self, *};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
use std::env;
|
||||
use thin_vec::thin_vec;
|
||||
|
||||
pub fn expand_option_env<'cx>(
|
||||
cx: &'cx mut ExtCtxt<'_>,
|
||||
|
@ -41,7 +41,7 @@ pub fn expand_option_env<'cx>(
|
|||
Some(value) => cx.expr_call_global(
|
||||
sp,
|
||||
cx.std_path(&[sym::option, sym::Option, sym::Some]),
|
||||
vec![cx.expr_str(sp, value)],
|
||||
thin_vec![cx.expr_str(sp, value)],
|
||||
),
|
||||
};
|
||||
MacEager::expr(e)
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc_ast::{Fn, ItemKind, Mutability, Stmt, Ty, TyKind, Unsafe};
|
|||
use rustc_expand::base::{Annotatable, ExtCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use thin_vec::thin_vec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub fn expand(
|
||||
ecx: &mut ExtCtxt<'_>,
|
||||
|
@ -47,7 +47,7 @@ pub fn expand(
|
|||
let stmts = ALLOCATOR_METHODS.iter().map(|method| f.allocator_fn(method)).collect();
|
||||
|
||||
// Generate anonymous constant serving as container for the allocator methods.
|
||||
let const_ty = ecx.ty(ty_span, TyKind::Tup(Vec::new()));
|
||||
let const_ty = ecx.ty(ty_span, TyKind::Tup(ThinVec::new()));
|
||||
let const_body = ecx.expr_block(ecx.block(span, stmts));
|
||||
let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body);
|
||||
let const_item = if is_stmt {
|
||||
|
@ -70,7 +70,7 @@ struct AllocFnFactory<'a, 'b> {
|
|||
|
||||
impl AllocFnFactory<'_, '_> {
|
||||
fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt {
|
||||
let mut abi_args = Vec::new();
|
||||
let mut abi_args = ThinVec::new();
|
||||
let mut i = 0;
|
||||
let mut mk = || {
|
||||
let name = Ident::from_str_and_span(&format!("arg{}", i), self.span);
|
||||
|
@ -99,7 +99,7 @@ impl AllocFnFactory<'_, '_> {
|
|||
self.cx.stmt_item(self.ty_span, item)
|
||||
}
|
||||
|
||||
fn call_allocator(&self, method: Symbol, mut args: Vec<P<Expr>>) -> P<Expr> {
|
||||
fn call_allocator(&self, method: Symbol, mut args: ThinVec<P<Expr>>) -> P<Expr> {
|
||||
let method = self.cx.std_path(&[sym::alloc, sym::GlobalAlloc, method]);
|
||||
let method = self.cx.expr_path(self.cx.path(self.ty_span, method));
|
||||
let allocator = self.cx.path_ident(self.ty_span, self.global);
|
||||
|
@ -117,7 +117,7 @@ impl AllocFnFactory<'_, '_> {
|
|||
fn arg_ty(
|
||||
&self,
|
||||
ty: &AllocatorTy,
|
||||
args: &mut Vec<Param>,
|
||||
args: &mut ThinVec<Param>,
|
||||
ident: &mut dyn FnMut() -> Ident,
|
||||
) -> P<Expr> {
|
||||
match *ty {
|
||||
|
@ -134,7 +134,7 @@ impl AllocFnFactory<'_, '_> {
|
|||
let layout_new = self.cx.expr_path(self.cx.path(self.span, layout_new));
|
||||
let size = self.cx.expr_ident(self.span, size);
|
||||
let align = self.cx.expr_ident(self.span, align);
|
||||
let layout = self.cx.expr_call(self.span, layout_new, vec![size, align]);
|
||||
let layout = self.cx.expr_call(self.span, layout_new, thin_vec![size, align]);
|
||||
layout
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ impl AllocFnFactory<'_, '_> {
|
|||
(self.ptr_u8(), expr)
|
||||
}
|
||||
|
||||
AllocatorTy::Unit => (self.cx.ty(self.span, TyKind::Tup(Vec::new())), expr),
|
||||
AllocatorTy::Unit => (self.cx.ty(self.span, TyKind::Tup(ThinVec::new())), expr),
|
||||
|
||||
AllocatorTy::Layout | AllocatorTy::Usize | AllocatorTy::Ptr => {
|
||||
panic!("can't convert `AllocatorTy` to an output")
|
||||
|
|
|
@ -11,6 +11,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
|||
use rustc_span::{Span, DUMMY_SP};
|
||||
use smallvec::smallvec;
|
||||
use std::mem;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
struct ProcMacroDerive {
|
||||
id: NodeId,
|
||||
|
@ -314,11 +315,14 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
|
|||
cx.expr_call(
|
||||
span,
|
||||
proc_macro_ty_method_path(cx, custom_derive),
|
||||
vec![
|
||||
thin_vec![
|
||||
cx.expr_str(span, cd.trait_name),
|
||||
cx.expr_array_ref(
|
||||
span,
|
||||
cd.attrs.iter().map(|&s| cx.expr_str(span, s)).collect::<Vec<_>>(),
|
||||
cd.attrs
|
||||
.iter()
|
||||
.map(|&s| cx.expr_str(span, s))
|
||||
.collect::<ThinVec<_>>(),
|
||||
),
|
||||
local_path(cx, cd.function_name),
|
||||
],
|
||||
|
@ -335,7 +339,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
|
|||
cx.expr_call(
|
||||
span,
|
||||
proc_macro_ty_method_path(cx, ident),
|
||||
vec![
|
||||
thin_vec![
|
||||
cx.expr_str(span, ca.function_name.name),
|
||||
local_path(cx, ca.function_name),
|
||||
],
|
||||
|
@ -377,7 +381,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
|
|||
let anon_constant = cx.item_const(
|
||||
span,
|
||||
Ident::new(kw::Underscore, span),
|
||||
cx.ty(span, ast::TyKind::Tup(Vec::new())),
|
||||
cx.ty(span, ast::TyKind::Tup(ThinVec::new())),
|
||||
block,
|
||||
);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_session::Session;
|
|||
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
use std::iter;
|
||||
use thin_vec::thin_vec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
/// #[test_case] is used by custom test authors to mark tests
|
||||
/// When building for test, it needs to make the item public and gensym the name
|
||||
|
@ -179,19 +179,19 @@ pub fn expand_test_or_bench(
|
|||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("StaticBenchFn")),
|
||||
vec![
|
||||
thin_vec![
|
||||
// |b| self::test::assert_test_result(
|
||||
cx.lambda1(
|
||||
sp,
|
||||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("assert_test_result")),
|
||||
vec![
|
||||
thin_vec![
|
||||
// super::$test_fn(b)
|
||||
cx.expr_call(
|
||||
ret_ty_sp,
|
||||
cx.expr_path(cx.path(sp, vec![item.ident])),
|
||||
vec![cx.expr_ident(sp, b)],
|
||||
thin_vec![cx.expr_ident(sp, b)],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -203,7 +203,7 @@ pub fn expand_test_or_bench(
|
|||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("StaticTestFn")),
|
||||
vec![
|
||||
thin_vec![
|
||||
// || {
|
||||
cx.lambda0(
|
||||
sp,
|
||||
|
@ -211,12 +211,12 @@ pub fn expand_test_or_bench(
|
|||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("assert_test_result")),
|
||||
vec![
|
||||
thin_vec![
|
||||
// $test_fn()
|
||||
cx.expr_call(
|
||||
ret_ty_sp,
|
||||
cx.expr_path(cx.path(sp, vec![item.ident])),
|
||||
vec![],
|
||||
ThinVec::new(),
|
||||
), // )
|
||||
],
|
||||
), // }
|
||||
|
@ -263,7 +263,7 @@ pub fn expand_test_or_bench(
|
|||
cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(test_path("StaticTestName")),
|
||||
vec![cx.expr_str(sp, test_path_symbol)],
|
||||
thin_vec![cx.expr_str(sp, test_path_symbol)],
|
||||
),
|
||||
),
|
||||
// ignore: true | false
|
||||
|
@ -300,7 +300,7 @@ pub fn expand_test_or_bench(
|
|||
ShouldPanic::Yes(Some(sym)) => cx.expr_call(
|
||||
sp,
|
||||
cx.expr_path(should_panic_path("YesWithMessage")),
|
||||
vec![cx.expr_str(sp, sym)],
|
||||
thin_vec![cx.expr_str(sp, sym)],
|
||||
),
|
||||
},
|
||||
),
|
||||
|
|
|
@ -14,7 +14,8 @@ use rustc_span::symbol::{sym, Ident, Symbol};
|
|||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use thin_vec::thin_vec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
use tracing::debug;
|
||||
|
||||
use std::{iter, mem};
|
||||
|
||||
|
@ -299,7 +300,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
|||
test_runner.span = sp;
|
||||
|
||||
let test_main_path_expr = ecx.expr_path(test_runner);
|
||||
let call_test_main = ecx.expr_call(sp, test_main_path_expr, vec![mk_tests_slice(cx, sp)]);
|
||||
let call_test_main = ecx.expr_call(sp, test_main_path_expr, thin_vec![mk_tests_slice(cx, sp)]);
|
||||
let call_test_main = ecx.stmt_expr(call_test_main);
|
||||
|
||||
// extern crate test
|
||||
|
@ -312,7 +313,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
|||
let main_attr = ecx.attr_word(sym::rustc_main, sp);
|
||||
|
||||
// pub fn main() { ... }
|
||||
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![]));
|
||||
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()));
|
||||
|
||||
// If no test runner is provided we need to import the test crate
|
||||
let main_body = if cx.test_runner.is_none() {
|
||||
|
@ -321,7 +322,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
|
|||
ecx.block(sp, vec![call_test_main])
|
||||
};
|
||||
|
||||
let decl = ecx.fn_decl(vec![], ast::FnRetTy::Ty(main_ret_ty));
|
||||
let decl = ecx.fn_decl(ThinVec::new(), ast::FnRetTy::Ty(main_ret_ty));
|
||||
let sig = ast::FnSig { decl, header: ast::FnHeader::default(), span: sp };
|
||||
let defaultness = ast::Defaultness::Final;
|
||||
let main = ast::ItemKind::Fn(Box::new(ast::Fn {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue