Skip to content

Allow storing format_args!() in variable #140748

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented May 7, 2025

Fixes #92698

Tracking issue for super let: #139076

Tracking issue for format_args: #99012

This change allows:

let name = "world";
let f = format_args!("hello {name}!"); // New: Store format_args!() for later!

println!("{f}");

This will need an FCP.

This implementation makes use of super let, which is unstable and might not exist in the future in its current form. However, it is entirely reasonable to assume future Rust will always have a way of expressing temporary lifetimes like this, since the (stable) pin!() macro needs this too. (This was also the motivation for merging #139114.)

(This is a second version of #139135)

@m-ou-se m-ou-se added T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. A-fmt Area: `core::fmt` labels May 7, 2025
@rustbot rustbot added A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 7, 2025
@m-ou-se m-ou-se removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) A-tidy Area: The tidy tool labels May 7, 2025
@m-ou-se m-ou-se force-pushed the super-format-args3 branch from 4971602 to d261de6 Compare May 7, 2025 16:08
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 7, 2025
@m-ou-se m-ou-se removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) A-tidy Area: The tidy tool labels May 7, 2025
@m-ou-se
Copy link
Member Author

m-ou-se commented May 7, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 7, 2025
@bors
Copy link
Collaborator

bors commented May 7, 2025

⌛ Trying commit d261de6 with merge beb8d4e...

bors added a commit to rust-lang-ci/rust that referenced this pull request May 7, 2025
 Allow storing format_args!() in variable

Fixes rust-lang#92698

Tracking issue for super let: rust-lang#139076

This change allows:

```rust
let name = "world";
let f = format_args!("hello {name}!");

println!("{f}");
```

This will need an FCP.

This implementation makes use of `super let`, which is unstable and might not exist in the future in its current form. However, it is entirely reasonable to assume future Rust will always have _a_ way of expressing temporary lifetimes like this, since the (stable) `pin!()` macro needs this. (This was also the motivation for merging rust-lang#139114.)

> [!NOTE]
> This PR causes many subtle changes in diagnostics output. Most of those are good. Some of those are bad. I've collected all the bad ones in the last commit. Those still need fixing. Marking this PR as draft.

(This is a second version of rust-lang#139135)
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 7, 2025

☀️ Try build successful - checks-actions
Build commit: beb8d4e (beb8d4ea463c3ae10548aabc62ac2cff505be075)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (beb8d4e): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.4% [0.2%, 1.1%] 24
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-4.5%, -0.2%] 2
Improvements ✅
(secondary)
-1.8% [-1.9%, -1.7%] 6
All ❌✅ (primary) 0.2% [-4.5%, 1.1%] 26

Max RSS (memory usage)

Results (primary 0.4%, secondary -0.2%)

This 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.

mean range count
Regressions ❌
(primary)
1.7% [0.4%, 12.3%] 27
Regressions ❌
(secondary)
3.8% [3.8%, 3.8%] 1
Improvements ✅
(primary)
-2.2% [-6.1%, -0.5%] 13
Improvements ✅
(secondary)
-2.3% [-3.2%, -1.3%] 2
All ❌✅ (primary) 0.4% [-6.1%, 12.3%] 40

Cycles

Results (primary 0.1%, secondary 2.4%)

This 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.

mean range count
Regressions ❌
(primary)
0.7% [0.4%, 2.0%] 14
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-2.6% [-5.4%, -0.5%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-5.4%, 2.0%] 17

Binary size

Results (primary 0.1%, secondary 0.1%)

This 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.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.8%] 87
Regressions ❌
(secondary)
0.1% [0.0%, 0.2%] 15
Improvements ✅
(primary)
-0.1% [-0.4%, -0.0%] 6
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.4%, 0.8%] 93

Bootstrap: 770.356s -> 770.437s (0.01%)
Artifact size: 365.20 MiB -> 365.11 MiB (-0.02%)

@rustbot rustbot added the perf-regression Performance regression. label May 7, 2025
@m-ou-se m-ou-se force-pushed the super-format-args3 branch from 7742371 to a1bd412 Compare June 5, 2025 08:24
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 5, 2025
@m-ou-se m-ou-se removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) A-tidy Area: The tidy tool labels Jun 5, 2025
@joshtriplett joshtriplett added the relnotes Marks issues that should be documented in the release notes of the next release. label Jun 9, 2025
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jun 14, 2025
@rfcbot
Copy link
Collaborator

rfcbot commented Jun 14, 2025

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@bors
Copy link
Collaborator

bors commented Jun 16, 2025

☔ The latest upstream changes (presumably #142550) made this pull request unmergeable. Please resolve the merge conflicts.

m-ou-se added 7 commits June 16, 2025 11:13
This uses `super let` to allow

    let f = format_args!("Hello {}", world);
    println!("{f}");

to work.
We no longer error in this case!
This message is no longer generated.

This is probably a good thing. The relevant span is entirely in user
code, and "format_args_nl" is an implementation detail with a name that
isn't even public.
Diagnostics should know that the `&` for arguments in format_args!()
come from the macro expansion rather than from the original source.
@m-ou-se m-ou-se force-pushed the super-format-args3 branch from a1bd412 to ae3bfda Compare June 16, 2025 11:04
@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 16, 2025
Copy link
Member

@fmease fmease Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the discussion in https://github.com/rust-lang/rust/pull/142543/files/6ff3713e0fc60146a36774b447204677ab7b8d5a#r2149545623, instead of fully removing this test, could you replace it with the one I suggested in #142543 (comment) or modify tests/ui/nll/issue-54556-used-vs-unused-tails.rs to add it there.

That would be very appreciated but not 'required' since it's more important to get your PR merged in the first place :) Urgau or I can simply re-add a test as a follow-up, no problem.

@bors
Copy link
Collaborator

bors commented Jun 17, 2025

☔ The latest upstream changes (presumably #142613) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fmt Area: `core::fmt` A-tidy Area: The tidy tool disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. perf-regression Performance regression. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow storing format_args! in a let binding