Skip to content

Commit 3a11261

Browse files
committed
Auto merge of #106760 - compiler-errors:rollup-0bogyco, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #103236 (doc: rewrite doc for signed int::{carrying_add,borrowing_sub}) - #103800 (Stabilize `::{core,std}::pin::pin!`) - #106097 (Migrate mir_build diagnostics 2 of 3) - #106170 (Move autoderef to `rustc_hir_analysis`) - #106323 (Stabilize f16c_target_feature) - #106360 (Tweak E0277 `&`-removal suggestions) - #106524 (Label `struct/enum constructor` instead of `fn item`, mention that it should be called on type mismatch) - #106739 (Remove `<dyn AstConv<'tcx>>::fun(c, ...)` calls in favour of `c.astconv().fun(...)`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d8d8745 + f3c70c9 commit 3a11261

File tree

4 files changed

+79
-45
lines changed

4 files changed

+79
-45
lines changed

core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@
239239
#![feature(arm_target_feature)]
240240
#![feature(avx512_target_feature)]
241241
#![feature(cmpxchg16b_target_feature)]
242-
#![feature(f16c_target_feature)]
243242
#![feature(hexagon_target_feature)]
244243
#![feature(mips_target_feature)]
245244
#![feature(powerpc_target_feature)]
@@ -248,6 +247,7 @@
248247
#![feature(sse4a_target_feature)]
249248
#![feature(tbm_target_feature)]
250249
#![feature(wasm_target_feature)]
250+
#![cfg_attr(bootstrap, feature(f16c_target_feature))]
251251

252252
// allow using `core::` in intra-doc links
253253
#[allow(unused_extern_crates)]

core/src/num/int_macros.rs

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,37 +1514,50 @@ macro_rules! int_impl {
15141514
(a as Self, b)
15151515
}
15161516

1517-
/// Calculates `self + rhs + carry` without the ability to overflow.
1517+
/// Calculates `self` + `rhs` + `carry` and checks for overflow.
15181518
///
1519-
/// Performs "signed ternary addition" which takes in an extra bit to add, and may return an
1520-
/// additional bit of overflow. This signed function is used only on the highest-ordered data,
1521-
/// for which the signed overflow result indicates whether the big integer overflowed or not.
1519+
/// Performs "ternary addition" of two integer operands and a carry-in
1520+
/// bit, and returns a tuple of the sum along with a boolean indicating
1521+
/// whether an arithmetic overflow would occur. On overflow, the wrapped
1522+
/// value is returned.
15221523
///
1523-
/// # Examples
1524+
/// This allows chaining together multiple additions to create a wider
1525+
/// addition, and can be useful for bignum addition. This method should
1526+
/// only be used for the most significant word; for the less significant
1527+
/// words the unsigned method
1528+
#[doc = concat!("[`", stringify!($UnsignedT), "::carrying_add`]")]
1529+
/// should be used.
15241530
///
1525-
/// Basic usage:
1531+
/// The output boolean returned by this method is *not* a carry flag,
1532+
/// and should *not* be added to a more significant word.
15261533
///
1527-
/// ```
1528-
/// #![feature(bigint_helper_methods)]
1529-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, false), (7, false));")]
1530-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".carrying_add(2, true), (8, false));")]
1531-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, false), (", stringify!($SelfT), "::MIN, true));")]
1532-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(0, true), (", stringify!($SelfT), "::MIN, true));")]
1533-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, true), (", stringify!($SelfT), "::MIN + 1, true));")]
1534-
#[doc = concat!("assert_eq!(",
1535-
stringify!($SelfT), "::MAX.carrying_add(", stringify!($SelfT), "::MAX, true), ",
1536-
"(-1, true));"
1537-
)]
1538-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.carrying_add(-1, true), (", stringify!($SelfT), "::MIN, false));")]
1539-
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".carrying_add(", stringify!($SelfT), "::MAX, true), (", stringify!($SelfT), "::MIN, true));")]
1540-
/// ```
1534+
/// If the input carry is false, this method is equivalent to
1535+
/// [`overflowing_add`](Self::overflowing_add).
15411536
///
1542-
/// If `carry` is false, this method is equivalent to [`overflowing_add`](Self::overflowing_add):
1537+
/// # Examples
15431538
///
15441539
/// ```
15451540
/// #![feature(bigint_helper_methods)]
1546-
#[doc = concat!("assert_eq!(5_", stringify!($SelfT), ".carrying_add(2, false), 5_", stringify!($SelfT), ".overflowing_add(2));")]
1547-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.carrying_add(1, false), ", stringify!($SelfT), "::MAX.overflowing_add(1));")]
1541+
/// // Only the most significant word is signed.
1542+
/// //
1543+
#[doc = concat!("// 10 MAX (a = 10 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
1544+
#[doc = concat!("// + -5 9 (b = -5 × 2^", stringify!($BITS), " + 9)")]
1545+
/// // ---------
1546+
#[doc = concat!("// 6 8 (sum = 6 × 2^", stringify!($BITS), " + 8)")]
1547+
///
1548+
#[doc = concat!("let (a1, a0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (10, ", stringify!($UnsignedT), "::MAX);")]
1549+
#[doc = concat!("let (b1, b0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (-5, 9);")]
1550+
/// let carry0 = false;
1551+
///
1552+
#[doc = concat!("// ", stringify!($UnsignedT), "::carrying_add for the less significant words")]
1553+
/// let (sum0, carry1) = a0.carrying_add(b0, carry0);
1554+
/// assert_eq!(carry1, true);
1555+
///
1556+
#[doc = concat!("// ", stringify!($SelfT), "::carrying_add for the most significant word")]
1557+
/// let (sum1, overflow) = a1.carrying_add(b1, carry1);
1558+
/// assert_eq!(overflow, false);
1559+
///
1560+
/// assert_eq!((sum1, sum0), (6, 8));
15481561
/// ```
15491562
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
15501563
#[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")]
@@ -1608,25 +1621,51 @@ macro_rules! int_impl {
16081621
(a as Self, b)
16091622
}
16101623

1611-
/// Calculates `self - rhs - borrow` without the ability to overflow.
1624+
/// Calculates `self` &minus; `rhs` &minus; `borrow` and checks for
1625+
/// overflow.
16121626
///
1613-
/// Performs "signed ternary subtraction" which takes in an extra bit to subtract, and may return an
1614-
/// additional bit of overflow. This signed function is used only on the highest-ordered data,
1615-
/// for which the signed overflow result indicates whether the big integer overflowed or not.
1627+
/// Performs "ternary subtraction" by subtracting both an integer
1628+
/// operandand a borrow-in bit from `self`, and returns a tuple of the
1629+
/// difference along with a boolean indicating whether an arithmetic
1630+
/// overflow would occur. On overflow, the wrapped value is returned.
16161631
///
1617-
/// # Examples
1632+
/// This allows chaining together multiple subtractions to create a
1633+
/// wider subtraction, and can be useful for bignum subtraction. This
1634+
/// method should only be used for the most significant word; for the
1635+
/// less significant words the unsigned method
1636+
#[doc = concat!("[`", stringify!($UnsignedT), "::borrowing_sub`]")]
1637+
/// should be used.
16181638
///
1619-
/// Basic usage:
1639+
/// The output boolean returned by this method is *not* a borrow flag,
1640+
/// and should *not* be subtracted from a more significant word.
1641+
///
1642+
/// If the input borrow is false, this method is equivalent to
1643+
/// [`overflowing_sub`](Self::overflowing_sub).
1644+
///
1645+
/// # Examples
16201646
///
16211647
/// ```
16221648
/// #![feature(bigint_helper_methods)]
1623-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".borrowing_sub(2, false), (3, false));")]
1624-
#[doc = concat!("assert_eq!(5", stringify!($SelfT), ".borrowing_sub(2, true), (2, false));")]
1625-
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".borrowing_sub(1, false), (-1, false));")]
1626-
#[doc = concat!("assert_eq!(0", stringify!($SelfT), ".borrowing_sub(1, true), (-2, false));")]
1627-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.borrowing_sub(1, true), (", stringify!($SelfT), "::MAX - 1, true));")]
1628-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.borrowing_sub(-1, false), (", stringify!($SelfT), "::MIN, true));")]
1629-
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.borrowing_sub(-1, true), (", stringify!($SelfT), "::MAX, false));")]
1649+
/// // Only the most significant word is signed.
1650+
/// //
1651+
#[doc = concat!("// 6 8 (a = 6 × 2^", stringify!($BITS), " + 8)")]
1652+
#[doc = concat!("// - -5 9 (b = -5 × 2^", stringify!($BITS), " + 9)")]
1653+
/// // ---------
1654+
#[doc = concat!("// 10 MAX (diff = 10 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
1655+
///
1656+
#[doc = concat!("let (a1, a0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (6, 8);")]
1657+
#[doc = concat!("let (b1, b0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (-5, 9);")]
1658+
/// let borrow0 = false;
1659+
///
1660+
#[doc = concat!("// ", stringify!($UnsignedT), "::borrowing_sub for the less significant words")]
1661+
/// let (diff0, borrow1) = a0.borrowing_sub(b0, borrow0);
1662+
/// assert_eq!(borrow1, true);
1663+
///
1664+
#[doc = concat!("// ", stringify!($SelfT), "::borrowing_sub for the most significant word")]
1665+
/// let (diff1, overflow) = a1.borrowing_sub(b1, borrow1);
1666+
/// assert_eq!(overflow, false);
1667+
///
1668+
#[doc = concat!("assert_eq!((diff1, diff0), (10, ", stringify!($UnsignedT), "::MAX));")]
16301669
/// ```
16311670
#[unstable(feature = "bigint_helper_methods", issue = "85532")]
16321671
#[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")]

core/src/pin.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,8 @@ impl<P: Deref> Pin<P> {
622622
/// that the closure is pinned.
623623
///
624624
/// The better alternative is to avoid all that trouble and do the pinning in the outer function
625-
/// instead (here using the unstable `pin` macro):
625+
/// instead (here using the [`pin!`][crate::pin::pin] macro):
626626
/// ```
627-
/// #![feature(pin_macro)]
628627
/// use std::pin::pin;
629628
/// use std::task::Context;
630629
/// use std::future::Future;
@@ -1026,7 +1025,6 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
10261025
/// ### Basic usage
10271026
///
10281027
/// ```rust
1029-
/// #![feature(pin_macro)]
10301028
/// # use core::marker::PhantomPinned as Foo;
10311029
/// use core::pin::{pin, Pin};
10321030
///
@@ -1044,7 +1042,6 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
10441042
/// ### Manually polling a `Future` (without `Unpin` bounds)
10451043
///
10461044
/// ```rust
1047-
/// #![feature(pin_macro)]
10481045
/// use std::{
10491046
/// future::Future,
10501047
/// pin::pin,
@@ -1083,7 +1080,7 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
10831080
/// ### With `Generator`s
10841081
///
10851082
/// ```rust
1086-
/// #![feature(generators, generator_trait, pin_macro)]
1083+
/// #![feature(generators, generator_trait)]
10871084
/// use core::{
10881085
/// ops::{Generator, GeneratorState},
10891086
/// pin::pin,
@@ -1126,7 +1123,6 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
11261123
/// The following, for instance, fails to compile:
11271124
///
11281125
/// ```rust,compile_fail
1129-
/// #![feature(pin_macro)]
11301126
/// use core::pin::{pin, Pin};
11311127
/// # use core::{marker::PhantomPinned as Foo, mem::drop as stuff};
11321128
///
@@ -1168,7 +1164,7 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
11681164
/// constructor.
11691165
///
11701166
/// [`Box::pin`]: ../../std/boxed/struct.Box.html#method.pin
1171-
#[unstable(feature = "pin_macro", issue = "93178")]
1167+
#[stable(feature = "pin_macro", since = "CURRENT_RUSTC_VERSION")]
11721168
#[rustc_macro_transparency = "semitransparent"]
11731169
#[allow_internal_unstable(unsafe_pin_internals)]
11741170
pub macro pin($value:expr $(,)?) {

core/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#![feature(is_sorted)]
4949
#![feature(layout_for_ptr)]
5050
#![feature(pattern)]
51-
#![feature(pin_macro)]
5251
#![feature(sort_internals)]
5352
#![feature(slice_take)]
5453
#![feature(slice_from_ptr_range)]

0 commit comments

Comments
 (0)