Simplify expansion for format_args!().
Instead of calling new(), we can just use a struct expression directly. Before: Placeholder::new(…, …, …, …) After: Placeholder { position: …, flags: …, width: …, precision: …, }
This commit is contained in:
parent
5cc60728e7
commit
cc5ee70b1a
3 changed files with 18 additions and 22 deletions
|
@ -323,14 +323,12 @@ fn make_count<'hir>(
|
||||||
/// Generates
|
/// Generates
|
||||||
///
|
///
|
||||||
/// ```text
|
/// ```text
|
||||||
/// <core::fmt::rt::Placeholder::new(
|
/// <core::fmt::rt::Placeholder {
|
||||||
/// …usize, // position
|
/// position: …usize,
|
||||||
/// '…', // fill
|
/// flags: …u32,
|
||||||
/// <core::fmt::rt::Alignment>::…, // alignment
|
/// precision: <core::fmt::rt::Count::…>,
|
||||||
/// …u32, // flags
|
/// width: <core::fmt::rt::Count::…>,
|
||||||
/// <core::fmt::rt::Count::…>, // width
|
/// }
|
||||||
/// <core::fmt::rt::Count::…>, // precision
|
|
||||||
/// )
|
|
||||||
/// ```
|
/// ```
|
||||||
fn make_format_spec<'hir>(
|
fn make_format_spec<'hir>(
|
||||||
ctx: &mut LoweringContext<'_, 'hir>,
|
ctx: &mut LoweringContext<'_, 'hir>,
|
||||||
|
@ -384,13 +382,13 @@ fn make_format_spec<'hir>(
|
||||||
let flags = ctx.expr_u32(sp, flags);
|
let flags = ctx.expr_u32(sp, flags);
|
||||||
let precision = make_count(ctx, sp, precision, argmap);
|
let precision = make_count(ctx, sp, precision, argmap);
|
||||||
let width = make_count(ctx, sp, width, argmap);
|
let width = make_count(ctx, sp, width, argmap);
|
||||||
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
|
let position = ctx.expr_field(Ident::new(sym::position, sp), ctx.arena.alloc(position), sp);
|
||||||
sp,
|
let flags = ctx.expr_field(Ident::new(sym::flags, sp), ctx.arena.alloc(flags), sp);
|
||||||
hir::LangItem::FormatPlaceholder,
|
let precision = ctx.expr_field(Ident::new(sym::precision, sp), ctx.arena.alloc(precision), sp);
|
||||||
sym::new,
|
let width = ctx.expr_field(Ident::new(sym::width, sp), ctx.arena.alloc(width), sp);
|
||||||
));
|
let placeholder = ctx.arena.alloc(hir::QPath::LangItem(hir::LangItem::FormatPlaceholder, sp));
|
||||||
let args = ctx.arena.alloc_from_iter([position, flags, precision, width]);
|
let fields = ctx.arena.alloc_from_iter([position, flags, precision, width]);
|
||||||
ctx.expr_call_mut(sp, format_placeholder_new, args)
|
ctx.expr(sp, hir::ExprKind::Struct(placeholder, fields, hir::StructTailExpr::None))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expand_format_args<'hir>(
|
fn expand_format_args<'hir>(
|
||||||
|
|
|
@ -986,6 +986,7 @@ symbols! {
|
||||||
field_init_shorthand,
|
field_init_shorthand,
|
||||||
file,
|
file,
|
||||||
file_options,
|
file_options,
|
||||||
|
flags,
|
||||||
float,
|
float,
|
||||||
float_to_int_unchecked,
|
float_to_int_unchecked,
|
||||||
floorf128,
|
floorf128,
|
||||||
|
@ -1570,6 +1571,7 @@ symbols! {
|
||||||
pointer_like,
|
pointer_like,
|
||||||
poll,
|
poll,
|
||||||
poll_next,
|
poll_next,
|
||||||
|
position,
|
||||||
post_dash_lto: "post-lto",
|
post_dash_lto: "post-lto",
|
||||||
postfix_match,
|
postfix_match,
|
||||||
powerpc_target_feature,
|
powerpc_target_feature,
|
||||||
|
@ -1585,6 +1587,7 @@ symbols! {
|
||||||
precise_capturing,
|
precise_capturing,
|
||||||
precise_capturing_in_traits,
|
precise_capturing_in_traits,
|
||||||
precise_pointer_size_matching,
|
precise_pointer_size_matching,
|
||||||
|
precision,
|
||||||
pref_align_of,
|
pref_align_of,
|
||||||
prefetch_read_data,
|
prefetch_read_data,
|
||||||
prefetch_read_instruction,
|
prefetch_read_instruction,
|
||||||
|
@ -2274,6 +2277,7 @@ symbols! {
|
||||||
wasm_target_feature,
|
wasm_target_feature,
|
||||||
where_clause_attrs,
|
where_clause_attrs,
|
||||||
while_let,
|
while_let,
|
||||||
|
width,
|
||||||
windows,
|
windows,
|
||||||
windows_subsystem,
|
windows_subsystem,
|
||||||
with_negative_coherence,
|
with_negative_coherence,
|
||||||
|
|
|
@ -20,8 +20,8 @@ pub struct Placeholder {
|
||||||
pub width: Count,
|
pub width: Count,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(bootstrap)]
|
||||||
impl Placeholder {
|
impl Placeholder {
|
||||||
#[cfg(bootstrap)]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn new(
|
pub const fn new(
|
||||||
position: usize,
|
position: usize,
|
||||||
|
@ -33,12 +33,6 @@ impl Placeholder {
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { position, fill, align, flags, precision, width }
|
Self { position, fill, align, flags, precision, width }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(bootstrap))]
|
|
||||||
#[inline]
|
|
||||||
pub const fn new(position: usize, flags: u32, precision: Count, width: Count) -> Self {
|
|
||||||
Self { position, flags, precision, width }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(bootstrap)]
|
#[cfg(bootstrap)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue