From 55a3364e35ef2adf7036483a4cba99bcb2450de3 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 31 Mar 2021 19:50:36 +0800 Subject: [PATCH] Fix parse u128 bug in proc-macro --- crates/proc_macro_srv/src/rustc_server.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/proc_macro_srv/src/rustc_server.rs b/crates/proc_macro_srv/src/rustc_server.rs index c147484c0e0..5d765f6e272 100644 --- a/crates/proc_macro_srv/src/rustc_server.rs +++ b/crates/proc_macro_srv/src/rustc_server.rs @@ -534,8 +534,12 @@ fn suffix(&mut self, _literal: &Self::Literal) -> Option { } 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::() { + n.to_string() + } else { + n.parse::().unwrap().to_string() + }; + return 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]