error on empty precision by hkBst · Pull Request #136638 · rust-lang/rust (original) (raw)
The other option, of course, is to document the current behavior. We do get this right for {:}
, because we document:
format := '{' [ argument ] [ ':' format_spec ] [ ws ] * '}' format_spec := [[fill]align][sign]['#']['0'][width]['.' precision]type type := '' | '?' | 'x?' | 'X?' | identifier
So since type
includes ''
, we must accept {:}
. But, for {:.}
, we'd look at:
format := '{' [ argument ] [ ':' format_spec ] [ ws ] * '}' argument := integer | identifier format_spec := [[fill]align][sign]['#']['0'][width]['.' precision]type precision := count | '*' count := parameter | integer parameter := argument '$'
Here, this bottoms out at requiring something after the dot.
We could say, instead, if we want, e.g.:
precision := count | '*' | ''
Since we do also accept today, e.g. {:.x}
, that seems right. Or alternatively, and maybe more directly, we could say:
format_spec := [[fill]align][sign]['#']['0'][width]['.' [precision]]type