Skip to content

Commit

Permalink
Merge pull request #89 from dtolnay/floatdot
Browse files Browse the repository at this point in the history
Avoid trailing '.' on non-macro float literals
  • Loading branch information
dtolnay authored Jan 5, 2025
2 parents 5478bcf + 988425d commit 0ddbeab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ impl Printer {
}

fn lit_float(&mut self, lit: &LitFloat) {
self.word(lit.token().to_string());
let repr = lit.token().to_string();
let dot = repr.ends_with('.');
self.word(repr);
if dot {
self.word("0");
}
}

fn lit_bool(&mut self, lit: &LitBool) {
Expand Down
1 change: 1 addition & 0 deletions src/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl Printer {
(_, Token::Ident(ident)) if !is_keyword(ident) => {
(state != Dot && state != Colon2, Ident)
}
(_, Token::Literal(lit)) if lit.to_string().ends_with('.') => (state != Dot, Other),
(_, Token::Literal(_)) => (state != Dot, Ident),
(_, Token::Punct(',' | ';', _)) => (false, Other),
(_, Token::Punct('.', _)) if !matcher => (state != Ident && state != Delim, Dot),
Expand Down

0 comments on commit 0ddbeab

Please sign in to comment.