Handle advanced formatter specs in template parser#67
Conversation
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| loop { | ||
| let mut chars = rest.chars(); | ||
| let Some(ch) = chars.next() else { | ||
| return Some(false); | ||
| }; | ||
|
|
||
| match ch { | ||
| '+' | '-' | ' ' => { | ||
| rest = &rest[ch.len_utf8()..]; | ||
| } | ||
| '#' => { | ||
| rest = &rest[ch.len_utf8()..]; | ||
| if rest.chars().any(|value| value == '#') { | ||
| return None; | ||
| } | ||
| return Some(true); | ||
| } | ||
| _ => return Some(false) | ||
| } |
There was a problem hiding this comment.
[P1] Reject # flag that appears after width or zero padding
The new alternate-flag detector returns Some(false) as soon as it encounters any character other than +, - or space and never inspects the remainder of the prefix. As a result, format strings such as {value:0#x} or {value:>8#x}—which the Rust formatter rejects because the # flag must precede 0/width—are now parsed as valid hex formatters with alternate: false. Earlier versions correctly produced TemplateError::InvalidFormatter. This regression means invalid templates are accepted by the macro while the subsequent format! invocation will still fail to compile. The function should scan the whole prefix and return None if a # appears after width or padding characters.
Useful? React with 👍 / 👎.
Summary
#markersTesting
cargo +nightly fmt --cargo +1.90.0 clippy -- -D warningscargo +1.90.0 test --allcargo +1.90.0 doc --no-depscargo deny checkcargo audithttps://chatgpt.com/codex/tasks/task_e_68cd02940704832ba97e2169e4f49a66