-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add support for captured identifiers #182
Conversation
This reverts commit 9cdb6d8.
I haven't looked at the code yet, but if it makes the implementation easier I wouldn't mind if it this new syntax is only supported on 1.58+, as long as the old syntax still works on the current MSRV. |
Both the new syntax and the old one work fine on MSRV with 1 limitation described in PR message.
This PR depends on a new parser implemented in #181 so we should wait until it's merged. |
# Conflicts: # Cargo.lock # Cargo.toml # src/display.rs # src/parsing.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilslv LGTM, thanks!
src/display.rs
Outdated
/// [Width argument][1], if present. | ||
/// | ||
/// [1]: https://doc.rust-lang.org/stable/std/fmt/index.html#width | ||
width: Option<Argument>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we better align here with the terminology used in the linked docs, not the one proposed by the formal grammar (we may keep it just for the parsing
).
So, Argument
- > Parameter
, Ident
-> Named
, Integer
-> Positional
.
Since Rust 1.58
format_args!
macro can capture identifiers:format!("Prefix: {some_local_variable}")
. This PR adds support for this feature while preserving MSRV by transformingformat!("Prefix: {field}")
intoformat!("Prefix: {field}", field = field)
.Limitations
This approach doesn't work well with unnamed fields that are aliased with
_0, _1, ...
because until 1.41 identifiers beginning with underscore weren't supported