diff --git a/src/sys/block_group.rs b/src/sys/block_group.rs index 14bff9b..70c6ab2 100644 --- a/src/sys/block_group.rs +++ b/src/sys/block_group.rs @@ -1,11 +1,4 @@ -#[cfg(test)] -use std::mem; -#[cfg(test)] -use std::slice; - -#[cfg(not(test))] use core::mem; -#[cfg(not(test))] use core::slice; use error::Error; @@ -52,11 +45,9 @@ impl BlockGroupDescriptor { return Err(Error::OutOfBounds(end)); } - let ptr = unsafe { - haystack.as_mut_ptr().offset(offset as isize) - as *mut BlockGroupDescriptor - }; - let slice = unsafe { slice::from_raw_parts_mut(ptr, count) }; + let ptr = haystack.as_mut_ptr().offset(offset as isize) + as *mut BlockGroupDescriptor; + let slice = slice::from_raw_parts_mut(ptr, count); Ok(slice) } } @@ -70,8 +61,9 @@ mod tests { let mut buffer = vec![0_u8; 4096]; let addr = &buffer[2048] as *const _ as usize; // magic - let table = - BlockGroupDescriptor::find_descriptor_table(&mut buffer, 0, 0); + let table = unsafe { + BlockGroupDescriptor::find_descriptor_table(&mut buffer, 0, 0) + }; assert!( table.is_ok(), "Err({:?})", diff --git a/src/sys/superblock.rs b/src/sys/superblock.rs index 1a26b9b..e89a66c 100644 --- a/src/sys/superblock.rs +++ b/src/sys/superblock.rs @@ -1,7 +1,3 @@ -#[cfg(test)] -use std::mem; - -#[cfg(not(test))] use core::mem; use error::Error; @@ -157,7 +153,7 @@ impl Superblock { return Err(Error::OutOfBounds(end)); } - let superblock: &mut Superblock = unsafe { + let superblock: &mut Superblock = { let ptr = haystack.as_mut_ptr().offset(offset as isize) as *mut Superblock; ptr.as_mut().unwrap() @@ -251,7 +247,7 @@ mod tests { // magic buffer[1024 + 56] = EXT2_MAGIC as u8; buffer[1024 + 57] = (EXT2_MAGIC >> 8) as u8; - let superblock = Superblock::find(&mut buffer, 0); + let superblock = unsafe { Superblock::find(&mut buffer, 0) }; assert!( superblock.is_ok(), "Err({:?})",