File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
compiler/rustc_index/src/bit_set Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ impl<T> DenseBitSet<T> {
81
81
82
82
/// The tag for the `empty_unallocated` variant. The two most significant bits are
83
83
/// `[0, 1]`.
84
- const EMPTY_UNALLOCATED_TAG_BITS : usize = 0b01 << ( WORD_BITS - 2 ) ;
84
+ const EMPTY_UNALLOCATED_TAG_BITS : usize = 0b01 << ( usize :: BITS - 2 ) ;
85
85
86
86
/// Create a new empty bit set with a given domain_size.
87
87
///
@@ -115,7 +115,9 @@ impl<T> DenseBitSet<T> {
115
115
* word = Word :: MAX ;
116
116
}
117
117
// Remove excessive bits on the last word.
118
- * words. last_mut ( ) . unwrap ( ) >>= WORD_BITS - domain_size % WORD_BITS ;
118
+ // Trust me: this mask is correct.
119
+ let last_word_mask = Word :: MAX . wrapping_shr ( domain_size. wrapping_neg ( ) as u32 ) ;
120
+ * words. last_mut ( ) . unwrap ( ) &= last_word_mask;
119
121
Self { on_heap : ManuallyDrop :: new ( on_heap) }
120
122
}
121
123
}
@@ -135,8 +137,8 @@ impl<T> DenseBitSet<T> {
135
137
// safe to assume `self.inline`, or `self.on_heap`.
136
138
#[ inline( always) ]
137
139
pub const fn is_empty_unallocated ( & self ) -> bool {
138
- ( unsafe { self . empty_unallocated } ) >> usize:: BITS as u32 - 2
139
- == Self :: EMPTY_UNALLOCATED_TAG_BITS >> usize :: BITS as u32 - 2
140
+ const MASK : usize = usize :: MAX << usize:: BITS - 2 ;
141
+ ( unsafe { self . empty_unallocated } & MASK ) == Self :: EMPTY_UNALLOCATED_TAG_BITS
140
142
}
141
143
142
144
/// Check if `self` is `empty_unallocated` and if so return the number of words required to
You can’t perform that action at this time.
0 commit comments