about summary refs log tree commit diff
path: root/compiler/rustc_index
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_index')
-rw-r--r--compiler/rustc_index/src/bit_set.rs48
-rw-r--r--compiler/rustc_index/src/lib.rs1
2 files changed, 37 insertions, 12 deletions
diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs
index d0b4889b45f..3ea1a52ae28 100644
--- a/compiler/rustc_index/src/bit_set.rs
+++ b/compiler/rustc_index/src/bit_set.rs
@@ -9,6 +9,7 @@ use std::slice;
 use arrayvec::ArrayVec;
 use smallvec::{smallvec, SmallVec};
 
+#[cfg(feature = "nightly")]
 use rustc_macros::{Decodable, Encodable};
 
 use crate::{Idx, IndexVec};
@@ -111,7 +112,8 @@ macro_rules! bit_relations_inherent_impls {
 /// to or greater than the domain size. All operations that involve two bitsets
 /// will panic if the bitsets have differing domain sizes.
 ///
-#[derive(Eq, PartialEq, Hash, Decodable, Encodable)]
+#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
+#[derive(Eq, PartialEq, Hash)]
 pub struct BitSet<T> {
     domain_size: usize,
     words: SmallVec<[Word; 2]>,
@@ -491,10 +493,21 @@ impl<T: Idx> ChunkedBitSet<T> {
         match *chunk {
             Zeros(chunk_domain_size) => {
                 if chunk_domain_size > 1 {
-                    // We take some effort to avoid copying the words.
-                    let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
-                    // SAFETY: `words` can safely be all zeroes.
-                    let mut words = unsafe { words.assume_init() };
+                    #[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 = {
+                        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);
@@ -545,10 +558,21 @@ impl<T: Idx> ChunkedBitSet<T> {
             Zeros(_) => false,
             Ones(chunk_domain_size) => {
                 if chunk_domain_size > 1 {
-                    // We take some effort to avoid copying the words.
-                    let words = Rc::<[Word; CHUNK_WORDS]>::new_zeroed();
-                    // SAFETY: `words` can safely be all zeroes.
-                    let mut words = unsafe { words.assume_init() };
+                    #[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 = {
+                        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.
@@ -1564,7 +1588,8 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
 ///
 /// All operations that involve a row and/or column index will panic if the
 /// index exceeds the relevant bound.
-#[derive(Clone, Eq, PartialEq, Hash, Decodable, Encodable)]
+#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
+#[derive(Clone, Eq, PartialEq, Hash)]
 pub struct BitMatrix<R: Idx, C: Idx> {
     num_rows: usize,
     num_columns: usize,
@@ -1993,7 +2018,8 @@ impl std::fmt::Debug for FiniteBitSet<u32> {
 
 /// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
 /// representable by `T` are considered set.
-#[derive(Copy, Clone, Eq, PartialEq, Decodable, Encodable)]
+#[cfg_attr(feature = "nightly", derive(Decodable, Encodable))]
+#[derive(Copy, Clone, Eq, PartialEq)]
 pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T);
 
 impl<T: FiniteBitSetTy> FiniteBitSet<T> {
diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs
index c5602392c53..185e0c7d698 100644
--- a/compiler/rustc_index/src/lib.rs
+++ b/compiler/rustc_index/src/lib.rs
@@ -14,7 +14,6 @@
 )]
 #![cfg_attr(feature = "nightly", allow(internal_features))]
 
-#[cfg(feature = "nightly")]
 pub mod bit_set;
 #[cfg(feature = "nightly")]
 pub mod interval;