Skip to content
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

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

m-ou-se
Copy link
Member

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

Fixes #92698

Fixes #139136

This includes and is blocked on #139080, #139112, and #139131. Marking this as draft.

This change allows:

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

and

const F: std::fmt::Arguments<'static> = format_args!("hello {NAME}!");

This will need an FCP.


This accidentally 'fixes' the tests/ui/codegen/equal-pointers-unequal/*/print3.rs tests. Those tests seem very fragile and should probably not depend on formatting implementation details at all.

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 added 4 commits March 31, 2025 15:20
This makes it posisble to do:

    let f = format_args!("Hello, {name}!");
We can now just make new_v1_formatted an unsafe fn.
@rust-log-analyzer

This comment has been minimized.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 31, 2025
Remove fragile equal-pointers-unequal/*/print3.rs tests.

These tests were added in rust-lang#127003

The print3.rs tests stop working when I change implementation details of format_args!(). (For example, in rust-lang#139175 and rust-lang#139135). These tests shouldn't rely on such implementation details. It gets in the way for format_args!() improvements.

If they test anything that aren't already covered by the other tests in this directory, they should be expressed in a less fragile way that doesn't rely on internal details of format_args!().

cc `@GrigorenkoPV,` author of these tests.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 31, 2025
Remove fragile equal-pointers-unequal/*/print3.rs tests.

These tests were added in rust-lang#127003

The print3.rs tests stop working when I change implementation details of format_args!(). (For example, in rust-lang#139175 and rust-lang#139135). These tests shouldn't rely on such implementation details. It gets in the way for format_args!() improvements.

If they test anything that aren't already covered by the other tests in this directory, they should be expressed in a less fragile way that doesn't rely on internal details of format_args!().

cc ``@GrigorenkoPV,`` author of these tests.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 1, 2025
Rollup merge of rust-lang#139176 - m-ou-se:print3, r=compiler-errors

Remove fragile equal-pointers-unequal/*/print3.rs tests.

These tests were added in rust-lang#127003

The print3.rs tests stop working when I change implementation details of format_args!(). (For example, in rust-lang#139175 and rust-lang#139135). These tests shouldn't rely on such implementation details. It gets in the way for format_args!() improvements.

If they test anything that aren't already covered by the other tests in this directory, they should be expressed in a less fragile way that doesn't rely on internal details of format_args!().

cc ``@GrigorenkoPV,`` author of these tests.
@bors
Copy link
Collaborator

bors commented Apr 1, 2025

☔ The latest upstream changes (presumably #138740) 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-tidy Area: The tidy tool needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-blocked Status: Blocked on something else such as an RFC or other implementation work. 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.
Projects
None yet
4 participants