Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions compiler/rustc_ast_lowering/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,12 @@ fn make_count<'hir>(
/// Generates
///
/// ```text
/// <core::fmt::rt::Placeholder::new(
/// …usize, // position
/// '…', // fill
/// <core::fmt::rt::Alignment>::…, // alignment
/// …u32, // flags
/// <core::fmt::rt::Count::…>, // width
/// <core::fmt::rt::Count::…>, // precision
/// )
/// <core::fmt::rt::Placeholder {
/// position: …usize,
/// flags: …u32,
/// precision: <core::fmt::rt::Count::…>,
/// width: <core::fmt::rt::Count::…>,
/// }
/// ```
fn make_format_spec<'hir>(
ctx: &mut LoweringContext<'_, 'hir>,
Expand Down Expand Up @@ -384,13 +382,13 @@ fn make_format_spec<'hir>(
let flags = ctx.expr_u32(sp, flags);
let precision = make_count(ctx, sp, precision, argmap);
let width = make_count(ctx, sp, width, argmap);
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
sp,
hir::LangItem::FormatPlaceholder,
sym::new,
));
let args = ctx.arena.alloc_from_iter([position, flags, precision, width]);
ctx.expr_call_mut(sp, format_placeholder_new, args)
let position = ctx.expr_field(Ident::new(sym::position, sp), ctx.arena.alloc(position), sp);
let flags = ctx.expr_field(Ident::new(sym::flags, sp), ctx.arena.alloc(flags), sp);
let precision = ctx.expr_field(Ident::new(sym::precision, sp), ctx.arena.alloc(precision), sp);
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 fields = ctx.arena.alloc_from_iter([position, flags, precision, width]);
ctx.expr(sp, hir::ExprKind::Struct(placeholder, fields, hir::StructTailExpr::None))
}

fn expand_format_args<'hir>(
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ symbols! {
field_init_shorthand,
file,
file_options,
flags,
float,
float_to_int_unchecked,
floorf128,
Expand Down Expand Up @@ -1570,6 +1571,7 @@ symbols! {
pointer_like,
poll,
poll_next,
position,
post_dash_lto: "post-lto",
postfix_match,
powerpc_target_feature,
Expand All @@ -1585,6 +1587,7 @@ symbols! {
precise_capturing,
precise_capturing_in_traits,
precise_pointer_size_matching,
precision,
pref_align_of,
prefetch_read_data,
prefetch_read_instruction,
Expand Down Expand Up @@ -2274,6 +2277,7 @@ symbols! {
wasm_target_feature,
where_clause_attrs,
while_let,
width,
windows,
windows_subsystem,
with_negative_coherence,
Expand Down
8 changes: 1 addition & 7 deletions library/core/src/fmt/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct Placeholder {
pub width: Count,
}

#[cfg(bootstrap)]
impl Placeholder {
#[cfg(bootstrap)]
#[inline]
pub const fn new(
position: usize,
Expand All @@ -33,12 +33,6 @@ impl Placeholder {
) -> Self {
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)]
Expand Down
Loading