-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
format!
currently doesn't support inline expressions, like format!("{binding.field}");
, but the error it emits while serviceable isn't great:
error: invalid format string: expected `'}'`, found `'.'`
--> src/main.rs:10:23
|
10 | println!("{binding.field}");
| - ^ expected `}` in format string
| |
| because of this opening brace
|
= note: if you intended to print `{`, you can escape it using `{{`
It would be much better experience if we started parsing first field access expressions, potentially method calls and later arbitrary expressions and explicitly told the user "you can't do that, move the expression to its own binding". If we were to ever attempt to support this, prototyping the machinery for diagnostics first would also be informative about its limits or potential problems.
error: invalid format string: field access isn't supported
--> src/main.rs:10:23
|
10 | println!("{binding.field}");
| ^^^^^^^^^^^^^ not supported
help: consider using a positional formatting argument instead
|
10 | println!("{}", binding.field);
| -- +++++++++++++
ilmannafian04, chilabot, vultix and tangowithfoxtrot
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTD-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.