Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a template for new experimental fmt::Arguments implementations. If you want to try out a new fmt::Arguments implementation, this branch is a useful place to start from.
To implement a new fmt::Arguments, you need to:
Implement the part of rustc that expands
format_args!(), incompiler/rustc_builtin_macros/src/format/expand.rs.expand_parsed_format_argsfunction takes aFormatArgsstruct representing the already parsed/processedformat_args!(), and you need to return the expanded ast expression that will create a newfmt::Argumentsat runtime.Implement the new
fmt::Argumentsstruct inlibrary/core/src/fmt/mod.rs.format_args!()macro implementation. Instead, you 'remove' old code by adding#[cfg(boostrap)]and add new code with#[cfg(not(bootstrap))]. (Old code is removed when the bootstrap/beta compiler is bumped to the next version.)TODOcomments, which point out theArgumentsstruct and the methods you need to implement. I've already put all the old code under#[cfg(bootstrap)]and created new empty placeholders for the new code.struct Arguments<'a>: the structure that represents a completeformat_args!()at runtime.Arguments::new: the function used in the expansion offormat_args!()to create this struct. Which arguments this takes is up to you, as it only needs to match your macro expansion.Arguments::from_static_str: this should create anArgumentsstruct that represents exactly the given string.Arguments::as_str: this should return the string in trivial cases likeformat_args!("hello")orArguments::from_static_str("hello"), or None otherwise.Arguments::estimated_capacity: this should return the estimated size of the complete output when displayed. It doesn't have to be very accurate. See the old implementation for an example.write: This function takes yourfmt::Argumentsand should write/display it to a&mut dyn Write.If you have something ready for sharing or testing, feel free to open a draft PR and drop a comment in #99012.