From 4f9fe856a25ab29345b90e7725509e9ee38a37be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:41 +0200 Subject: Adding upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- .../rustc_builtin_macros/src/deriving/encodable.rs | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'compiler/rustc_builtin_macros/src/deriving/encodable.rs') diff --git a/compiler/rustc_builtin_macros/src/deriving/encodable.rs b/compiler/rustc_builtin_macros/src/deriving/encodable.rs index 2afeed927..a3b11309d 100644 --- a/compiler/rustc_builtin_macros/src/deriving/encodable.rs +++ b/compiler/rustc_builtin_macros/src/deriving/encodable.rs @@ -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<'_>, @@ -109,6 +109,7 @@ pub fn expand_deriving_rustc_encodable( span, path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global), skip_path_as_bound: false, + needs_copy_as_bound_if_packed: true, additional_bounds: Vec::new(), supports_unions: false, methods: vec![MethodDef { @@ -168,19 +169,20 @@ fn encodable_substructure( Struct(_, fields) => { let fn_emit_struct_field_path = cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_struct_field]); - let mut stmts = Vec::new(); + let mut stmts = ThinVec::new(); for (i, &FieldInfo { name, ref self_expr, span, .. }) in fields.iter().enumerate() { let name = match name { Some(id) => id.name, 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), @@ -202,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) @@ -214,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()), @@ -235,19 +237,22 @@ fn encodable_substructure( let fn_emit_enum_variant_arg_path: Vec<_> = cx.def_site_path(&[sym::rustc_serialize, sym::Encoder, sym::emit_enum_variant_arg]); - let mut stmts = Vec::new(); + let mut stmts = ThinVec::new(); if !fields.is_empty() { 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) @@ -257,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)); } @@ -271,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), @@ -286,9 +291,9 @@ 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)) + BlockOrExpr::new_mixed(thin_vec![me], Some(expr)) } _ => cx.bug("expected Struct or EnumMatching in derive(Encodable)"), -- cgit v1.2.3