Skip to content

Commit a20e5bb

Browse files
committed
Auto merge of #147684 - matthiaskrgr:rollup-uza3rqa, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #146187 (Unstably constify `ptr::drop_in_place` and related methods) - #146503 (std: improve handling of timed condition variable waits on macOS) - #147421 (Add check if span is from macro expansion) - #147630 (Bitset cleanups) - #147666 (Replace manual implementation with `carrying_mul_add`) - #147669 (fix missing link to `std::char` in `std` docs) - #147673 (pretty print u128 with display) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e100792 + 2054ec4 commit a20e5bb

File tree

25 files changed

+368
-171
lines changed

25 files changed

+368
-171
lines changed

compiler/rustc_hir/src/attrs/pretty_printing.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ pub trait PrintAttribute {
2626
fn print_attribute(&self, p: &mut Printer);
2727
}
2828

29-
impl PrintAttribute for u128 {
30-
fn should_render(&self) -> bool {
31-
true
32-
}
33-
34-
fn print_attribute(&self, p: &mut Printer) {
35-
p.word(self.to_string())
36-
}
37-
}
38-
3929
impl<T: PrintAttribute> PrintAttribute for &T {
4030
fn should_render(&self) -> bool {
4131
T::should_render(self)
@@ -148,7 +138,7 @@ macro_rules! print_tup {
148138

149139
print_tup!(A B C D E F G H);
150140
print_skip!(Span, (), ErrorGuaranteed);
151-
print_disp!(u16, bool, NonZero<u32>, Limit);
141+
print_disp!(u16, u128, bool, NonZero<u32>, Limit);
152142
print_debug!(
153143
Symbol,
154144
Ident,

compiler/rustc_index/src/bit_set.rs

Lines changed: 18 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<T: Idx> DenseBitSet<T> {
160160

161161
/// Count the number of set bits in the set.
162162
pub fn count(&self) -> usize {
163-
self.words.iter().map(|e| e.count_ones() as usize).sum()
163+
count_ones(&self.words)
164164
}
165165

166166
/// Returns `true` if `self` contains `elem`.
@@ -786,7 +786,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
786786

787787
match (&mut self_chunk, &other_chunk) {
788788
(_, Zeros) | (Ones, _) => {}
789-
(Zeros, Ones) | (Mixed(..), Ones) | (Zeros, Mixed(..)) => {
789+
(Zeros, _) | (Mixed(..), Ones) => {
790790
// `other_chunk` fully overwrites `self_chunk`
791791
*self_chunk = other_chunk.clone();
792792
changed = true;
@@ -814,10 +814,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
814814
op,
815815
);
816816
debug_assert!(has_changed);
817-
*self_chunk_count = self_chunk_words[0..num_words]
818-
.iter()
819-
.map(|w| w.count_ones() as ChunkSize)
820-
.sum();
817+
*self_chunk_count =
818+
count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
821819
if *self_chunk_count == chunk_domain_size {
822820
*self_chunk = Ones;
823821
}
@@ -850,7 +848,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
850848

851849
match (&mut self_chunk, &other_chunk) {
852850
(Zeros, _) | (_, Zeros) => {}
853-
(Ones | Mixed(_, _), Ones) => {
851+
(Ones | Mixed(..), Ones) => {
854852
changed = true;
855853
*self_chunk = Zeros;
856854
}
@@ -868,10 +866,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
868866
let self_chunk_count = chunk_domain_size - *other_chunk_count;
869867
debug_assert_eq!(
870868
self_chunk_count,
871-
self_chunk_words[0..num_words]
872-
.iter()
873-
.map(|w| w.count_ones() as ChunkSize)
874-
.sum()
869+
count_ones(&self_chunk_words[0..num_words]) as ChunkSize
875870
);
876871
*self_chunk = Mixed(self_chunk_count, Rc::new(self_chunk_words));
877872
}
@@ -894,10 +889,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
894889
op,
895890
);
896891
debug_assert!(has_changed);
897-
*self_chunk_count = self_chunk_words[0..num_words]
898-
.iter()
899-
.map(|w| w.count_ones() as ChunkSize)
900-
.sum();
892+
*self_chunk_count =
893+
count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
901894
if *self_chunk_count == 0 {
902895
*self_chunk = Zeros;
903896
}
@@ -953,10 +946,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
953946
op,
954947
);
955948
debug_assert!(has_changed);
956-
*self_chunk_count = self_chunk_words[0..num_words]
957-
.iter()
958-
.map(|w| w.count_ones() as ChunkSize)
959-
.sum();
949+
*self_chunk_count =
950+
count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
960951
if *self_chunk_count == 0 {
961952
*self_chunk = Zeros;
962953
}
@@ -970,48 +961,6 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
970961
}
971962
}
972963

973-
impl<T: Idx> BitRelations<ChunkedBitSet<T>> for DenseBitSet<T> {
974-
fn union(&mut self, other: &ChunkedBitSet<T>) -> bool {
975-
sequential_update(|elem| self.insert(elem), other.iter())
976-
}
977-
978-
fn subtract(&mut self, _other: &ChunkedBitSet<T>) -> bool {
979-
unimplemented!("implement if/when necessary");
980-
}
981-
982-
fn intersect(&mut self, other: &ChunkedBitSet<T>) -> bool {
983-
assert_eq!(self.domain_size(), other.domain_size);
984-
let mut changed = false;
985-
for (i, chunk) in other.chunks.iter().enumerate() {
986-
let mut words = &mut self.words[i * CHUNK_WORDS..];
987-
if words.len() > CHUNK_WORDS {
988-
words = &mut words[..CHUNK_WORDS];
989-
}
990-
match chunk {
991-
Zeros => {
992-
for word in words {
993-
if *word != 0 {
994-
changed = true;
995-
*word = 0;
996-
}
997-
}
998-
}
999-
Ones => (),
1000-
Mixed(_, data) => {
1001-
for (i, word) in words.iter_mut().enumerate() {
1002-
let new_val = *word & data[i];
1003-
if new_val != *word {
1004-
changed = true;
1005-
*word = new_val;
1006-
}
1007-
}
1008-
}
1009-
}
1010-
}
1011-
changed
1012-
}
1013-
}
1014-
1015964
impl<T> Clone for ChunkedBitSet<T> {
1016965
fn clone(&self) -> Self {
1017966
ChunkedBitSet {
@@ -1085,21 +1034,12 @@ impl Chunk {
10851034
assert!(0 < count && count < chunk_domain_size);
10861035

10871036
// Check the number of set bits matches `count`.
1088-
assert_eq!(
1089-
words.iter().map(|w| w.count_ones() as ChunkSize).sum::<ChunkSize>(),
1090-
count
1091-
);
1037+
assert_eq!(count_ones(words.as_slice()) as ChunkSize, count);
10921038

10931039
// Check the not-in-use words are all zeroed.
10941040
let num_words = num_words(chunk_domain_size as usize);
10951041
if num_words < CHUNK_WORDS {
1096-
assert_eq!(
1097-
words[num_words..]
1098-
.iter()
1099-
.map(|w| w.count_ones() as ChunkSize)
1100-
.sum::<ChunkSize>(),
1101-
0
1102-
);
1042+
assert_eq!(count_ones(&words[num_words..]) as ChunkSize, 0);
11031043
}
11041044
}
11051045
}
@@ -1122,15 +1062,6 @@ enum ChunkIter<'a> {
11221062
Finished,
11231063
}
11241064

1125-
// Applies a function to mutate a bitset, and returns true if any
1126-
// of the applications return true
1127-
fn sequential_update<T: Idx>(
1128-
mut self_update: impl FnMut(T) -> bool,
1129-
it: impl Iterator<Item = T>,
1130-
) -> bool {
1131-
it.fold(false, |changed, elem| self_update(elem) | changed)
1132-
}
1133-
11341065
impl<T: Idx> fmt::Debug for ChunkedBitSet<T> {
11351066
fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
11361067
w.debug_list().entries(self.iter()).finish()
@@ -1590,7 +1521,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
15901521
/// Returns the number of elements in `row`.
15911522
pub fn count(&self, row: R) -> usize {
15921523
let (start, end) = self.range(row);
1593-
self.words[start..end].iter().map(|e| e.count_ones() as usize).sum()
1524+
count_ones(&self.words[start..end])
15941525
}
15951526
}
15961527

@@ -1801,6 +1732,11 @@ fn max_bit(word: Word) -> usize {
18011732
WORD_BITS - 1 - word.leading_zeros() as usize
18021733
}
18031734

1735+
#[inline]
1736+
fn count_ones(words: &[Word]) -> usize {
1737+
words.iter().map(|word| word.count_ones() as usize).sum()
1738+
}
1739+
18041740
/// Integral type used to represent the bit set.
18051741
pub trait FiniteBitSetTy:
18061742
BitAnd<Output = Self>

compiler/rustc_index/src/bit_set/tests.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -306,34 +306,6 @@ fn with_elements_chunked(elements: &[usize], domain_size: usize) -> ChunkedBitSe
306306
s
307307
}
308308

309-
fn with_elements_standard(elements: &[usize], domain_size: usize) -> DenseBitSet<usize> {
310-
let mut s = DenseBitSet::new_empty(domain_size);
311-
for &e in elements {
312-
assert!(s.insert(e));
313-
}
314-
s
315-
}
316-
317-
#[test]
318-
fn chunked_bitset_into_bitset_operations() {
319-
let a = vec![1, 5, 7, 11, 15, 2000, 3000];
320-
let b = vec![3, 4, 11, 3000, 4000];
321-
let aub = vec![1, 3, 4, 5, 7, 11, 15, 2000, 3000, 4000];
322-
let aib = vec![11, 3000];
323-
324-
let b = with_elements_chunked(&b, 9876);
325-
326-
let mut union = with_elements_standard(&a, 9876);
327-
assert!(union.union(&b));
328-
assert!(!union.union(&b));
329-
assert!(union.iter().eq(aub.iter().copied()));
330-
331-
let mut intersection = with_elements_standard(&a, 9876);
332-
assert!(intersection.intersect(&b));
333-
assert!(!intersection.intersect(&b));
334-
assert!(intersection.iter().eq(aib.iter().copied()));
335-
}
336-
337309
#[test]
338310
fn chunked_bitset_iter() {
339311
fn check_iter(bit: &ChunkedBitSet<usize>, vec: &Vec<usize>) {

compiler/rustc_lint/src/shadowed_into_iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ impl<'tcx> LateLintPass<'tcx> for ShadowedIntoIter {
134134
&& let hir::ExprKind::Call(path, [_]) = &arg.kind
135135
&& let hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::IntoIterIntoIter, ..)) =
136136
&path.kind
137+
&& !receiver_arg.span.from_expansion()
138+
&& !expr.span.from_expansion()
137139
{
138140
Some(ShadowedIntoIterDiagSub::RemoveIntoIter {
139141
span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),

library/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ dependencies = [
139139

140140
[[package]]
141141
name = "libc"
142-
version = "0.2.175"
142+
version = "0.2.177"
143143
source = "registry+https://github.com/rust-lang/crates.io-index"
144-
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
144+
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
145145
dependencies = [
146146
"rustc-std-workspace-core",
147147
]

library/core/src/mem/manually_drop.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::marker::Destruct;
12
use crate::ops::{Deref, DerefMut, DerefPure};
23
use crate::ptr;
34

@@ -249,7 +250,11 @@ impl<T: ?Sized> ManuallyDrop<T> {
249250
/// [pinned]: crate::pin
250251
#[stable(feature = "manually_drop", since = "1.20.0")]
251252
#[inline]
252-
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {
253+
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
254+
pub const unsafe fn drop(slot: &mut ManuallyDrop<T>)
255+
where
256+
T: [const] Destruct,
257+
{
253258
// SAFETY: we are dropping the value pointed to by a mutable reference
254259
// which is guaranteed to be valid for writes.
255260
// It is up to the caller to make sure that `slot` isn't dropped again.

library/core/src/mem/maybe_uninit.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::any::type_name;
2+
use crate::marker::Destruct;
23
use crate::mem::ManuallyDrop;
34
use crate::{fmt, intrinsics, ptr, slice};
45

@@ -714,7 +715,11 @@ impl<T> MaybeUninit<T> {
714715
///
715716
/// [`assume_init`]: MaybeUninit::assume_init
716717
#[stable(feature = "maybe_uninit_extra", since = "1.60.0")]
717-
pub unsafe fn assume_init_drop(&mut self) {
718+
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
719+
pub const unsafe fn assume_init_drop(&mut self)
720+
where
721+
T: [const] Destruct,
722+
{
718723
// SAFETY: the caller must guarantee that `self` is initialized and
719724
// satisfies all invariants of `T`.
720725
// Dropping the value in place is safe if that is the case.
@@ -1390,7 +1395,11 @@ impl<T> [MaybeUninit<T>] {
13901395
/// behaviour.
13911396
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
13921397
#[inline(always)]
1393-
pub unsafe fn assume_init_drop(&mut self) {
1398+
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
1399+
pub const unsafe fn assume_init_drop(&mut self)
1400+
where
1401+
T: [const] Destruct,
1402+
{
13941403
if !self.is_empty() {
13951404
// SAFETY: the caller must guarantee that every element of `self`
13961405
// is initialized and satisfies all invariants of `T`.

library/core/src/num/bignum.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ macro_rules! impl_full_ops {
3838
fn full_mul_add(self, other: $ty, other2: $ty, carry: $ty) -> ($ty, $ty) {
3939
// This cannot overflow;
4040
// the output is between `0` and `2^nbits * (2^nbits - 1)`.
41-
let v = (self as $bigty) * (other as $bigty) + (other2 as $bigty) +
42-
(carry as $bigty);
43-
((v >> <$ty>::BITS) as $ty, v as $ty)
41+
let (lo, hi) = self.carrying_mul_add(other, other2, carry);
42+
(hi, lo)
4443
}
4544

4645
fn full_div_rem(self, other: $ty, borrow: $ty) -> ($ty, $ty) {

library/core/src/ptr/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@
403403

404404
use crate::cmp::Ordering;
405405
use crate::intrinsics::const_eval_select;
406-
use crate::marker::{FnPtr, PointeeSized};
406+
use crate::marker::{Destruct, FnPtr, PointeeSized};
407407
use crate::mem::{self, MaybeUninit, SizedTypeProperties};
408408
use crate::num::NonZero;
409409
use crate::{fmt, hash, intrinsics, ub_checks};
@@ -801,7 +801,11 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
801801
#[lang = "drop_in_place"]
802802
#[allow(unconditional_recursion)]
803803
#[rustc_diagnostic_item = "ptr_drop_in_place"]
804-
pub unsafe fn drop_in_place<T: PointeeSized>(to_drop: *mut T) {
804+
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
805+
pub const unsafe fn drop_in_place<T: PointeeSized>(to_drop: *mut T)
806+
where
807+
T: [const] Destruct,
808+
{
805809
// Code here does not matter - this is replaced by the
806810
// real drop glue by the compiler.
807811

library/core/src/ptr/mut_ptr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use crate::cmp::Ordering::{Equal, Greater, Less};
33
use crate::intrinsics::const_eval_select;
4-
use crate::marker::PointeeSized;
4+
use crate::marker::{Destruct, PointeeSized};
55
use crate::mem::{self, SizedTypeProperties};
66
use crate::slice::{self, SliceIndex};
77

@@ -1390,8 +1390,12 @@ impl<T: PointeeSized> *mut T {
13901390
///
13911391
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place()
13921392
#[stable(feature = "pointer_methods", since = "1.26.0")]
1393+
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
13931394
#[inline(always)]
1394-
pub unsafe fn drop_in_place(self) {
1395+
pub const unsafe fn drop_in_place(self)
1396+
where
1397+
T: [const] Destruct,
1398+
{
13951399
// SAFETY: the caller must uphold the safety contract for `drop_in_place`.
13961400
unsafe { drop_in_place(self) }
13971401
}

0 commit comments

Comments
 (0)