warn on empty precision by hkBst · Pull Request #136638 · rust-lang/rust (original) (raw)
@samueltardieu: could you explain whether it is feasible to lint format macro syntax (like in this PR) within clippy?
We can do this as we have access to the parsed format specifier as well as the original source code. However, unless I'm mistaken, this might require an error-prone reparsing because:
- The precision in
FormatOptionswould beNonein the presence of a sole., so we don't have a span for the precision that we can check for emptyness. - We have access to the whole placeholder span, but there are a lot of combinations to check for:
{:.x}should lint,{:.x$}should not,{:.?}should lint,{:.<10}should not, etc.
This would be easier if the span of the precision was available outside the precision (so that we can get a None precision with an associated Some(_) span containing "."). Would this be worth it? Another option would be to add a FormatCount::Empty variant, but it would complicate the usage logic a bit (I haven't checked the details).