Skip to content

Commit 8a23ad1

Browse files
committed
Update comments in rustc_ast_lowering/src/format.rs.
1 parent 0a1934a commit 8a23ad1

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ enum ArgumentType {
2222
Usize,
2323
}
2424

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+
/// ```
2532
fn make_argument<'hir>(
2633
ctx: &mut LoweringContext<'_, 'hir>,
2734
sp: Span,
2835
arg: &'hir hir::Expr<'hir>,
2936
ty: ArgumentType,
3037
) -> hir::Expr<'hir> {
31-
// Generate:
32-
// ::core::fmt::ArgumentV1::new_…(arg)
3338
use ArgumentType::*;
3439
use FormatTrait::*;
3540
let new_fn = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
@@ -51,14 +56,31 @@ fn make_argument<'hir>(
5156
ctx.expr_call_mut(sp, new_fn, std::slice::from_ref(arg))
5257
}
5358

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+
/// ```
5478
fn make_count<'hir>(
5579
ctx: &mut LoweringContext<'_, 'hir>,
5680
sp: Span,
5781
count: &Option<FormatCount>,
5882
argmap: &mut FxIndexSet<(usize, ArgumentType)>,
5983
) -> hir::Expr<'hir> {
60-
// Generate:
61-
// ::core::fmt::rt::v1::Count::…(…)
6284
match count {
6385
Some(FormatCount::Literal(n)) => {
6486
let count_is = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
@@ -87,21 +109,26 @@ fn make_count<'hir>(
87109
}
88110
}
89111

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+
/// ```
90126
fn make_format_spec<'hir>(
91127
ctx: &mut LoweringContext<'_, 'hir>,
92128
sp: Span,
93129
placeholder: &FormatPlaceholder,
94130
argmap: &mut FxIndexSet<(usize, ArgumentType)>,
95131
) -> 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-
// )
105132
let position = match placeholder.argument.index {
106133
Ok(arg_index) => {
107134
let (i, _) =
@@ -203,9 +230,10 @@ fn expand_format_args<'hir>(
203230
let args = if use_simple_array {
204231
// Generate:
205232
// &[
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+
// …
209237
// ]
210238
let elements: Vec<_> = arguments
211239
.iter()
@@ -223,11 +251,12 @@ fn expand_format_args<'hir>(
223251
ctx.expr_array_ref(macsp, ctx.arena.alloc_from_iter(elements))
224252
} else {
225253
// Generate:
226-
// &match (&arg0, &arg1, &arg2) {
254+
// &match (&arg0, &arg1, &) {
227255
// 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+
// …
231260
// ]
232261
// }
233262
let args_ident = Ident::new(sym::args, macsp);
@@ -277,7 +306,7 @@ fn expand_format_args<'hir>(
277306

278307
if let Some(format_options) = format_options {
279308
// Generate:
280-
// ::core::fmt::Arguments::new_v1_formatted(
309+
// <core::fmt::Arguments>::new_v1_formatted(
281310
// lit_pieces,
282311
// args,
283312
// format_options,
@@ -307,7 +336,7 @@ fn expand_format_args<'hir>(
307336
hir::ExprKind::Call(new_v1_formatted, args)
308337
} else {
309338
// Generate:
310-
// ::core::fmt::Arguments::new_v1(
339+
// <core::fmt::Arguments>::new_v1(
311340
// lit_pieces,
312341
// args,
313342
// )

0 commit comments

Comments
 (0)