@@ -9,6 +9,7 @@ use std::slice;
9
9
use arrayvec:: ArrayVec ;
10
10
use smallvec:: { smallvec, SmallVec } ;
11
11
12
+ #[ cfg( feature = "nightly" ) ]
12
13
use rustc_macros:: { Decodable , Encodable } ;
13
14
14
15
use crate :: { Idx , IndexVec } ;
@@ -111,7 +112,8 @@ macro_rules! bit_relations_inherent_impls {
111
112
/// to or greater than the domain size. All operations that involve two bitsets
112
113
/// will panic if the bitsets have differing domain sizes.
113
114
///
114
- #[ derive( Eq , PartialEq , Hash , Decodable , Encodable ) ]
115
+ #[ cfg_attr( feature = "nightly" , derive( Decodable , Encodable ) ) ]
116
+ #[ derive( Eq , PartialEq , Hash ) ]
115
117
pub struct BitSet < T > {
116
118
domain_size : usize ,
117
119
words : SmallVec < [ Word ; 2 ] > ,
@@ -491,10 +493,21 @@ impl<T: Idx> ChunkedBitSet<T> {
491
493
match * chunk {
492
494
Zeros ( chunk_domain_size) => {
493
495
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
+ } ;
498
511
let words_ref = Rc :: get_mut ( & mut words) . unwrap ( ) ;
499
512
500
513
let ( word_index, mask) = chunk_word_index_and_mask ( elem) ;
@@ -545,10 +558,21 @@ impl<T: Idx> ChunkedBitSet<T> {
545
558
Zeros ( _) => false ,
546
559
Ones ( chunk_domain_size) => {
547
560
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
+ } ;
552
576
let words_ref = Rc :: get_mut ( & mut words) . unwrap ( ) ;
553
577
554
578
// Set only the bits in use.
@@ -1564,7 +1588,8 @@ impl<T: Idx> From<BitSet<T>> for GrowableBitSet<T> {
1564
1588
///
1565
1589
/// All operations that involve a row and/or column index will panic if the
1566
1590
/// 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 ) ]
1568
1593
pub struct BitMatrix < R : Idx , C : Idx > {
1569
1594
num_rows : usize ,
1570
1595
num_columns : usize ,
@@ -1993,7 +2018,8 @@ impl std::fmt::Debug for FiniteBitSet<u32> {
1993
2018
1994
2019
/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
1995
2020
/// 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 ) ]
1997
2023
pub struct FiniteBitSet < T : FiniteBitSetTy > ( pub T ) ;
1998
2024
1999
2025
impl < T : FiniteBitSetTy > FiniteBitSet < T > {
0 commit comments