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
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.
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