Skip to content

Commit aca9004

Browse files
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]>
2 parents b6e21a4 + 55a3364 commit aca9004

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

crates/proc_macro_srv/src/rustc_server.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,12 @@ impl server::Literal for Rustc {
534534
}
535535

536536
fn integer(&mut self, n: &str) -> Self::Literal {
537-
let n: i128 = n.parse().unwrap();
538-
Literal { text: n.to_string().into(), id: tt::TokenId::unspecified() }
537+
let n = if let Ok(n) = n.parse::<i128>() {
538+
n.to_string()
539+
} else {
540+
n.parse::<u128>().unwrap().to_string()
541+
};
542+
return Literal { text: n.into(), id: tt::TokenId::unspecified() };
539543
}
540544

541545
fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal {
@@ -757,6 +761,17 @@ mod tests {
757761
assert_eq!(srv.string("hello_world").text, "\"hello_world\"");
758762
assert_eq!(srv.character('c').text, "'c'");
759763
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+
);
760775
}
761776

762777
#[test]

0 commit comments

Comments
 (0)