diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-31 13:08:12 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-31 13:08:12 +0100 |
commit | aca9004c7e4bafe1fc60d0e0298f5687b2e7615a (patch) | |
tree | b4af4bf8f1354200d6a3b19133bf3651c3e2964a /crates/proc_macro_srv | |
parent | b6e21a4ca45087b0a0bbe10948a4b9f11e5ee7fb (diff) | |
parent | 55a3364e35ef2adf7036483a4cba99bcb2450de3 (diff) |
Merge #8271
8271: Fix fail to parse u128 in proc-macro r=edwin0cheng a=edwin0cheng
fixes #8270
bors r+
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/proc_macro_srv')
-rw-r--r-- | crates/proc_macro_srv/src/rustc_server.rs | 19 |
1 files 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 c147484c0..5d765f6e2 100644 --- a/crates/proc_macro_srv/src/rustc_server.rs +++ b/crates/proc_macro_srv/src/rustc_server.rs | |||
@@ -534,8 +534,12 @@ impl server::Literal for Rustc { | |||
534 | } | 534 | } |
535 | 535 | ||
536 | fn integer(&mut self, n: &str) -> Self::Literal { | 536 | fn integer(&mut self, n: &str) -> Self::Literal { |
537 | let n: i128 = n.parse().unwrap(); | 537 | let n = if let Ok(n) = n.parse::<i128>() { |
538 | Literal { text: n.to_string().into(), id: tt::TokenId::unspecified() } | 538 | n.to_string() |
539 | } else { | ||
540 | n.parse::<u128>().unwrap().to_string() | ||
541 | }; | ||
542 | return Literal { text: n.into(), id: tt::TokenId::unspecified() }; | ||
539 | } | 543 | } |
540 | 544 | ||
541 | fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal { | 545 | fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal { |
@@ -757,6 +761,17 @@ mod tests { | |||
757 | assert_eq!(srv.string("hello_world").text, "\"hello_world\""); | 761 | assert_eq!(srv.string("hello_world").text, "\"hello_world\""); |
758 | assert_eq!(srv.character('c').text, "'c'"); | 762 | assert_eq!(srv.character('c').text, "'c'"); |
759 | assert_eq!(srv.byte_string(b"1234586\x88").text, "b\"1234586\\x88\""); | 763 | assert_eq!(srv.byte_string(b"1234586\x88").text, "b\"1234586\\x88\""); |
764 | |||
765 | // u128::max | ||
766 | assert_eq!( | ||
767 | srv.integer("340282366920938463463374607431768211455").text, | ||
768 | "340282366920938463463374607431768211455" | ||
769 | ); | ||
770 | // i128::min | ||
771 | assert_eq!( | ||
772 | srv.integer("-170141183460469231731687303715884105728").text, | ||
773 | "-170141183460469231731687303715884105728" | ||
774 | ); | ||
760 | } | 775 | } |
761 | 776 | ||
762 | #[test] | 777 | #[test] |