Skip to content

Commit 15795ee

Browse files
committed
Auto merge of rust-lang#123385 - matthiaskrgr:rollup-v69vjbn, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#123198 (Add fn const BuildHasherDefault::new) - rust-lang#123226 (De-LLVM the unchecked shifts [MCP#693]) - rust-lang#123302 (Make sure to insert `Sized` bound first into clauses list) - rust-lang#123348 (rustdoc: add a couple of regression tests) - rust-lang#123362 (Check that nested statics in thread locals are duplicated per thread.) - rust-lang#123368 (CFI: Support non-general coroutines) - rust-lang#123375 (rustdoc: synthetic auto trait impls: accept unresolved region vars for now) - rust-lang#123378 (Update sysinfo to 0.30.8) Failed merges: - rust-lang#123349 (Fix capture analysis for by-move closure bodies) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c1824d1 + 4dd5c26 commit 15795ee

File tree

6 files changed

+77
-32
lines changed

6 files changed

+77
-32
lines changed

core/src/hash/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,18 @@ pub trait BuildHasher {
752752
#[stable(since = "1.7.0", feature = "build_hasher")]
753753
pub struct BuildHasherDefault<H>(marker::PhantomData<fn() -> H>);
754754

755+
impl<H> BuildHasherDefault<H> {
756+
/// Creates a new BuildHasherDefault for Hasher `H`.
757+
#[unstable(
758+
feature = "build_hasher_default_const_new",
759+
issue = "123197",
760+
reason = "recently added"
761+
)]
762+
pub const fn new() -> Self {
763+
BuildHasherDefault(marker::PhantomData)
764+
}
765+
}
766+
755767
#[stable(since = "1.9.0", feature = "core_impl_debug")]
756768
impl<H> fmt::Debug for BuildHasherDefault<H> {
757769
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -778,7 +790,7 @@ impl<H> Clone for BuildHasherDefault<H> {
778790
#[stable(since = "1.7.0", feature = "build_hasher")]
779791
impl<H> Default for BuildHasherDefault<H> {
780792
fn default() -> BuildHasherDefault<H> {
781-
BuildHasherDefault(marker::PhantomData)
793+
Self::new()
782794
}
783795
}
784796

core/src/intrinsics.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,18 +2236,20 @@ extern "rust-intrinsic" {
22362236
/// Safe wrappers for this intrinsic are available on the integer
22372237
/// primitives via the `checked_shl` method. For example,
22382238
/// [`u32::checked_shl`]
2239+
#[cfg(not(bootstrap))]
22392240
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
22402241
#[rustc_nounwind]
2241-
pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
2242+
pub fn unchecked_shl<T: Copy, U: Copy>(x: T, y: U) -> T;
22422243
/// Performs an unchecked right shift, resulting in undefined behavior when
22432244
/// `y < 0` or `y >= N`, where N is the width of T in bits.
22442245
///
22452246
/// Safe wrappers for this intrinsic are available on the integer
22462247
/// primitives via the `checked_shr` method. For example,
22472248
/// [`u32::checked_shr`]
2249+
#[cfg(not(bootstrap))]
22482250
#[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
22492251
#[rustc_nounwind]
2250-
pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
2252+
pub fn unchecked_shr<T: Copy, U: Copy>(x: T, y: U) -> T;
22512253

22522254
/// Returns the result of an unchecked addition, resulting in
22532255
/// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.

core/src/num/int_macros.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,18 @@ macro_rules! int_impl {
12271227
#[inline(always)]
12281228
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12291229
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
1230-
// SAFETY: the caller must uphold the safety contract for
1231-
// `unchecked_shl`.
1232-
// Any legal shift amount is losslessly representable in the self type.
1233-
unsafe { intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
1230+
#[cfg(bootstrap)]
1231+
{
1232+
// For bootstrapping, just use built-in primitive shift.
1233+
// panicking is a legal manifestation of UB
1234+
self << rhs
1235+
}
1236+
#[cfg(not(bootstrap))]
1237+
{
1238+
// SAFETY: the caller must uphold the safety contract for
1239+
// `unchecked_shl`.
1240+
unsafe { intrinsics::unchecked_shl(self, rhs) }
1241+
}
12341242
}
12351243

12361244
/// Checked shift right. Computes `self >> rhs`, returning `None` if `rhs` is
@@ -1310,10 +1318,18 @@ macro_rules! int_impl {
13101318
#[inline(always)]
13111319
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13121320
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
1313-
// SAFETY: the caller must uphold the safety contract for
1314-
// `unchecked_shr`.
1315-
// Any legal shift amount is losslessly representable in the self type.
1316-
unsafe { intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
1321+
#[cfg(bootstrap)]
1322+
{
1323+
// For bootstrapping, just use built-in primitive shift.
1324+
// panicking is a legal manifestation of UB
1325+
self >> rhs
1326+
}
1327+
#[cfg(not(bootstrap))]
1328+
{
1329+
// SAFETY: the caller must uphold the safety contract for
1330+
// `unchecked_shr`.
1331+
unsafe { intrinsics::unchecked_shr(self, rhs) }
1332+
}
13171333
}
13181334

13191335
/// Checked absolute value. Computes `self.abs()`, returning `None` if

core/src/num/mod.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,6 @@ macro_rules! widening_impl {
285285
};
286286
}
287287

288-
macro_rules! conv_rhs_for_unchecked_shift {
289-
($SelfT:ty, $x:expr) => {{
290-
// If the `as` cast will truncate, ensure we still tell the backend
291-
// that the pre-truncation value was also small.
292-
if <$SelfT>::BITS < 32 {
293-
intrinsics::assume($x <= (<$SelfT>::MAX as u32));
294-
}
295-
$x as $SelfT
296-
}};
297-
}
298-
299288
impl i8 {
300289
int_impl! {
301290
Self = i8,

core/src/num/uint_macros.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,10 +1286,18 @@ macro_rules! uint_impl {
12861286
#[inline(always)]
12871287
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12881288
pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
1289-
// SAFETY: the caller must uphold the safety contract for
1290-
// `unchecked_shl`.
1291-
// Any legal shift amount is losslessly representable in the self type.
1292-
unsafe { intrinsics::unchecked_shl(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
1289+
#[cfg(bootstrap)]
1290+
{
1291+
// For bootstrapping, just use built-in primitive shift.
1292+
// panicking is a legal manifestation of UB
1293+
self << rhs
1294+
}
1295+
#[cfg(not(bootstrap))]
1296+
{
1297+
// SAFETY: the caller must uphold the safety contract for
1298+
// `unchecked_shl`.
1299+
unsafe { intrinsics::unchecked_shl(self, rhs) }
1300+
}
12931301
}
12941302

12951303
/// Checked shift right. Computes `self >> rhs`, returning `None`
@@ -1369,10 +1377,18 @@ macro_rules! uint_impl {
13691377
#[inline(always)]
13701378
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
13711379
pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
1372-
// SAFETY: the caller must uphold the safety contract for
1373-
// `unchecked_shr`.
1374-
// Any legal shift amount is losslessly representable in the self type.
1375-
unsafe { intrinsics::unchecked_shr(self, conv_rhs_for_unchecked_shift!($SelfT, rhs)) }
1380+
#[cfg(bootstrap)]
1381+
{
1382+
// For bootstrapping, just use built-in primitive shift.
1383+
// panicking is a legal manifestation of UB
1384+
self >> rhs
1385+
}
1386+
#[cfg(not(bootstrap))]
1387+
{
1388+
// SAFETY: the caller must uphold the safety contract for
1389+
// `unchecked_shr`.
1390+
unsafe { intrinsics::unchecked_shr(self, rhs) }
1391+
}
13761392
}
13771393

13781394
/// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if

core/src/ptr/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,9 +1781,19 @@ pub(crate) const unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usiz
17811781
// FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <=
17821782
// 1, where the method versions of these operations are not inlined.
17831783
use intrinsics::{
1784-
assume, cttz_nonzero, exact_div, mul_with_overflow, unchecked_rem, unchecked_shl,
1785-
unchecked_shr, unchecked_sub, wrapping_add, wrapping_mul, wrapping_sub,
1784+
assume, cttz_nonzero, exact_div, mul_with_overflow, unchecked_rem, unchecked_sub,
1785+
wrapping_add, wrapping_mul, wrapping_sub,
17861786
};
1787+
#[cfg(bootstrap)]
1788+
const unsafe fn unchecked_shl(value: usize, shift: usize) -> usize {
1789+
value << shift
1790+
}
1791+
#[cfg(bootstrap)]
1792+
const unsafe fn unchecked_shr(value: usize, shift: usize) -> usize {
1793+
value >> shift
1794+
}
1795+
#[cfg(not(bootstrap))]
1796+
use intrinsics::{unchecked_shl, unchecked_shr};
17871797

17881798
/// Calculate multiplicative modular inverse of `x` modulo `m`.
17891799
///

0 commit comments

Comments
 (0)