diff options
| author | David Tolnay <dtolnay@gmail.com> | 2021-10-25 20:25:30 -0700 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2021-10-25 20:30:47 -0700 |
| commit | c5025f0e4e46569bdd31743434a9d2dd602e95f2 (patch) | |
| tree | cab3f6e40bb3bf8f76897e901e1336e5b1bd77d4 /library/proc_macro/src | |
| parent | ffba4309241a7a21df4ec7b16f1357cbcd327d6e (diff) | |
| download | rust-c5025f0e4e46569bdd31743434a9d2dd602e95f2.tar.gz rust-c5025f0e4e46569bdd31743434a9d2dd602e95f2.zip | |
Append .0 to unsuffixed float if it would otherwise become int token
Diffstat (limited to 'library/proc_macro/src')
| -rw-r--r-- | library/proc_macro/src/lib.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 3a06cd04ab1..9d673d69687 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -1074,7 +1074,11 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {}", n); } - Literal(bridge::client::Literal::float(&n.to_string())) + let mut repr = n.to_string(); + if !repr.contains('.') { + repr.push_str(".0"); + } + Literal(bridge::client::Literal::float(&repr)) } /// Creates a new suffixed floating-point literal. @@ -1115,7 +1119,11 @@ impl Literal { if !n.is_finite() { panic!("Invalid float literal {}", n); } - Literal(bridge::client::Literal::float(&n.to_string())) + let mut repr = n.to_string(); + if !repr.contains('.') { + repr.push_str(".0"); + } + Literal(bridge::client::Literal::float(&repr)) } /// Creates a new suffixed floating-point literal. |
