Skip to content

Commit

Permalink
make uninit_mask a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Nov 6, 2022
1 parent 6b7f6b9 commit edbbb10
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod init_mask;
mod provenance_map;
#[cfg(test)]
mod tests;

use std::borrow::Cow;
use std::fmt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl InitMask {
}

#[inline]
fn get(&self, i: Size) -> bool {
pub fn get(&self, i: Size) -> bool {
let (block, bit) = Self::bit_index(i);
(self.blocks[block] & (1 << bit)) != 0
}
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/allocation/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use super::*;

#[test]
fn uninit_mask() {
let mut mask = InitMask::new(Size::from_bytes(500), false);
assert!(!mask.get(Size::from_bytes(499)));
mask.set_range(alloc_range(Size::from_bytes(499), Size::from_bytes(1)), true);
assert!(mask.get(Size::from_bytes(499)));
mask.set_range((100..256).into(), true);
for i in 0..100 {
assert!(!mask.get(Size::from_bytes(i)), "{i} should not be set");
}
for i in 100..256 {
assert!(mask.get(Size::from_bytes(i)), "{i} should be set");
}
for i in 256..499 {
assert!(!mask.get(Size::from_bytes(i)), "{i} should not be set");
}
}
28 changes: 0 additions & 28 deletions src/test/ui-fulldeps/uninit_mask.rs

This file was deleted.

0 comments on commit edbbb10

Please sign in to comment.