Skip to content

Allow storing format_args!() in variable or const #139135

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

Closed
wants to merge 6 commits into from

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Mar 30, 2025

Fixes #92698

Tracking issue for super let: #139076

This change allows:

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

println!("{f}");

This will need an FCP.


This accidentally 'fixes' a bunch of tests/ui/codegen/equal-pointers-unequal/* tests. Those tests seem very fragile and should probably not depend on formatting implementation details.

This accidentally 'fixes' tests/ui/consts/const-eval/format.rs: it now allows any panic!() in a const fn. This might be expected. But we should then work on a better error when such a panic!() is const evaluated. (Now it reaches unreachable_unchecked().)

@m-ou-se m-ou-se added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Mar 30, 2025
@m-ou-se m-ou-se self-assigned this Mar 30, 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) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 30, 2025
@m-ou-se m-ou-se added needs-fcp This change is insta-stable, so needs a completed FCP to proceed. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. A-tidy Area: The tidy tool labels Mar 30, 2025
@rust-log-analyzer

This comment was marked as outdated.

@m-ou-se m-ou-se force-pushed the super-format-args branch from 3b4d57d to 627b48c Compare March 30, 2025 11:50
@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) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 30, 2025
@rust-log-analyzer

This comment was marked as outdated.

@m-ou-se m-ou-se force-pushed the super-format-args branch from 627b48c to 25d0db8 Compare March 30, 2025 12:14
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se force-pushed the super-format-args branch from 25d0db8 to 2a4d503 Compare March 30, 2025 12:43
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se force-pushed the super-format-args branch from 2a4d503 to 44b1861 Compare March 30, 2025 12:51
@m-ou-se
Copy link
Member Author

m-ou-se commented Mar 30, 2025

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)

FAILED TEST: tests/ui/manual_inspect.rs
command: CLIPPY_CONF_DIR="tests" RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/clippy-driver" [..]

One day, clippy will not break when I make any change to format_args!(). That day is not today.

@rust-log-analyzer

This comment has been minimized.

@m-ou-se

This comment was marked as resolved.

@RalfJung

This comment was marked as resolved.

@m-ou-se

This comment was marked as resolved.

@oli-obk

This comment was marked as resolved.

@RalfJung

This comment was marked as resolved.

@oli-obk

This comment was marked as resolved.

@m-ou-se
Copy link
Member Author

m-ou-se commented Apr 10, 2025

I've opened a separate issue for the panic discussion: #139621

@bors
Copy link
Collaborator

bors commented Apr 15, 2025

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

@m-ou-se m-ou-se force-pushed the super-format-args branch from 3db7f57 to a364c4b Compare April 22, 2025 14:25
@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Apr 22, 2025
@m-ou-se m-ou-se removed the A-tidy Area: The tidy tool label Apr 22, 2025
m-ou-se added 5 commits April 22, 2025 16:38
This makes it posisble to do:

    let f = format_args!("Hello, {name}!");
We can now just make new_v1_formatted an unsafe fn.
These tests rely on internal implementation details of format_args!(),
which have changed now.
@m-ou-se m-ou-se force-pushed the super-format-args branch from a364c4b to 3fbcdc0 Compare April 22, 2025 14:40
@rustbot rustbot added the A-tidy Area: The tidy tool label Apr 22, 2025
@rust-log-analyzer

This comment has been minimized.

@m-ou-se m-ou-se added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 22, 2025
@bors
Copy link
Collaborator

bors commented Apr 23, 2025

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

@m-ou-se
Copy link
Member Author

m-ou-se commented May 7, 2025

Closing this in favor of a slightly improved implementation without the const issues discussed above: #140748

@m-ou-se m-ou-se closed this May 7, 2025
@m-ou-se m-ou-se removed the A-tidy Area: The tidy tool label May 7, 2025
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow storing format_args! in a let binding
6 participants