diff --git a/src/compiler/rust/bitset.rs b/src/compiler/rust/bitset.rs index 9fc25c5ef77..204912052b5 100644 --- a/src/compiler/rust/bitset.rs +++ b/src/compiler/rust/bitset.rs @@ -181,10 +181,13 @@ impl BitSet { pub fn remove(&mut self, key: K) -> bool { let idx = BitIndex::from(key); - self.reserve_words(idx.word + 1); - let exists = self.words[idx.word] & (1_u32 << idx.bit) != 0; - self.words[idx.word] &= !(1_u32 << idx.bit); - exists + if idx.word < self.words.len() { + let exists = self.words[idx.word] & (1_u32 << idx.bit) != 0; + self.words[idx.word] &= !(1_u32 << idx.bit); + exists + } else { + false + } } }