Skip to content

Commit fb96ecc

Browse files
authored
Rollup merge of #90848 - scottmcm:remove-signed-bigint-helpers, r=joshtriplett
Remove bigint_helper_methods for *signed* types This PR inspired by `@cuviper's` comment @ #90541 (comment) These are working well for *unsigned* types, so keep those, but for the the *signed* ones there are a bunch of questions about what the semantics and API should be. For the main "helpers for big integer implementations" use, there's no need for the signed versions anyway. There are plenty of other methods which exist for unsigned types but not signed ones, like `next_power_of_two`, so this isn't unusual. Fixes #90541 Tracking issue #85532
2 parents 12d5297 + 6323f92 commit fb96ecc

File tree

2 files changed

+1
-68
lines changed

2 files changed

+1
-68
lines changed

library/core/src/num/int_macros.rs

-54
Original file line numberDiff line numberDiff line change
@@ -1511,33 +1511,6 @@ macro_rules! int_impl {
15111511
(a as Self, b)
15121512
}
15131513

1514-
/// Calculates `self + rhs + carry` without the ability to overflow.
1515-
///
1516-
/// Performs "ternary addition" which takes in an extra bit to add, and may return an
1517-
/// additional bit of overflow. This allows for chaining together multiple additions
1518-
/// to create "big integers" which represent larger values.
1519-
///
1520-
/// # Examples
1521-
///
1522-
/// Basic usage
1523-
///
1524-
/// ```
1525-
/// #![feature(bigint_helper_methods)]
1526-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, false), (7, false));")]
1527-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, true), (8, false));")]
1528-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, false), (", stringify!($SelfT), "::MIN, false));")]
1529-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, true), (", stringify!($SelfT), "::MIN + 1, false));")]
1530-
/// ```
1531-
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
1532-
#[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")]
1533-
#[must_use = "this returns the result of the operation, \
1534-
without modifying the original"]
1535-
#[inline]
1536-
pub const fn carrying_add(self, rhs: Self, carry: bool) -> (Self, bool) {
1537-
let (sum, carry) = (self as $UnsignedT).carrying_add(rhs as $UnsignedT, carry);
1538-
(sum as $SelfT, carry)
1539-
}
1540-
15411514
/// Calculates `self` + `rhs` with an unsigned `rhs`
15421515
///
15431516
/// Returns a tuple of the addition along with a boolean indicating
@@ -1589,33 +1562,6 @@ macro_rules! int_impl {
15891562
(a as Self, b)
15901563
}
15911564

1592-
/// Calculates `self - rhs - borrow` without the ability to overflow.
1593-
///
1594-
/// Performs "ternary subtraction" which takes in an extra bit to subtract, and may return
1595-
/// an additional bit of overflow. This allows for chaining together multiple subtractions
1596-
/// to create "big integers" which represent larger values.
1597-
///
1598-
/// # Examples
1599-
///
1600-
/// Basic usage
1601-
///
1602-
/// ```
1603-
/// #![feature(bigint_helper_methods)]
1604-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".borrowing_sub(2, false), (3, false));")]
1605-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".borrowing_sub(2, true), (2, false));")]
1606-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.borrowing_sub(1, false), (", stringify!($SelfT), "::MAX, false));")]
1607-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.borrowing_sub(1, true), (", stringify!($SelfT), "::MAX - 1, false));")]
1608-
/// ```
1609-
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
1610-
#[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")]
1611-
#[must_use = "this returns the result of the operation, \
1612-
without modifying the original"]
1613-
#[inline]
1614-
pub const fn borrowing_sub(self, rhs: Self, borrow: bool) -> (Self, bool) {
1615-
let (sum, borrow) = (self as $UnsignedT).borrowing_sub(rhs as $UnsignedT, borrow);
1616-
(sum as $SelfT, borrow)
1617-
}
1618-
16191565
/// Calculates `self` - `rhs` with an unsigned `rhs`
16201566
///
16211567
/// Returns a tuple of the subtraction along with a boolean indicating

library/core/src/num/mod.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ depending on the target pointer size.
9595

9696
macro_rules! widening_impl {
9797
($SelfT:ty, $WideT:ty, $BITS:literal, unsigned) => {
98-
widening_impl!($SelfT, $WideT, $BITS, "");
99-
};
100-
($SelfT:ty, $WideT:ty, $BITS:literal, signed) => {
101-
widening_impl!($SelfT, $WideT, $BITS, "# //");
102-
};
103-
($SelfT:ty, $WideT:ty, $BITS:literal, $AdaptiveTestPrefix:literal) => {
10498
/// Calculates the complete product `self * rhs` without the possibility to overflow.
10599
///
106100
/// This returns the low-order (wrapping) bits and the high-order (overflow) bits
@@ -154,7 +148,7 @@ macro_rules! widening_impl {
154148
/// assert_eq!(5u32.carrying_mul(2, 10), (20, 0));
155149
/// assert_eq!(1_000_000_000u32.carrying_mul(10, 0), (1410065408, 2));
156150
/// assert_eq!(1_000_000_000u32.carrying_mul(10, 10), (1410065418, 2));
157-
#[doc = concat!($AdaptiveTestPrefix, "assert_eq!(",
151+
#[doc = concat!("assert_eq!(",
158152
stringify!($SelfT), "::MAX.carrying_mul(", stringify!($SelfT), "::MAX, ", stringify!($SelfT), "::MAX), ",
159153
"(0, ", stringify!($SelfT), "::MAX));"
160154
)]
@@ -203,22 +197,19 @@ macro_rules! widening_impl {
203197
impl i8 {
204198
int_impl! { i8, i8, u8, 8, 7, -128, 127, 2, "-0x7e", "0xa", "0x12", "0x12", "0x48",
205199
"[0x12]", "[0x12]", "", "" }
206-
widening_impl! { i8, i16, 8, signed }
207200
}
208201

209202
#[lang = "i16"]
210203
impl i16 {
211204
int_impl! { i16, i16, u16, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234", "0x3412",
212205
"0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" }
213-
widening_impl! { i16, i32, 16, signed }
214206
}
215207

216208
#[lang = "i32"]
217209
impl i32 {
218210
int_impl! { i32, i32, u32, 32, 31, -2147483648, 2147483647, 8, "0x10000b3", "0xb301",
219211
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
220212
"[0x12, 0x34, 0x56, 0x78]", "", "" }
221-
widening_impl! { i32, i64, 32, signed }
222213
}
223214

224215
#[lang = "i64"]
@@ -227,7 +218,6 @@ impl i64 {
227218
"0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
228219
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
229220
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", "", "" }
230-
widening_impl! { i64, i128, 64, signed }
231221
}
232222

233223
#[lang = "i128"]
@@ -248,7 +238,6 @@ impl isize {
248238
int_impl! { isize, i16, usize, 16, 15, -32768, 32767, 4, "-0x5ffd", "0x3a", "0x1234",
249239
"0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]",
250240
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
251-
widening_impl! { isize, i32, 16, signed }
252241
}
253242

254243
#[cfg(target_pointer_width = "32")]
@@ -258,7 +247,6 @@ impl isize {
258247
"0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
259248
"[0x12, 0x34, 0x56, 0x78]",
260249
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
261-
widening_impl! { isize, i64, 32, signed }
262250
}
263251

264252
#[cfg(target_pointer_width = "64")]
@@ -269,7 +257,6 @@ impl isize {
269257
"0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
270258
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]",
271259
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
272-
widening_impl! { isize, i128, 64, signed }
273260
}
274261

275262
/// If 6th bit set ascii is upper case.

0 commit comments

Comments
 (0)