-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable flatten-format-args by default. #109999
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
c551788
to
a77d39b
Compare
I am a bit worried about these two cases because these are not achievable by proc macros, and thus would make
|
This comment was marked as resolved.
This comment was marked as resolved.
Note that I'm not saying that necessarily means that
A proc macro
It's usually okay for a standard library macro to use something that's not yet stable. The Footnotes
|
This is a quite convincing argument, and address my main worry that this would turn |
This comment has been minimized.
This comment has been minimized.
87d942c
to
63d8758
Compare
r? @oli-obk |
@bors r+ |
⌛ Testing commit 2cd5ce0 with merge 7bcb998f019b911e8852347cce2433683f85e3ee... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (d19b64f): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
Love this! |
Enable flatten-format-args by default. Part of rust-lang#99012. This enables the `flatten-format-args` feature that was added by rust-lang#106824: > This change inlines string literals, integer literals and nested format_args!() into format_args!() during ast lowering, making all of the following pairs result in equivalent hir: > > ```rust > println!("Hello, {}!", "World"); > println!("Hello, World!"); > ``` > > ```rust > println!("[info] {}", format_args!("error")); > println!("[info] error"); > ``` > > ```rust > println!("[{}] {}", status, format_args!("error: {}", msg)); > println!("[{}] error: {}", status, msg); > ``` > > ```rust > println!("{} + {} = {}", 1, 2, 1 + 2); > println!("1 + 2 = {}", 1 + 2); > ``` > > And so on. > > This is useful for macros. E.g. a `log::info!()` macro could just pass the tokens from the user directly into a `format_args!()` that gets efficiently flattened/inlined into a `format_args!("info: {}")`. > > It also means that `dbg!(x)` will have its file, line, and expression name inlined: > > ```rust > eprintln!("[{}:{}] {} = {:#?}", file!(), line!(), stringify!(x), x); // before > eprintln!("[example.rs:1] x = {:#?}", x); // after > ``` > > Which can be nice in some cases, but also means a lot more unique static strings than before if dbg!() is used a lot. This is mostly an optimization, except that it will be visible through [`fmt::Arguments::as_str()`](https://doc.rust-lang.org/nightly/std/fmt/struct.Arguments.html#method.as_str). In rust-lang#106823, there was already a libs-api FCP about the documentation of `fmt::Arguments::as_str()` to allow it to give `Some` rather than `None` depending on optimizations like this. That was just a documentation update though. This PR is the one that actually makes the user visible change: ```rust assert_eq!(format_args!("abc").as_str(), Some("abc")); // Unchanged. assert_eq!(format_args!("ab{}", "c").as_str(), Some("abc")); // Was `None` before! ```
Part of #99012.
This enables the
flatten-format-args
feature that was added by #106824:This is mostly an optimization, except that it will be visible through
fmt::Arguments::as_str()
.In #106823, there was already a libs-api FCP about the documentation of
fmt::Arguments::as_str()
to allow it to giveSome
rather thanNone
depending on optimizations like this. That was just a documentation update though. This PR is the one that actually makes the user visible change: