about summary refs log tree commit diff
path: root/library/proc_macro/src
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2021-10-25 20:25:30 -0700
committerDavid Tolnay <dtolnay@gmail.com>2021-10-25 20:30:47 -0700
commitc5025f0e4e46569bdd31743434a9d2dd602e95f2 (patch)
treecab3f6e40bb3bf8f76897e901e1336e5b1bd77d4 /library/proc_macro/src
parentffba4309241a7a21df4ec7b16f1357cbcd327d6e (diff)
downloadrust-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.rs12
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.