@@ -9,6 +9,7 @@ use std::slice;
99use arrayvec:: ArrayVec ;
1010use smallvec:: { smallvec, SmallVec } ;
1111
12+ #[ cfg( feature = "nightly" ) ]
1213use rustc_macros:: { Decodable , Encodable } ;
1314
1415use crate :: { Idx , IndexVec } ;
@@ -111,7 +112,8 @@ macro_rules! bit_relations_inherent_impls {
111112/// to or greater than the domain size. All operations that involve two bitsets
112113/// will panic if the bitsets have differing domain sizes.
113114///
114- #[ derive( Eq , PartialEq , Hash , Decodable , Encodable ) ]
115+ #[ cfg_attr( feature = "nightly" , derive( Decodable , Encodable ) ) ]
116+ #[ derive( Eq , PartialEq , Hash ) ]
115117pub struct BitSet < T > {
116118 domain_size : usize ,
117119 words : SmallVec < [ Word ; 2 ] > ,
@@ -491,10 +493,21 @@ impl<T: Idx> ChunkedBitSet<T> {
491493 match * chunk {
492494 Zeros ( chunk_domain_size) => {
493495 if chunk_domain_size > 1 {
494- // We take some effort to avoid copying the words.
495- let words = Rc :: < [ Word ; CHUNK_WORDS ] > :: new_zeroed ( ) ;
496- // SAFETY: `words` can safely be all zeroes.
497- let mut words = unsafe { words. assume_init ( ) } ;
496+ #[ cfg( feature = "nightly" ) ]
497+ let mut words = {
498+ // We take some effort to avoid copying the words.
499+ let words = Rc :: < [ Word ; CHUNK_WORDS ] > :: new_zeroed ( ) ;
500+ // SAFETY: `words` can safely be all zeroes.
501+ unsafe { words. assume_init ( ) }
502+ } ;
503+ #[ cfg( not( feature = "nightly" ) ) ]
504+ let mut words = {
505+ let words = mem:: MaybeUninit :: < [ Word ; CHUNK_WORDS ] > :: zeroed ( ) ;
506+ // SAFETY: `words` can safely be all zeroes.
507+ let words = unsafe { words. assume_init ( ) } ;
508+ // Unfortunate possibly-large copy
509+ Rc :: new ( words)
510+ } ;
498511 let words_ref = Rc :: get_mut ( & mut words) . unwrap ( ) ;
499512
500513 let ( word_index, mask) = chunk_word_index_and_mask ( elem) ;
@@ -545,10 +558,21 @@ impl<T: Idx> ChunkedBitSet<T> {
545558 Zeros ( _) => false ,
546559 Ones ( chunk_domain_size) => {
547560 if chunk_domain_size > 1 {
548- // We take some effort to avoid copying the words.
549- let words = Rc :: < [ Word ; CHUNK_WORDS ] > :: new_zeroed ( ) ;
550- // SAFETY: `words` can safely be all zeroes.
551- let mut words = unsafe { words. assume_init ( ) } ;
561+ #[ cfg( feature = "nightly" ) ]
562+ let mut words = {
563+ // We take some effort to avoid copying the words.
564+ let words = Rc :: < [ Word ; CHUNK_WORDS ] > :: new_zeroed ( ) ;
565+ // SAFETY: `words` can safely be all zeroes.
566+ unsafe { words. assume_init ( ) }
567+ } ;
568+ #[ cfg( not( feature = "nightly" ) ) ]
569+ let mut words = {
570+ let words = mem:: MaybeUninit :: < [ Word ; CHUNK_WORDS ] > :: zeroed ( ) ;
571+ // SAFETY: `words` can safely be all zeroes.
572+ let words = unsafe { words. assume_init ( ) } ;
573+ // Unfortunate possibly-large copy
574+ Rc :: new ( words)
575+ } ;
552576 let words_ref = Rc :: get_mut ( & mut words) . unwrap ( ) ;
553577
554578 // Set only the bits in use.
@@ -1564,7 +1588,8 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
15641588///
15651589/// All operations that involve a row and/or column index will panic if the
15661590/// index exceeds the relevant bound.
1567- #[ derive( Clone , Eq , PartialEq , Hash , Decodable , Encodable ) ]
1591+ #[ cfg_attr( feature = "nightly" , derive( Decodable , Encodable ) ) ]
1592+ #[ derive( Clone , Eq , PartialEq , Hash ) ]
15681593pub struct BitMatrix < R : Idx , C : Idx > {
15691594 num_rows : usize ,
15701595 num_columns : usize ,
@@ -1993,7 +2018,8 @@ impl std::fmt::Debug for FiniteBitSet<u32> {
19932018
19942019/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
19952020/// representable by `T` are considered set.
1996- #[ derive( Copy , Clone , Eq , PartialEq , Decodable , Encodable ) ]
2021+ #[ cfg_attr( feature = "nightly" , derive( Decodable , Encodable ) ) ]
2022+ #[ derive( Copy , Clone , Eq , PartialEq ) ]
19972023pub struct FiniteBitSet < T : FiniteBitSetTy > ( pub T ) ;
19982024
19992025impl < T : FiniteBitSetTy > FiniteBitSet < T > {
0 commit comments