1
- use rustc_ast :: ptr:: P ;
2
- use rustc_ast :: Expr ;
1
+ use crate :: ptr:: P ;
2
+ use crate :: Expr ;
3
3
use rustc_data_structures:: fx:: FxHashMap ;
4
4
use rustc_span:: symbol:: { Ident , Symbol } ;
5
5
use rustc_span:: Span ;
@@ -39,7 +39,7 @@ use rustc_span::Span;
39
39
/// Basically the "AST" for a complete `format_args!()`.
40
40
///
41
41
/// E.g., `format_args!("hello {name}");`.
42
- #[ derive( Clone , Debug ) ]
42
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
43
43
pub struct FormatArgs {
44
44
pub span : Span ,
45
45
pub template : Vec < FormatArgsPiece > ,
@@ -49,7 +49,7 @@ pub struct FormatArgs {
49
49
/// A piece of a format template string.
50
50
///
51
51
/// E.g. "hello" or "{name}".
52
- #[ derive( Clone , Debug ) ]
52
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
53
53
pub enum FormatArgsPiece {
54
54
Literal ( Symbol ) ,
55
55
Placeholder ( FormatPlaceholder ) ,
@@ -59,7 +59,7 @@ pub enum FormatArgsPiece {
59
59
///
60
60
/// E.g. `1, 2, name="ferris", n=3`,
61
61
/// but also implicit captured arguments like `x` in `format_args!("{x}")`.
62
- #[ derive( Clone , Debug ) ]
62
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
63
63
pub struct FormatArguments {
64
64
arguments : Vec < FormatArgument > ,
65
65
num_unnamed_args : usize ,
@@ -121,18 +121,22 @@ impl FormatArguments {
121
121
& self . arguments [ ..self . num_explicit_args ]
122
122
}
123
123
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 [ ..]
126
130
}
127
131
}
128
132
129
- #[ derive( Clone , Debug ) ]
133
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
130
134
pub struct FormatArgument {
131
135
pub kind : FormatArgumentKind ,
132
136
pub expr : P < Expr > ,
133
137
}
134
138
135
- #[ derive( Clone , Debug ) ]
139
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
136
140
pub enum FormatArgumentKind {
137
141
/// `format_args(…, arg)`
138
142
Normal ,
@@ -152,7 +156,7 @@ impl FormatArgumentKind {
152
156
}
153
157
}
154
158
155
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
159
+ #[ derive( Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
156
160
pub struct FormatPlaceholder {
157
161
/// Index into [`FormatArgs::arguments`].
158
162
pub argument : FormatArgPosition ,
@@ -164,7 +168,7 @@ pub struct FormatPlaceholder {
164
168
pub format_options : FormatOptions ,
165
169
}
166
170
167
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
171
+ #[ derive( Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
168
172
pub struct FormatArgPosition {
169
173
/// Which argument this position refers to (Ok),
170
174
/// or would've referred to if it existed (Err).
@@ -175,7 +179,7 @@ pub struct FormatArgPosition {
175
179
pub span : Option < Span > ,
176
180
}
177
181
178
- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
182
+ #[ derive( Copy , Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
179
183
pub enum FormatArgPositionKind {
180
184
/// `{}` or `{:.*}`
181
185
Implicit ,
@@ -185,7 +189,7 @@ pub enum FormatArgPositionKind {
185
189
Named ,
186
190
}
187
191
188
- #[ derive( Copy , Clone , Debug , Hash , PartialEq , Eq ) ]
192
+ #[ derive( Copy , Clone , Encodable , Decodable , Debug , PartialEq , Eq , Hash ) ]
189
193
pub enum FormatTrait {
190
194
/// `{}`
191
195
Display ,
@@ -207,7 +211,7 @@ pub enum FormatTrait {
207
211
UpperHex ,
208
212
}
209
213
210
- #[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
214
+ #[ derive( Clone , Encodable , Decodable , Default , Debug , PartialEq , Eq ) ]
211
215
pub struct FormatOptions {
212
216
/// The width. E.g. `{:5}` or `{:width$}`.
213
217
pub width : Option < FormatCount > ,
@@ -221,7 +225,7 @@ pub struct FormatOptions {
221
225
pub flags : u32 ,
222
226
}
223
227
224
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
228
+ #[ derive( Copy , Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
225
229
pub enum FormatAlignment {
226
230
/// `{:<}`
227
231
Left ,
@@ -231,7 +235,7 @@ pub enum FormatAlignment {
231
235
Center ,
232
236
}
233
237
234
- #[ derive( Clone , Debug , PartialEq , Eq ) ]
238
+ #[ derive( Clone , Encodable , Decodable , Debug , PartialEq , Eq ) ]
235
239
pub enum FormatCount {
236
240
/// `{:5}` or `{:.5}`
237
241
Literal ( usize ) ,
0 commit comments