Skip to content

Commit 0ddbeab

Browse files
authored
Merge pull request #89 from dtolnay/floatdot
Avoid trailing '.' on non-macro float literals
2 parents 5478bcf + 988425d commit 0ddbeab

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/lit.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ impl Printer {
4444
}
4545

4646
fn lit_float(&mut self, lit: &LitFloat) {
47-
self.word(lit.token().to_string());
47+
let repr = lit.token().to_string();
48+
let dot = repr.ends_with('.');
49+
self.word(repr);
50+
if dot {
51+
self.word("0");
52+
}
4853
}
4954

5055
fn lit_bool(&mut self, lit: &LitBool) {

src/mac.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ impl Printer {
179179
(_, Token::Ident(ident)) if !is_keyword(ident) => {
180180
(state != Dot && state != Colon2, Ident)
181181
}
182+
(_, Token::Literal(lit)) if lit.to_string().ends_with('.') => (state != Dot, Other),
182183
(_, Token::Literal(_)) => (state != Dot, Ident),
183184
(_, Token::Punct(',' | ';', _)) => (false, Other),
184185
(_, Token::Punct('.', _)) if !matcher => (state != Ident && state != Delim, Dot),

0 commit comments

Comments
 (0)