From 0dc5b52e8eef98e973d9935c45e8dc3d7fbd6a1d Mon Sep 17 00:00:00 2001 From: Usman Akinyemi Date: Fri, 16 Jan 2026 04:25:12 +0530 Subject: [PATCH] simplify words initialization using Rc::new_zeroed Now that Rc::new_zeroed is stable, remove the cfg(feature = "nightly") branch and the temporary zeroed array on stable. This avoids copying a potentially large [Word; CHUNK_WORDS] into the Rc. Signed-off-by: Usman Akinyemi --- compiler/rustc_index/src/bit_set.rs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index a9bdf597e128f..184fa409d9605 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -634,22 +634,12 @@ impl ChunkedBitSet { match *chunk { Zeros => { if chunk_domain_size > 1 { - #[cfg(feature = "nightly")] let mut words = { // We take some effort to avoid copying the words. let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed(); // SAFETY: `words` can safely be all zeroes. unsafe { words.assume_init() } }; - #[cfg(not(feature = "nightly"))] - let mut words = { - // FIXME: unconditionally use `Rc::new_zeroed` once it is stable (#129396). - let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed(); - // SAFETY: `words` can safely be all zeroes. - let words = unsafe { words.assume_init() }; - // Unfortunate possibly-large copy - Rc::new(words) - }; let words_ref = Rc::get_mut(&mut words).unwrap(); let (word_index, mask) = chunk_word_index_and_mask(elem); @@ -695,22 +685,12 @@ impl ChunkedBitSet { Zeros => false, Ones => { if chunk_domain_size > 1 { - #[cfg(feature = "nightly")] let mut words = { // We take some effort to avoid copying the words. let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed(); // SAFETY: `words` can safely be all zeroes. unsafe { words.assume_init() } }; - #[cfg(not(feature = "nightly"))] - let mut words = { - // FIXME: unconditionally use `Rc::new_zeroed` once it is stable (#129396). - let words = mem::MaybeUninit::<[Word; CHUNK_WORDS]>::zeroed(); - // SAFETY: `words` can safely be all zeroes. - let words = unsafe { words.assume_init() }; - // Unfortunate possibly-large copy - Rc::new(words) - }; let words_ref = Rc::get_mut(&mut words).unwrap(); // Set only the bits in use.