1- use rustc_ast :: ptr:: P ;
2- use rustc_ast :: Expr ;
1+ use crate :: ptr:: P ;
2+ use crate :: Expr ;
33use rustc_data_structures:: fx:: FxHashMap ;
44use rustc_span:: symbol:: { Ident , Symbol } ;
55use rustc_span:: Span ;
@@ -39,7 +39,7 @@ use rustc_span::Span;
3939/// Basically the "AST" for a complete `format_args!()`.
4040///
4141/// E.g., `format_args!("hello {name}");`.
42- #[ derive( Clone , Debug ) ]
42+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
4343pub struct FormatArgs {
4444 pub span : Span ,
4545 pub template : Vec < FormatArgsPiece > ,
@@ -49,7 +49,7 @@ pub struct FormatArgs {
4949/// A piece of a format template string.
5050///
5151/// E.g. "hello" or "{name}".
52- #[ derive( Clone , Debug ) ]
52+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
5353pub enum FormatArgsPiece {
5454 Literal ( Symbol ) ,
5555 Placeholder ( FormatPlaceholder ) ,
@@ -59,7 +59,7 @@ pub enum FormatArgsPiece {
5959///
6060/// E.g. `1, 2, name="ferris", n=3`,
6161/// but also implicit captured arguments like `x` in `format_args!("{x}")`.
62- #[ derive( Clone , Debug ) ]
62+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
6363pub struct FormatArguments {
6464 arguments : Vec < FormatArgument > ,
6565 num_unnamed_args : usize ,
@@ -121,18 +121,22 @@ impl FormatArguments {
121121 & self . arguments [ ..self . num_explicit_args ]
122122 }
123123
124- pub fn into_vec ( self ) -> Vec < FormatArgument > {
125- self . arguments
124+ pub fn all_args ( & self ) -> & [ FormatArgument ] {
125+ & self . arguments [ ..]
126+ }
127+
128+ pub fn all_args_mut ( & mut self ) -> & mut [ FormatArgument ] {
129+ & mut self . arguments [ ..]
126130 }
127131}
128132
129- #[ derive( Clone , Debug ) ]
133+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
130134pub struct FormatArgument {
131135 pub kind : FormatArgumentKind ,
132136 pub expr : P < Expr > ,
133137}
134138
135- #[ derive( Clone , Debug ) ]
139+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
136140pub enum FormatArgumentKind {
137141 /// `format_args(…, arg)`
138142 Normal ,
@@ -152,7 +156,7 @@ impl FormatArgumentKind {
152156 }
153157}
154158
155- #[ derive( Clone , Debug , PartialEq , Eq ) ]
159+ #[ derive( Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
156160pub struct FormatPlaceholder {
157161 /// Index into [`FormatArgs::arguments`].
158162 pub argument : FormatArgPosition ,
@@ -164,7 +168,7 @@ pub struct FormatPlaceholder {
164168 pub format_options : FormatOptions ,
165169}
166170
167- #[ derive( Clone , Debug , PartialEq , Eq ) ]
171+ #[ derive( Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
168172pub struct FormatArgPosition {
169173 /// Which argument this position refers to (Ok),
170174 /// or would've referred to if it existed (Err).
@@ -175,7 +179,7 @@ pub struct FormatArgPosition {
175179 pub span : Option < Span > ,
176180}
177181
178- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
182+ #[ derive( Copy , Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
179183pub enum FormatArgPositionKind {
180184 /// `{}` or `{:.*}`
181185 Implicit ,
@@ -185,7 +189,7 @@ pub enum FormatArgPositionKind {
185189 Named ,
186190}
187191
188- #[ derive( Copy , Clone , Debug , Hash , PartialEq , Eq ) ]
192+ #[ derive( Copy , Clone , Encodable , Decodable , Debug , PartialEq , Eq , Hash ) ]
189193pub enum FormatTrait {
190194 /// `{}`
191195 Display ,
@@ -207,7 +211,7 @@ pub enum FormatTrait {
207211 UpperHex ,
208212}
209213
210- #[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
214+ #[ derive( Clone , Encodable , Decodable , Default , Debug , PartialEq , Eq ) ]
211215pub struct FormatOptions {
212216 /// The width. E.g. `{:5}` or `{:width$}`.
213217 pub width : Option < FormatCount > ,
@@ -221,7 +225,7 @@ pub struct FormatOptions {
221225 pub flags : u32 ,
222226}
223227
224- #[ derive( Clone , Debug , PartialEq , Eq ) ]
228+ #[ derive( Copy , Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
225229pub enum FormatAlignment {
226230 /// `{:<}`
227231 Left ,
@@ -231,7 +235,7 @@ pub enum FormatAlignment {
231235 Center ,
232236}
233237
234- #[ derive( Clone , Debug , PartialEq , Eq ) ]
238+ #[ derive( Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
235239pub enum FormatCount {
236240 /// `{:5}` or `{:.5}`
237241 Literal ( usize ) ,
0 commit comments