@@ -22,14 +22,19 @@ enum ArgumentType {
22
22
Usize ,
23
23
}
24
24
25
+ /// Generate a hir expression representing an argument to a format_args invocation.
26
+ ///
27
+ /// Generates:
28
+ ///
29
+ /// ```text
30
+ /// <core::fmt::ArgumentV1>::new_…(arg)
31
+ /// ```
25
32
fn make_argument < ' hir > (
26
33
ctx : & mut LoweringContext < ' _ , ' hir > ,
27
34
sp : Span ,
28
35
arg : & ' hir hir:: Expr < ' hir > ,
29
36
ty : ArgumentType ,
30
37
) -> hir:: Expr < ' hir > {
31
- // Generate:
32
- // ::core::fmt::ArgumentV1::new_…(arg)
33
38
use ArgumentType :: * ;
34
39
use FormatTrait :: * ;
35
40
let new_fn = ctx. arena . alloc ( ctx. expr_lang_item_type_relative (
@@ -51,14 +56,31 @@ fn make_argument<'hir>(
51
56
ctx. expr_call_mut ( sp, new_fn, std:: slice:: from_ref ( arg) )
52
57
}
53
58
59
+ /// Generate a hir expression for a format_args Count.
60
+ ///
61
+ /// Generates:
62
+ ///
63
+ /// ```text
64
+ /// <core::fmt::rt::v1::Count>::Is(…)
65
+ /// ```
66
+ ///
67
+ /// or
68
+ ///
69
+ /// ```text
70
+ /// <core::fmt::rt::v1::Count>::Param(…)
71
+ /// ```
72
+ ///
73
+ /// or
74
+ ///
75
+ /// ```text
76
+ /// <core::fmt::rt::v1::Count>::Implied
77
+ /// ```
54
78
fn make_count < ' hir > (
55
79
ctx : & mut LoweringContext < ' _ , ' hir > ,
56
80
sp : Span ,
57
81
count : & Option < FormatCount > ,
58
82
argmap : & mut FxIndexSet < ( usize , ArgumentType ) > ,
59
83
) -> hir:: Expr < ' hir > {
60
- // Generate:
61
- // ::core::fmt::rt::v1::Count::…(…)
62
84
match count {
63
85
Some ( FormatCount :: Literal ( n) ) => {
64
86
let count_is = ctx. arena . alloc ( ctx. expr_lang_item_type_relative (
@@ -87,21 +109,26 @@ fn make_count<'hir>(
87
109
}
88
110
}
89
111
112
+ /// Generate a hir expression for a format_args placeholder specification.
113
+ ///
114
+ /// Generates
115
+ ///
116
+ /// ```text
117
+ /// <core::fmt::rt::v1::Argument::new(
118
+ /// …usize, // position
119
+ /// '…', // fill
120
+ /// <core::fmt::rt::v1::Alignment>::…, // alignment
121
+ /// …u32, // flags
122
+ /// <core::fmt::rt::v1::Count::…>, // width
123
+ /// <core::fmt::rt::v1::Count::…>, // precision
124
+ /// )
125
+ /// ```
90
126
fn make_format_spec < ' hir > (
91
127
ctx : & mut LoweringContext < ' _ , ' hir > ,
92
128
sp : Span ,
93
129
placeholder : & FormatPlaceholder ,
94
130
argmap : & mut FxIndexSet < ( usize , ArgumentType ) > ,
95
131
) -> hir:: Expr < ' hir > {
96
- // Generate:
97
- // ::core::fmt::rt::v1::Argument::new(
98
- // 0usize, // position
99
- // ' ', // fill
100
- // ::core::fmt::rt::v1::Alignment::Unknown,
101
- // 0u32, // flags
102
- // ::core::fmt::rt::v1::Count::Implied, // width
103
- // ::core::fmt::rt::v1::Count::Implied, // precision
104
- // )
105
132
let position = match placeholder. argument . index {
106
133
Ok ( arg_index) => {
107
134
let ( i, _) =
@@ -203,9 +230,10 @@ fn expand_format_args<'hir>(
203
230
let args = if use_simple_array {
204
231
// Generate:
205
232
// &[
206
- // ::core::fmt::ArgumentV1::new_display(&arg0),
207
- // ::core::fmt::ArgumentV1::new_lower_hex(&arg1),
208
- // ::core::fmt::ArgumentV1::new_debug(&arg2),
233
+ // <core::fmt::ArgumentV1>::new_display(&arg0),
234
+ // <core::fmt::ArgumentV1>::new_lower_hex(&arg1),
235
+ // <core::fmt::ArgumentV1>::new_debug(&arg2),
236
+ // …
209
237
// ]
210
238
let elements: Vec < _ > = arguments
211
239
. iter ( )
@@ -223,11 +251,12 @@ fn expand_format_args<'hir>(
223
251
ctx. expr_array_ref ( macsp, ctx. arena . alloc_from_iter ( elements) )
224
252
} else {
225
253
// Generate:
226
- // &match (&arg0, &arg1, &arg2 ) {
254
+ // &match (&arg0, &arg1, &… ) {
227
255
// args => [
228
- // ::core::fmt::ArgumentV1::new_display(args.0),
229
- // ::core::fmt::ArgumentV1::new_lower_hex(args.1),
230
- // ::core::fmt::ArgumentV1::new_debug(args.0),
256
+ // <core::fmt::ArgumentV1>::new_display(args.0),
257
+ // <core::fmt::ArgumentV1>::new_lower_hex(args.1),
258
+ // <core::fmt::ArgumentV1>::new_debug(args.0),
259
+ // …
231
260
// ]
232
261
// }
233
262
let args_ident = Ident :: new ( sym:: args, macsp) ;
@@ -277,7 +306,7 @@ fn expand_format_args<'hir>(
277
306
278
307
if let Some ( format_options) = format_options {
279
308
// Generate:
280
- // :: core::fmt::Arguments::new_v1_formatted(
309
+ // < core::fmt::Arguments> ::new_v1_formatted(
281
310
// lit_pieces,
282
311
// args,
283
312
// format_options,
@@ -307,7 +336,7 @@ fn expand_format_args<'hir>(
307
336
hir:: ExprKind :: Call ( new_v1_formatted, args)
308
337
} else {
309
338
// Generate:
310
- // :: core::fmt::Arguments::new_v1(
339
+ // < core::fmt::Arguments> ::new_v1(
311
340
// lit_pieces,
312
341
// args,
313
342
// )
0 commit comments