Skip to content

Commit 6938566

Browse files
committed
Add support for 128-bit integers
Only compile in this support if rustc is new enough, otherwise continue to omit the bindings for older-than-1.26 rustc Closes dtolnay#143
1 parent 92bca96 commit 6938566

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

build.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ fn main() {
77

88
let target = env::var("TARGET").unwrap();
99

10-
if !enable_use_proc_macro(&target) {
11-
return;
12-
}
13-
println!("cargo:rustc-cfg=use_proc_macro");
14-
1510
let minor = match rustc_minor_version() {
1611
Some(n) => n,
1712
None => return,
1813
};
1914

15+
if minor >= 26 {
16+
println!("cargo:rustc-cfg=u128");
17+
}
18+
19+
if !enable_use_proc_macro(&target) {
20+
return;
21+
}
22+
println!("cargo:rustc-cfg=use_proc_macro");
23+
2024
// Rust 1.29 stabilized the necessary APIs in the `proc_macro` crate
2125
if minor >= 29 || cfg!(feature = "nightly") {
2226
println!("cargo:rustc-cfg=wrap_proc_macro");

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,12 @@ impl Literal {
973973
isize_suffixed => isize,
974974
}
975975

976+
#[cfg(u128)]
977+
suffixed_int_literals! {
978+
u128_suffixed => u128,
979+
i128_suffixed => i128,
980+
}
981+
976982
unsuffixed_int_literals! {
977983
u8_unsuffixed => u8,
978984
u16_unsuffixed => u16,
@@ -986,6 +992,12 @@ impl Literal {
986992
isize_unsuffixed => isize,
987993
}
988994

995+
#[cfg(u128)]
996+
unsuffixed_int_literals! {
997+
u128_unsuffixed => u128,
998+
i128_unsuffixed => i128,
999+
}
1000+
9891001
pub fn f64_unsuffixed(f: f64) -> Literal {
9901002
assert!(f.is_finite());
9911003
Literal::_new(imp::Literal::f64_unsuffixed(f))

src/stable.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,12 @@ impl Literal {
678678
f64_suffixed => f64,
679679
}
680680

681+
#[cfg(u128)]
682+
suffixed_numbers! {
683+
u128_suffixed => u128,
684+
i128_suffixed => i128,
685+
}
686+
681687
unsuffixed_numbers! {
682688
u8_unsuffixed => u8,
683689
u16_unsuffixed => u16,
@@ -691,6 +697,12 @@ impl Literal {
691697
isize_unsuffixed => isize,
692698
}
693699

700+
#[cfg(u128)]
701+
unsuffixed_numbers! {
702+
u128_unsuffixed => u128,
703+
i128_unsuffixed => i128,
704+
}
705+
694706
pub fn f32_unsuffixed(f: f32) -> Literal {
695707
let mut s = f.to_string();
696708
if !s.contains(".") {

src/unstable.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,12 @@ impl Literal {
819819
f64_suffixed => f64,
820820
}
821821

822+
#[cfg(u128)]
823+
suffixed_numbers! {
824+
i128_suffixed => i128,
825+
u128_suffixed => u128,
826+
}
827+
822828
unsuffixed_integers! {
823829
u8_unsuffixed => u8,
824830
u16_unsuffixed => u16,
@@ -832,6 +838,12 @@ impl Literal {
832838
isize_unsuffixed => isize,
833839
}
834840

841+
#[cfg(u128)]
842+
unsuffixed_integers! {
843+
i128_unsuffixed => i128,
844+
u128_unsuffixed => u128,
845+
}
846+
835847
pub fn f32_unsuffixed(f: f32) -> Literal {
836848
if nightly_works() {
837849
Literal::Nightly(proc_macro::Literal::f32_unsuffixed(f))

0 commit comments

Comments
 (0)