]> git.lizzy.rs Git - rust.git/blobdiff - crates/proc_macro_srv/src/rustc_server.rs
check rustc major version == 1 not < 1
[rust.git] / crates / proc_macro_srv / src / rustc_server.rs
index c147484c0e0f65518b54e427fdc03203a2c1482a..e252e89a5697c26a70c6ccca8a3fdab45847e186 100644 (file)
@@ -1,6 +1,6 @@
 //! Rustc proc-macro server implementation with tt
 //!
-//! Based on idea from https://github.com/fedochet/rust-proc-macro-expander
+//! Based on idea from <https://github.com/fedochet/rust-proc-macro-expander>
 //! The lib-proc-macro server backend is `TokenStream`-agnostic, such that
 //! we could provide any TokenStream implementation.
 //! The original idea from fedochet is using proc-macro2 as backend,
@@ -248,7 +248,7 @@ fn subtree_replace_token_ids_with_unspecified(subtree: tt::Subtree) -> tt::Subtr
             token_trees: subtree
                 .token_trees
                 .into_iter()
-                .map(|t| token_tree_replace_token_ids_with_unspecified(t))
+                .map(token_tree_replace_token_ids_with_unspecified)
                 .collect(),
         }
     }
@@ -457,7 +457,7 @@ fn stream(&mut self, group: &Self::Group) -> Self::TokenStream {
     }
 
     fn span(&mut self, group: &Self::Group) -> Self::Span {
-        group.delimiter.map(|it| it.id).unwrap_or_else(|| tt::TokenId::unspecified())
+        group.delimiter.map(|it| it.id).unwrap_or_else(tt::TokenId::unspecified)
     }
 
     fn set_span(&mut self, _group: &mut Self::Group, _span: Self::Span) {
@@ -534,8 +534,12 @@ fn suffix(&mut self, _literal: &Self::Literal) -> Option<String> {
     }
 
     fn integer(&mut self, n: &str) -> Self::Literal {
-        let n: i128 = n.parse().unwrap();
-        Literal { text: n.to_string().into(), id: tt::TokenId::unspecified() }
+        let n = if let Ok(n) = n.parse::<i128>() {
+            n.to_string()
+        } else {
+            n.parse::<u128>().unwrap().to_string()
+        };
+        Literal { text: n.into(), id: tt::TokenId::unspecified() }
     }
 
     fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal {
@@ -757,6 +761,17 @@ fn test_rustc_server_literals() {
         assert_eq!(srv.string("hello_world").text, "\"hello_world\"");
         assert_eq!(srv.character('c').text, "'c'");
         assert_eq!(srv.byte_string(b"1234586\x88").text, "b\"1234586\\x88\"");
+
+        // u128::max
+        assert_eq!(
+            srv.integer("340282366920938463463374607431768211455").text,
+            "340282366920938463463374607431768211455"
+        );
+        // i128::min
+        assert_eq!(
+            srv.integer("-170141183460469231731687303715884105728").text,
+            "-170141183460469231731687303715884105728"
+        );
     }
 
     #[test]