[functional-tests] Fix clippy warnings

This commit is contained in:
Joe Thornber
2020-08-07 15:41:21 +01:00
parent fa4ea3e2d9
commit 8f76371bb2
9 changed files with 46 additions and 58 deletions

View File

@ -190,7 +190,7 @@ impl IoEngine for AsyncIoEngine {
let count = blocks.len();
let fd = types::Target::Fd(inner.input.as_raw_fd());
for b in blocks.into_iter() {
for b in blocks.iter_mut() {
let read_e = opcode::Read::new(fd, b.data, BLOCK_SIZE as u32)
.offset(b.loc as i64 * BLOCK_SIZE as i64);

View File

@ -416,7 +416,7 @@ mod tests {
}
}
fn check_u64s_match(ns: &Vec<u64>, bytes: &[u8]) -> bool {
fn check_u64s_match(ns: &[u64], bytes: &[u8]) -> bool {
let mut packed = Vec::with_capacity(ns.len() * 8);
let mut w = Cursor::new(&mut packed);
for n in ns {
@ -425,7 +425,7 @@ mod tests {
packed == bytes
}
fn check_pack_u64s(ns: &Vec<u64>) -> bool {
fn check_pack_u64s(ns: &[u64]) -> bool {
println!("packing {:?}", &ns);
let mut bs = Vec::with_capacity(4096);
@ -461,7 +461,7 @@ mod tests {
check_pack_u64s(&ns)
}
fn check_pack_shifted_u64s(ns: &Vec<(u64, u64)>) -> bool {
fn check_pack_shifted_u64s(ns: &[(u64, u64)]) -> bool {
let shifted: Vec<u64> = ns
.iter()
.map(|(h, l)| (h << 24) | (l & ((1 << 24) - 1)))

View File

@ -31,7 +31,6 @@ const NODE_HEADER_SIZE: usize = 32;
pub struct NodeHeader {
is_leaf: bool,
block: u64,
nr_entries: u32,
max_entries: u32,
value_size: u32,
@ -44,7 +43,7 @@ const LEAF_NODE: u32 = 2;
pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> {
let (i, _csum) = le_u32(data)?;
let (i, flags) = le_u32(i)?;
let (i, block) = le_u64(i)?;
let (i, _block) = le_u64(i)?;
let (i, nr_entries) = le_u32(i)?;
let (i, max_entries) = le_u32(i)?;
let (i, value_size) = le_u32(i)?;
@ -54,7 +53,6 @@ pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> {
i,
NodeHeader {
is_leaf: flags == LEAF_NODE,
block,
nr_entries,
max_entries,
value_size,
@ -111,18 +109,18 @@ pub fn unpack_node<V: Unpack>(
}
if header.nr_entries > header.max_entries {
return node_err(format!("nr_entries > max_entries"));
return node_err("nr_entries > max_entries".to_string());
}
if !ignore_non_fatal {
if header.max_entries % 3 != 0 {
return node_err(format!("max_entries is not divisible by 3"));
return node_err("max_entries is not divisible by 3".to_string());
}
if !is_root {
let min = header.max_entries / 3;
if header.nr_entries < min {
return node_err(format!("too few entries"));
return node_err("too few entries".to_string());
}
}
}
@ -133,7 +131,7 @@ pub fn unpack_node<V: Unpack>(
for k in &keys {
if let Some(l) = last {
if k <= l {
return node_err(format!("keys out of order"));
return node_err("keys out of order".to_string());
}
}
@ -186,7 +184,7 @@ impl Unpack for u32 {
//------------------------------------------
pub trait NodeVisitor<V: Unpack> {
fn visit<'a>(&mut self, w: &BTreeWalker, b: &Block, node: &Node<V>) -> Result<()>;
fn visit(&mut self, w: &BTreeWalker, b: &Block, node: &Node<V>) -> Result<()>;
}
#[derive(Clone)]
@ -200,7 +198,7 @@ impl BTreeWalker {
pub fn new(engine: Arc<AsyncIoEngine>, ignore_non_fatal: bool) -> BTreeWalker {
let nr_blocks = engine.get_nr_blocks() as usize;
let r: BTreeWalker = BTreeWalker {
engine: engine,
engine,
seen: Arc::new(Mutex::new(FixedBitSet::with_capacity(nr_blocks))),
ignore_non_fatal,
};
@ -224,7 +222,7 @@ impl BTreeWalker {
}
}
fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &Vec<u64>) -> Result<()>
fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &[u64]) -> Result<()>
where
NV: NodeVisitor<V>,
V: Unpack,

View File

@ -116,7 +116,7 @@ impl Unpack for Bitmap {
for _b in 0..32 {
let val = word & 0x3;
word = word >> 2;
word >>= 2;
if val < 3 {
entries.push(BitmapEntry::Small(val as u8));

View File

@ -148,12 +148,12 @@ impl NodeVisitor<IndexEntry> for IndexVisitor {
fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<IndexEntry>) -> Result<()> {
if let Node::Leaf {
header: _h,
keys,
keys: _k,
values,
} = node {
for n in 0..keys.len() {
for v in values {
// FIXME: check keys are in incremental order
let v = values[n].clone();
let v = v.clone();
self.entries.push(v);
}
}

View File

@ -359,13 +359,7 @@ where
reader.trim_text(true);
let mut buf = Vec::new();
loop {
match handle_event(&mut reader, &mut buf, visitor)? {
Visit::Continue => {}
Visit::Stop => break,
}
}
while let Visit::Continue = handle_event(&mut reader, &mut buf, visitor)? {}
Ok(())
}
@ -380,7 +374,7 @@ impl MetadataVisitor for SBVisitor {
self.superblock = Some(sb.clone());
Ok(Visit::Stop)
}
fn superblock_e(&mut self) -> Result<Visit> {
Ok(Visit::Continue)
}
@ -405,7 +399,7 @@ pub fn read_superblock<R>(input: R) -> Result<Superblock>
where
R: Read,
{
let mut v = SBVisitor {superblock: None};
let mut v = SBVisitor { superblock: None };
read(input, &mut v)?;
Ok(v.superblock.unwrap())
}