Skip to content

Commit ec853b6

Browse files
committed
Add copy bound to numeric intrinsics
1 parent 7fdc3ef commit ec853b6

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/libcore/intrinsics.rs

+31-31
Original file line numberDiff line numberDiff line change
@@ -1550,36 +1550,36 @@ extern "rust-intrinsic" {
15501550

15511551
/// Float addition that allows optimizations based on algebraic rules.
15521552
/// May assume inputs are finite.
1553-
pub fn fadd_fast<T>(a: T, b: T) -> T;
1553+
pub fn fadd_fast<T: Copy>(a: T, b: T) -> T;
15541554

15551555
/// Float subtraction that allows optimizations based on algebraic rules.
15561556
/// May assume inputs are finite.
1557-
pub fn fsub_fast<T>(a: T, b: T) -> T;
1557+
pub fn fsub_fast<T: Copy>(a: T, b: T) -> T;
15581558

15591559
/// Float multiplication that allows optimizations based on algebraic rules.
15601560
/// May assume inputs are finite.
1561-
pub fn fmul_fast<T>(a: T, b: T) -> T;
1561+
pub fn fmul_fast<T: Copy>(a: T, b: T) -> T;
15621562

15631563
/// Float division that allows optimizations based on algebraic rules.
15641564
/// May assume inputs are finite.
1565-
pub fn fdiv_fast<T>(a: T, b: T) -> T;
1565+
pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
15661566

15671567
/// Float remainder that allows optimizations based on algebraic rules.
15681568
/// May assume inputs are finite.
1569-
pub fn frem_fast<T>(a: T, b: T) -> T;
1569+
pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
15701570

15711571
/// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
15721572
/// (<https://github.com/rust-lang/rust/issues/10184>)
15731573
/// This is under stabilization at <https://github.com/rust-lang/rust/issues/67058>
1574-
pub fn float_to_int_approx_unchecked<Float, Int>(value: Float) -> Int;
1574+
pub fn float_to_int_approx_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
15751575

15761576
/// Returns the number of bits set in an integer type `T`
15771577
///
15781578
/// The stabilized versions of this intrinsic are available on the integer
15791579
/// primitives via the `count_ones` method. For example,
15801580
/// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
15811581
#[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1582-
pub fn ctpop<T>(x: T) -> T;
1582+
pub fn ctpop<T: Copy>(x: T) -> T;
15831583

15841584
/// Returns the number of leading unset bits (zeroes) in an integer type `T`.
15851585
///
@@ -1611,7 +1611,7 @@ extern "rust-intrinsic" {
16111611
/// assert_eq!(num_leading, 16);
16121612
/// ```
16131613
#[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1614-
pub fn ctlz<T>(x: T) -> T;
1614+
pub fn ctlz<T: Copy>(x: T) -> T;
16151615

16161616
/// Like `ctlz`, but extra-unsafe as it returns `undef` when
16171617
/// given an `x` with value `0`.
@@ -1628,7 +1628,7 @@ extern "rust-intrinsic" {
16281628
/// assert_eq!(num_leading, 3);
16291629
/// ```
16301630
#[rustc_const_unstable(feature = "constctlz", issue = "none")]
1631-
pub fn ctlz_nonzero<T>(x: T) -> T;
1631+
pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
16321632

16331633
/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
16341634
///
@@ -1660,7 +1660,7 @@ extern "rust-intrinsic" {
16601660
/// assert_eq!(num_trailing, 16);
16611661
/// ```
16621662
#[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1663-
pub fn cttz<T>(x: T) -> T;
1663+
pub fn cttz<T: Copy>(x: T) -> T;
16641664

16651665
/// Like `cttz`, but extra-unsafe as it returns `undef` when
16661666
/// given an `x` with value `0`.
@@ -1677,51 +1677,51 @@ extern "rust-intrinsic" {
16771677
/// assert_eq!(num_trailing, 3);
16781678
/// ```
16791679
#[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1680-
pub fn cttz_nonzero<T>(x: T) -> T;
1680+
pub fn cttz_nonzero<T: Copy>(x: T) -> T;
16811681

16821682
/// Reverses the bytes in an integer type `T`.
16831683
///
16841684
/// The stabilized versions of this intrinsic are available on the integer
16851685
/// primitives via the `swap_bytes` method. For example,
16861686
/// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
16871687
#[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1688-
pub fn bswap<T>(x: T) -> T;
1688+
pub fn bswap<T: Copy>(x: T) -> T;
16891689

16901690
/// Reverses the bits in an integer type `T`.
16911691
///
16921692
/// The stabilized versions of this intrinsic are available on the integer
16931693
/// primitives via the `reverse_bits` method. For example,
16941694
/// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
16951695
#[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1696-
pub fn bitreverse<T>(x: T) -> T;
1696+
pub fn bitreverse<T: Copy>(x: T) -> T;
16971697

16981698
/// Performs checked integer addition.
16991699
///
17001700
/// The stabilized versions of this intrinsic are available on the integer
17011701
/// primitives via the `overflowing_add` method. For example,
17021702
/// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
17031703
#[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1704-
pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
1704+
pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
17051705

17061706
/// Performs checked integer subtraction
17071707
///
17081708
/// The stabilized versions of this intrinsic are available on the integer
17091709
/// primitives via the `overflowing_sub` method. For example,
17101710
/// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
17111711
#[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1712-
pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
1712+
pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
17131713

17141714
/// Performs checked integer multiplication
17151715
///
17161716
/// The stabilized versions of this intrinsic are available on the integer
17171717
/// primitives via the `overflowing_mul` method. For example,
17181718
/// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
17191719
#[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1720-
pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
1720+
pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
17211721

17221722
/// Performs an exact division, resulting in undefined behavior where
17231723
/// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1724-
pub fn exact_div<T>(x: T, y: T) -> T;
1724+
pub fn exact_div<T: Copy>(x: T, y: T) -> T;
17251725

17261726
/// Performs an unchecked division, resulting in undefined behavior
17271727
/// where y = 0 or x = `T::min_value()` and y = -1
@@ -1730,15 +1730,15 @@ extern "rust-intrinsic" {
17301730
/// primitives via the `checked_div` method. For example,
17311731
/// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
17321732
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1733-
pub fn unchecked_div<T>(x: T, y: T) -> T;
1733+
pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
17341734
/// Returns the remainder of an unchecked division, resulting in
17351735
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
17361736
///
17371737
/// The stabilized versions of this intrinsic are available on the integer
17381738
/// primitives via the `checked_rem` method. For example,
17391739
/// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
17401740
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1741-
pub fn unchecked_rem<T>(x: T, y: T) -> T;
1741+
pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
17421742

17431743
/// Performs an unchecked left shift, resulting in undefined behavior when
17441744
/// y < 0 or y >= N, where N is the width of T in bits.
@@ -1747,83 +1747,83 @@ extern "rust-intrinsic" {
17471747
/// primitives via the `checked_shl` method. For example,
17481748
/// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
17491749
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1750-
pub fn unchecked_shl<T>(x: T, y: T) -> T;
1750+
pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
17511751
/// Performs an unchecked right shift, resulting in undefined behavior when
17521752
/// y < 0 or y >= N, where N is the width of T in bits.
17531753
///
17541754
/// The stabilized versions of this intrinsic are available on the integer
17551755
/// primitives via the `checked_shr` method. For example,
17561756
/// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
17571757
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1758-
pub fn unchecked_shr<T>(x: T, y: T) -> T;
1758+
pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
17591759

17601760
/// Returns the result of an unchecked addition, resulting in
17611761
/// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
17621762
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1763-
pub fn unchecked_add<T>(x: T, y: T) -> T;
1763+
pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
17641764

17651765
/// Returns the result of an unchecked subtraction, resulting in
17661766
/// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
17671767
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1768-
pub fn unchecked_sub<T>(x: T, y: T) -> T;
1768+
pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
17691769

17701770
/// Returns the result of an unchecked multiplication, resulting in
17711771
/// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
17721772
#[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1773-
pub fn unchecked_mul<T>(x: T, y: T) -> T;
1773+
pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
17741774

17751775
/// Performs rotate left.
17761776
///
17771777
/// The stabilized versions of this intrinsic are available on the integer
17781778
/// primitives via the `rotate_left` method. For example,
17791779
/// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
17801780
#[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1781-
pub fn rotate_left<T>(x: T, y: T) -> T;
1781+
pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
17821782

17831783
/// Performs rotate right.
17841784
///
17851785
/// The stabilized versions of this intrinsic are available on the integer
17861786
/// primitives via the `rotate_right` method. For example,
17871787
/// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
17881788
#[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1789-
pub fn rotate_right<T>(x: T, y: T) -> T;
1789+
pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
17901790

17911791
/// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
17921792
///
17931793
/// The stabilized versions of this intrinsic are available on the integer
17941794
/// primitives via the `checked_add` method. For example,
17951795
/// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
17961796
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1797-
pub fn wrapping_add<T>(a: T, b: T) -> T;
1797+
pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
17981798
/// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
17991799
///
18001800
/// The stabilized versions of this intrinsic are available on the integer
18011801
/// primitives via the `checked_sub` method. For example,
18021802
/// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
18031803
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1804-
pub fn wrapping_sub<T>(a: T, b: T) -> T;
1804+
pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
18051805
/// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
18061806
///
18071807
/// The stabilized versions of this intrinsic are available on the integer
18081808
/// primitives via the `checked_mul` method. For example,
18091809
/// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
18101810
#[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1811-
pub fn wrapping_mul<T>(a: T, b: T) -> T;
1811+
pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
18121812

18131813
/// Computes `a + b`, while saturating at numeric bounds.
18141814
///
18151815
/// The stabilized versions of this intrinsic are available on the integer
18161816
/// primitives via the `saturating_add` method. For example,
18171817
/// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
18181818
#[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1819-
pub fn saturating_add<T>(a: T, b: T) -> T;
1819+
pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
18201820
/// Computes `a - b`, while saturating at numeric bounds.
18211821
///
18221822
/// The stabilized versions of this intrinsic are available on the integer
18231823
/// primitives via the `saturating_sub` method. For example,
18241824
/// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
18251825
#[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1826-
pub fn saturating_sub<T>(a: T, b: T) -> T;
1826+
pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
18271827

18281828
/// Returns the value of the discriminant for the variant in 'v',
18291829
/// cast to a `u64`; if `T` has no discriminant, returns 0.

0 commit comments

Comments
 (0)