Skip to content

Commit bebf9fe

Browse files
committed
Turn format arguments types into lang items.
1 parent 3c45176 commit bebf9fe

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

compiler/rustc_hir/src/lang_items.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ language_item_table! {
244244
/// libstd panic entry point. Necessary for const eval to be able to catch it
245245
BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None;
246246

247+
// Lang items needed for `format_args!()`.
248+
FormatAlignment, sym::format_alignment, format_alignment, Target::Enum, GenericRequirement::None;
249+
FormatArgument, sym::format_argument, format_argument, Target::Struct, GenericRequirement::None;
250+
FormatArguments, sym::format_arguments, format_arguments, Target::Struct, GenericRequirement::None;
251+
FormatCount, sym::format_count, format_count, Target::Enum, GenericRequirement::None;
252+
FormatPlaceholder, sym::format_placeholder, format_placeholder, Target::Struct, GenericRequirement::None;
253+
FormatUnsafeArg, sym::format_unsafe_arg, format_unsafe_arg, Target::Struct, GenericRequirement::None;
254+
247255
ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None;
248256
BoxFree, sym::box_free, box_free_fn, Target::Fn, GenericRequirement::Minimum(1);
249257
DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1);

compiler/rustc_span/src/symbol.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,17 @@ symbols! {
721721
forbid,
722722
forget,
723723
format,
724+
format_alignment,
724725
format_args,
725726
format_args_capture,
726727
format_args_macro,
727728
format_args_nl,
729+
format_argument,
730+
format_arguments,
731+
format_count,
728732
format_macro,
733+
format_placeholder,
734+
format_unsafe_arg,
729735
freeze,
730736
freg,
731737
frem_fast,

library/core/src/fmt/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ extern "C" {
262262
/// family of functions. It contains a function to format the given value. At
263263
/// compile time it is ensured that the function and the value have the correct
264264
/// types, and then this struct is used to canonicalize arguments to one type.
265+
#[cfg_attr(not(bootstrap), lang = "format_argument")]
265266
#[derive(Copy, Clone)]
266267
#[allow(missing_debug_implementations)]
267268
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
@@ -274,6 +275,7 @@ pub struct ArgumentV1<'a> {
274275
/// This struct represents the unsafety of constructing an `Arguments`.
275276
/// It exists, rather than an unsafe function, in order to simplify the expansion
276277
/// of `format_args!(..)` and reduce the scope of the `unsafe` block.
278+
#[cfg_attr(not(bootstrap), lang = "format_unsafe_arg")]
277279
#[allow(missing_debug_implementations)]
278280
#[doc(hidden)]
279281
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
@@ -468,8 +470,8 @@ impl<'a> Arguments<'a> {
468470
/// ```
469471
///
470472
/// [`format()`]: ../../std/fmt/fn.format.html
473+
#[cfg_attr(not(bootstrap), lang = "format_arguments")]
471474
#[stable(feature = "rust1", since = "1.0.0")]
472-
#[cfg_attr(not(test), rustc_diagnostic_item = "Arguments")]
473475
#[derive(Copy, Clone)]
474476
pub struct Arguments<'a> {
475477
// Format string pieces to print.

library/core/src/fmt/rt/v1.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
//! these can be statically allocated and are slightly optimized for the runtime
66
#![allow(missing_debug_implementations)]
77

8+
#[cfg_attr(not(bootstrap), lang = "format_placeholder")]
89
#[derive(Copy, Clone)]
10+
// FIXME: Rename this to Placeholder
911
pub struct Argument {
1012
pub position: usize,
1113
pub format: FormatSpec,
@@ -21,6 +23,7 @@ pub struct FormatSpec {
2123
}
2224

2325
/// Possible alignments that can be requested as part of a formatting directive.
26+
#[cfg_attr(not(bootstrap), lang = "format_alignment")]
2427
#[derive(Copy, Clone, PartialEq, Eq)]
2528
pub enum Alignment {
2629
/// Indication that contents should be left-aligned.
@@ -34,6 +37,7 @@ pub enum Alignment {
3437
}
3538

3639
/// Used by [width](https://doc.rust-lang.org/std/fmt/#width) and [precision](https://doc.rust-lang.org/std/fmt/#precision) specifiers.
40+
#[cfg_attr(not(bootstrap), lang = "format_count")]
3741
#[derive(Copy, Clone)]
3842
pub enum Count {
3943
/// Specified with a literal number, stores the value

0 commit comments

Comments
 (0)