Repository navigation
f-strings everywhere: only f"..." interpolates, messages included - #116
Merged
Merged
Conversation
An error's message and an assert's message interpolated in a plain
"...", while a constant needed f"..." - two spellings for one idea,
and f"..." in a message was a parse error. Now a message is either:
"...", printed as written, or f"...", which interpolates, as a
constant's does.
The frozen template keeps {{ / }} escapes (a plain message's braces all
come out escaped), so a reader can always tell a literal brace from a
placeholder - reconstruct collapsed them before, the old ambiguity the
Rust generator worked around.
Migration help: a path written like a placeholder in a plain message,
"{value.name} is empty", is recorded and warned about at the message
(validation::message-not-interpolated). std's StringBounds is f-strings.
And a validator whose validate block is empty is warned about at that
block, naming the validator as a secondary location.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Interpolation had two spellings. A constant needed
f"page {N}", but anerror'smessageand an assert's message interpolated in a plain"…", andf"…"there was a parse error. Now the rule is the same everywhere: only an f-string interpolates.Grammar. A message (
message = …, and anassert's second argument) is"…", printed as written, orf"…", with{path}placeholders and{{/}}escapes as for a constant. Both carry their span.IR
{{/}}escapes, and every brace in a plain message comes out escaped. A reader can always tell a literal brace from a placeholder. Before,reconstructcollapsed escapes into bare braces, the ambiguity comline-rust's message renderer worked around. Templates without literal braces are unchanged.serde(default):Error.message_spanandError.uninterpolated;Assert.message_spanandAssert.uninterpolated;Validator.validate_span.Diagnostics
validation::message-not-interpolated, the migration aid. A path written like a placeholder in a plain message, e.g."{value.name} is empty", is printed as written. The warning sits on the message, and the help says to writef"…". A re-exported error is warned about only where it's declared.validator-checks-nothingwith an emptyvalidateblock now points at the block and names the validator as a secondary location. Without a block it says so, and its example is now an f-string.{{skipped, so an escaped{{params.x}}doesn't count as a use.Migration
StringBoundsnow uses f-strings.f"…"; expected IR templates are unchanged.errorandmessagevocabulary entries are reworded.Tests: escape round-trips for both kinds of string, plain braces parsing, the new warning and its spans, the validate-block span, and literal braces not counting as placeholders. The full suite passes.
Follow-ups:
{{/}}in templates;f, f-string highlighting, and a VS Code</>fix;