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

Unclear error message when using . in format string #122535

Closed
Alon0709 opened this issue Mar 15, 2024 · 3 comments · Fixed by #122556
Closed

Unclear error message when using . in format string #122535

Alon0709 opened this issue Mar 15, 2024 · 3 comments · Fixed by #122556
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Alon0709
Copy link

I tried this code:

    let x = (1, 2, 3);
    println!("{x.0}",);

I expected to see this happen: printing of the value 1.

Instead, this happened: it gave the following error:

invalid format string: expected '}', found '.'
if you intended to print {, you can escape it using {{rustcClick for full compiler diagnostic

Meta

rustc --version --verbose:

1.76.0
@Alon0709 Alon0709 added the C-bug Category: This is a bug. label Mar 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 15, 2024
@Noratrieb
Copy link
Member

Only printing an identifer is supported, arbitrary expressions are not: https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html

@Noratrieb
Copy link
Member

There's more discussion about this in https://internals.rust-lang.org/t/how-to-allow-arbitrary-expressions-in-format-strings/15812 or in many other places, it's a thing that keeps coming up.

@Noratrieb
Copy link
Member

The error message could be nicer, so I'll convert it into a diagnostics issue.

@Noratrieb Noratrieb added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 15, 2024
@Noratrieb Noratrieb changed the title Printing a Specific Value In a Tuple Breaks The Format String Unclear error message when using . in format string Mar 15, 2024
@jieyouxu jieyouxu added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Mar 15, 2024
@bors bors closed this as completed in 45e005d Mar 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 19, 2024
Rollup merge of rust-lang#122556 - jieyouxu:non-identifier-format-arg, r=petrochenkov

Extend format arg help for simple tuple index access expression

The help is only applicable for simple field access `a.b` and (with this PR) simple tuple index access expressions `a.0`.

Closes rust-lang#122535.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants