From 78060cb6de9aba3be1dc5c883cf54eb98a084e22 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Tue, 6 Dec 2022 12:02:56 +0000 Subject: Box `rustc_parse_format::Piece::NextArgument` This makes both variants closer together in size (previously they were different by 208 bytes -- 16 vs 224). This may make things worse, but it's worth a try. --- compiler/rustc_parse_format/src/lib.rs | 6 +-- compiler/rustc_parse_format/src/tests.rs | 80 ++++++++++++++++---------------- 2 files changed, 43 insertions(+), 43 deletions(-) (limited to 'compiler/rustc_parse_format/src') diff --git a/compiler/rustc_parse_format/src/lib.rs b/compiler/rustc_parse_format/src/lib.rs index 0113eb4e3d1..4d01f706272 100644 --- a/compiler/rustc_parse_format/src/lib.rs +++ b/compiler/rustc_parse_format/src/lib.rs @@ -58,13 +58,13 @@ impl InnerOffset { /// A piece is a portion of the format string which represents the next part /// to emit. These are emitted as a stream by the `Parser` class. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub enum Piece<'a> { /// A literal string which should directly be emitted String(&'a str), /// This describes that formatting should process the next argument (as /// specified inside) for emission. - NextArgument(Argument<'a>), + NextArgument(Box>), } /// Representation of an argument specification. @@ -244,7 +244,7 @@ impl<'a> Iterator for Parser<'a> { } else { self.suggest_positional_arg_instead_of_captured_arg(arg); } - Some(NextArgument(arg)) + Some(NextArgument(Box::new(arg))) } } '}' => { diff --git a/compiler/rustc_parse_format/src/tests.rs b/compiler/rustc_parse_format/src/tests.rs index 3f9cb149b53..2992ba845ab 100644 --- a/compiler/rustc_parse_format/src/tests.rs +++ b/compiler/rustc_parse_format/src/tests.rs @@ -76,51 +76,51 @@ fn invalid_precision() { fn format_nothing() { same( "{}", - &[NextArgument(Argument { + &[NextArgument(Box::new(Argument { position: ArgumentImplicitlyIs(0), position_span: InnerSpan { start: 2, end: 2 }, format: fmtdflt(), - })], + }))], ); } #[test] fn format_position() { same( "{3}", - &[NextArgument(Argument { + &[NextArgument(Box::new(Argument { position: ArgumentIs(3), position_span: InnerSpan { start: 2, end: 3 }, format: fmtdflt(), - })], + }))], ); } #[test] fn format_position_nothing_else() { same( "{3:}", - &[NextArgument(Argument { + &[NextArgument(Box::new(Argument { position: ArgumentIs(3), position_span: InnerSpan { start: 2, end: 3 }, format: fmtdflt(), - })], + }))], ); } #[test] fn format_named() { same( "{name}", - &[NextArgument(Argument { + &[NextArgument(Box::new(Argument { position: ArgumentNamed("name"), position_span: InnerSpan { start: 2, end: 6 }, format: fmtdflt(), - })], + }))], ) } #[test] fn format_type() { same( "{3:x}", - &[NextArgument(Argument { + &[NextArgument(Box::new(Argument { position: ArgumentIs(3), position_span: InnerSpan { start: 2, end: 3 }, format: FormatSpec { @@ -134,14 +134,14 @@ fn format_type() { ty: "x", ty_span: None, }, - })], + }))], ); } #[test] fn format_align_fill() { same( "{3:>}", - &[NextArgument(Argument { + &[NextArgument(Box::new(Argument { position: ArgumentIs(3), position_span: InnerSpan { start: 2, end: 3 }, format: FormatSpec { @@ -155,11 +155,11 @@ fn format_align_fill() { ty: "", ty_span: None, }, - })], + }))], ); same( "{3:0<}", - &[NextArgument(Argument { + &[NextArgument(Box::new(Argument { position: ArgumentIs(3), position_span: InnerSpan { start: 2, end: 3 }, format: FormatSpec { @@ -173,11 +173,11 @@ fn format_align_fill() { ty: "", ty_span: None, }, - })], + }))], ); same( "{3:*