Skip to content

Commit 5d3d055

Browse files
committed
Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
Move format_args!() into AST (and expand it during AST lowering) Implements rust-lang/compiler-team#541 This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier. This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`. This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
2 parents 60bfe32 + 0b9a8ba commit 5d3d055

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

core/src/fmt/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ extern "C" {
267267
/// family of functions. It contains a function to format the given value. At
268268
/// compile time it is ensured that the function and the value have the correct
269269
/// types, and then this struct is used to canonicalize arguments to one type.
270+
#[cfg_attr(not(bootstrap), lang = "format_argument")]
270271
#[derive(Copy, Clone)]
271272
#[allow(missing_debug_implementations)]
272273
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
@@ -279,6 +280,7 @@ pub struct ArgumentV1<'a> {
279280
/// This struct represents the unsafety of constructing an `Arguments`.
280281
/// It exists, rather than an unsafe function, in order to simplify the expansion
281282
/// of `format_args!(..)` and reduce the scope of the `unsafe` block.
283+
#[cfg_attr(not(bootstrap), lang = "format_unsafe_arg")]
282284
#[allow(missing_debug_implementations)]
283285
#[doc(hidden)]
284286
#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "none")]
@@ -473,8 +475,8 @@ impl<'a> Arguments<'a> {
473475
/// ```
474476
///
475477
/// [`format()`]: ../../std/fmt/fn.format.html
478+
#[cfg_attr(not(bootstrap), lang = "format_arguments")]
476479
#[stable(feature = "rust1", since = "1.0.0")]
477-
#[cfg_attr(not(test), rustc_diagnostic_item = "Arguments")]
478480
#[derive(Copy, Clone)]
479481
pub struct Arguments<'a> {
480482
// Format string pieces to print.

core/src/fmt/rt/v1.rs

Lines changed: 18 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,
@@ -20,7 +22,22 @@ pub struct FormatSpec {
2022
pub width: Count,
2123
}
2224

25+
impl Argument {
26+
#[inline(always)]
27+
pub const fn new(
28+
position: usize,
29+
fill: char,
30+
align: Alignment,
31+
flags: u32,
32+
precision: Count,
33+
width: Count,
34+
) -> Self {
35+
Self { position, format: FormatSpec { fill, align, flags, precision, width } }
36+
}
37+
}
38+
2339
/// Possible alignments that can be requested as part of a formatting directive.
40+
#[cfg_attr(not(bootstrap), lang = "format_alignment")]
2441
#[derive(Copy, Clone, PartialEq, Eq)]
2542
pub enum Alignment {
2643
/// Indication that contents should be left-aligned.
@@ -34,6 +51,7 @@ pub enum Alignment {
3451
}
3552

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

0 commit comments

Comments
 (0)