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

Merged
merged 11 commits into from
Jun 19, 2025
Merged

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
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label 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.

m-ou-se added 9 commits June 18, 2025 10:20
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 ae3bfda to 2c175e1 Compare June 18, 2025 08:32
@jdonszelmann
Copy link
Contributor

bors-r-plus

@bors
Copy link
Collaborator

bors commented Jun 19, 2025

📌 Commit b4f2cac has been approved by jdonszelmann

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2025
@bors
Copy link
Collaborator

bors commented Jun 19, 2025

⌛ Testing commit b4f2cac with merge 255aa22...

@bors
Copy link
Collaborator

bors commented Jun 19, 2025

☀️ Test successful - checks-actions
Approved by: jdonszelmann
Pushing 255aa22 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 19, 2025
@bors bors merged commit 255aa22 into rust-lang:master Jun 19, 2025
11 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 19, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 8de4c72 (parent) -> 255aa22 (this PR)

Test differences

Show 8 test diffs

Stage 1

  • [ui] tests/ui/borrowck/issue-114374-invalid-help-fmt-args.rs: pass -> [missing] (J1)
  • fmt::test_lifetime: [missing] -> pass (J2)

Stage 2

  • [ui] tests/ui/borrowck/issue-114374-invalid-help-fmt-args.rs: pass -> [missing] (J0)

Additionally, 5 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 255aa220821c05c3eac7605fce4ea1c9ab2cbdb4 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-aarch64-msvc: 14983.1s -> 8413.0s (-43.9%)
  2. dist-aarch64-apple: 6723.7s -> 4689.2s (-30.3%)
  3. x86_64-apple-2: 4537.4s -> 3543.9s (-21.9%)
  4. dist-x86_64-apple: 11510.2s -> 9048.3s (-21.4%)
  5. x86_64-apple-1: 7805.5s -> 6181.5s (-20.8%)
  6. dist-apple-various: 8283.5s -> 6874.9s (-17.0%)
  7. x86_64-gnu-llvm-19-2: 5280.0s -> 5852.9s (10.9%)
  8. x86_64-gnu-aux: 5956.6s -> 6537.8s (9.8%)
  9. mingw-check-tidy: 70.4s -> 77.1s (9.6%)
  10. dist-various-2: 3377.5s -> 3110.7s (-7.9%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (255aa22): comparison URL.

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

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.4% [0.2%, 1.0%] 24
Regressions ❌
(secondary)
1.6% [0.3%, 4.7%] 12
Improvements ✅
(primary)
-3.7% [-7.1%, -0.3%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-7.1%, 1.0%] 26

Max RSS (memory usage)

Results (primary 1.0%, secondary 2.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.0% [2.1%, 4.3%] 4
Regressions ❌
(secondary)
3.8% [2.6%, 6.5%] 4
Improvements ✅
(primary)
-3.2% [-3.2%, -3.1%] 2
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) 1.0% [-3.2%, 4.3%] 6

Cycles

Results (primary -6.8%, secondary 5.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.1% [4.0%, 7.2%] 4
Improvements ✅
(primary)
-6.8% [-6.8%, -6.8%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -6.8% [-6.8%, -6.8%] 1

Binary size

Results (primary 0.1%, secondary 1.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.2% [0.0%, 0.7%] 60
Regressions ❌
(secondary)
1.9% [0.0%, 17.0%] 35
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 5
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.2%, 0.7%] 65

Bootstrap: 691.904s -> 692.261s (0.05%)
Artifact size: 372.02 MiB -> 371.96 MiB (-0.02%)

@Kobzol
Copy link
Contributor

Kobzol commented Jun 20, 2025

Weird, somehow this makes binary size and linking time of workspaces with a lot of crates much worse.

@m-ou-se m-ou-se deleted the super-format-args3 branch June 20, 2025 06:04
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. merged-by-bors This PR was explicitly merged by bors. 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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