Skip to content

Commit

Permalink
[all] Apply cargo fmt, and fix clippy lints
Browse files Browse the repository at this point in the history
- Remove unneeded return statements
- Implement Eq for types that derive PartialEq
- Use auto-deref
- Remove unused lifetime annotation
- Use From<bool> for integer conversion
  • Loading branch information
mingnus committed Nov 16, 2022
1 parent 1b5831e commit 71a4881
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 80 deletions.
52 changes: 21 additions & 31 deletions src/cache/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,53 +204,43 @@ where
b"superblock" => visitor.superblock_b(&parse_superblock(e)?),
b"mappings" => visitor.mappings_b(),
b"hints" => visitor.hints_b(),
_ => {
return Err(anyhow!(
"Parse error 1 at byte {}",
reader.buffer_position()
))
}
_ => Err(anyhow!(
"Parse error 1 at byte {}",
reader.buffer_position()
)),
},
Ok(Event::End(ref e)) => match e.name() {
b"superblock" => visitor.superblock_e(),
b"mappings" => visitor.mappings_e(),
b"hints" => visitor.hints_e(),
_ => {
return Err(anyhow!(
"Parse error 2 at byte {}",
reader.buffer_position()
))
}
_ => Err(anyhow!(
"Parse error 2 at byte {}",
reader.buffer_position()
)),
},
Ok(Event::Empty(ref e)) => match e.name() {
b"mapping" => visitor.mapping(&parse_mapping(e)?),
b"hint" => visitor.hint(&parse_hint(e)?),
_ => {
return Err(anyhow!(
"Parse error 3 at byte {}",
reader.buffer_position()
))
}
_ => Err(anyhow!(
"Parse error 3 at byte {}",
reader.buffer_position()
)),
},
Ok(Event::Text(_)) => Ok(Visit::Continue),
Ok(Event::Comment(_)) => Ok(Visit::Continue),
Ok(Event::Eof) => {
visitor.eof()?;
Ok(Visit::Stop)
}
Ok(_) => {
return Err(anyhow!(
"Parse error 4 at byte {}",
reader.buffer_position()
))
}
Err(e) => {
return Err(anyhow!(
"Parse error 5 at byte {}: {:?}",
reader.buffer_position(),
e
))
}
Ok(_) => Err(anyhow!(
"Parse error 4 at byte {}",
reader.buffer_position()
)),
Err(e) => Err(anyhow!(
"Parse error 5 at byte {}: {:?}",
reader.buffer_position(),
e
)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn checksum(buf: &[u8]) -> u32 {
crc32c(&buf[4..]) ^ 0xffffffff
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
#[allow(clippy::upper_case_acronyms)]
#[allow(non_camel_case_types)]
pub enum BT {
Expand Down
2 changes: 1 addition & 1 deletion src/copier/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;

pub type Block = u64;

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CopyOp {
pub src: Block,
pub dst: Block,
Expand Down
2 changes: 1 addition & 1 deletion src/copier/sync_copier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl<T: ReadBlocks + WriteBlocks + Send + 'static> Copier for SyncCopier<T> {

let mut stats = stats.write().unwrap();
stats.nr_copied += write_success.len() as u64;
progress.update(&*stats);
progress.update(&stats);
})
};

Expand Down
2 changes: 1 addition & 1 deletion src/era/invalidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct BitsetCollator {
composed_bits: Mutex<Vec<u64>>,
}

impl<'a> BitsetCollator {
impl BitsetCollator {
fn new(bitset: Vec<u64>) -> BitsetCollator {
BitsetCollator {
composed_bits: Mutex::new(bitset),
Expand Down
20 changes: 9 additions & 11 deletions src/era/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ where
b"superblock" => visitor.superblock_b(&parse_superblock(e)?),
b"writeset" => visitor.writeset_b(&parse_writeset(e)?),
b"era_array" => visitor.era_b(),
_ => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
_ => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
},
Ok(Event::End(ref e)) => match e.name() {
b"superblock" => visitor.superblock_e(),
b"writeset" => visitor.writeset_e(),
b"era_array" => visitor.era_e(),
_ => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
_ => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
},
Ok(Event::Empty(ref e)) => match e.name() {
b"bit" => {
Expand All @@ -278,22 +278,20 @@ where
}
b"marked" => visitor.writeset_blocks(&parse_writeset_blocks(e)?),
b"era" => visitor.era(&parse_era(e)?),
_ => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
_ => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
},
Ok(Event::Text(_)) => Ok(Visit::Continue),
Ok(Event::Comment(_)) => Ok(Visit::Continue),
Ok(Event::Eof) => {
visitor.eof()?;
Ok(Visit::Stop)
}
Ok(_) => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
Err(e) => {
return Err(anyhow!(
"Parse error at byte {}: {:?}",
reader.buffer_position(),
e
))
}
Ok(_) => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
Err(e) => Err(anyhow!(
"Parse error at byte {}: {:?}",
reader.buffer_position(),
e
)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/io_engine/spindle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl IoEngine for SpindleIoEngine {
let mut inner = self.inner.write().unwrap();
let mut bs = Vec::new();
for b in blocks {
bs.push(inner.write_(&*b));
bs.push(inner.write_(b));
}
Ok(bs)
}
Expand Down
2 changes: 1 addition & 1 deletion src/pack/delta_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-------------------------------------------------

#[derive(PartialEq, Debug, Clone)]
#[derive(PartialEq, Eq, Debug, Clone)]
pub enum Delta {
Base { n: u64 },
Const { count: u64 },
Expand Down
2 changes: 1 addition & 1 deletion src/pdata/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests;

const ARRAY_BLOCK_HEADER_SIZE: u32 = 24;

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct ArrayBlockHeader {
pub max_entries: u32,
pub nr_entries: u32,
Expand Down
2 changes: 1 addition & 1 deletion src/pdata/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use btree_error::*;

const NODE_HEADER_SIZE: usize = 32;

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NodeHeader {
pub block: u64,
pub is_leaf: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/pdata/btree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub struct NodeSummary {
shared: bool,
}

impl<'a, V: Pack + Unpack + Clone> NodeBuilder<V> {
impl<V: Pack + Unpack + Clone> NodeBuilder<V> {
/// Create a new NodeBuilder
pub fn new(nio: Box<dyn NodeIO<V>>, value_rc: Box<dyn RefCounter<V>>, shared: bool) -> Self {
NodeBuilder {
Expand Down
2 changes: 1 addition & 1 deletion src/pdata/btree_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::pack::vm;

//------------------------------------------

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct KeyRange {
pub start: Option<u64>,
pub end: Option<u64>, // This is the one-past-the-end value
Expand Down
2 changes: 1 addition & 1 deletion src/pdata/space_map/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl SpaceMap for RestrictedSpaceMap {
self.counts.set(b as usize, false);
}

Ok(if old { 1 } else { 0 })
Ok(u32::from(old))
}

fn inc(&mut self, begin: u64, len: u64) -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::thread::{self, JoinHandle};

//------------------------------------------

#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Eq)]
pub enum ReportOutcome {
Success,
NonFatal,
Expand Down Expand Up @@ -259,7 +259,7 @@ impl ProgressMonitor {

let n = processed() * 100 / total;

let _r = report.progress(n as u8);
report.progress(n as u8);
thread::sleep(interval);
}
});
Expand Down
20 changes: 9 additions & 11 deletions src/thin/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,34 +271,32 @@ where
b"superblock" => visitor.superblock_b(&parse_superblock(e)?),
b"device" => visitor.device_b(&parse_device(e)?),
b"def" => visitor.def_shared_b(&parse_def(e, "def")?),
_ => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
_ => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
},
Ok(Event::End(ref e)) => match e.name() {
b"superblock" => visitor.superblock_e(),
b"device" => visitor.device_e(),
b"def" => visitor.def_shared_e(),
_ => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
_ => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
},
Ok(Event::Empty(ref e)) => match e.name() {
b"single_mapping" => visitor.map(&parse_single_map(e)?),
b"range_mapping" => visitor.map(&parse_range_map(e)?),
b"ref" => visitor.ref_shared(&parse_def(e, "ref")?),
_ => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
_ => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
},
Ok(Event::Text(_)) => Ok(Visit::Continue),
Ok(Event::Comment(_)) => Ok(Visit::Continue),
Ok(Event::Eof) => {
visitor.eof()?;
Ok(Visit::Stop)
}
Ok(_) => return Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
Err(e) => {
return Err(anyhow!(
"Parse error at byte {}: {:?}",
reader.buffer_position(),
e
))
}
Ok(_) => Err(anyhow!("Parse error at byte {}", reader.buffer_position())),
Err(e) => Err(anyhow!(
"Parse error at byte {}: {:?}",
reader.buffer_position(),
e
)),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;

//------------------------------------------

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Units {
Byte,
Sector,
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn to_units(bytes: u64, unit: Units) -> f64 {

//------------------------------------------

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct StorageSize {
multiple: u64,
unit: Units,
Expand Down Expand Up @@ -210,7 +210,7 @@ impl FromStr for StorageSize {

// default to sectors
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (multiple, unit) = if let Some(pos) = s.find(|c: char| !c.is_digit(10)) {
let (multiple, unit) = if let Some(pos) = s.find(|c: char| !c.is_ascii_digit()) {
(s[..pos].parse::<u64>()?, s[pos..].parse::<Units>()?)
} else {
(s.parse::<u64>()?, Units::Sector)
Expand Down
2 changes: 1 addition & 1 deletion tests/thin_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<'a> InputProgram<'a> for ThinCheck {
}
}

impl<'a> MetadataReader<'_> for ThinCheck {}
impl MetadataReader<'_> for ThinCheck {}

//------------------------------------------

Expand Down
14 changes: 4 additions & 10 deletions tests/thin_shrink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,16 @@ fn create_data_file(data_path: &Path, xml_path: &Path) -> Result<()> {
}

fn stamp(xml_path: &Path, data_path: &Path, seed: u64) -> Result<()> {
let mut data = OpenOptions::new()
.read(false)
.write(true)
.open(&data_path)?;
let xml = OpenOptions::new().read(true).write(false).open(&xml_path)?;
let mut data = OpenOptions::new().read(false).write(true).open(data_path)?;
let xml = OpenOptions::new().read(true).write(false).open(xml_path)?;

let mut stamper = Stamper::new(&mut data, seed);
thin_visit(xml, &mut stamper)
}

fn verify(xml_path: &Path, data_path: &Path, seed: u64) -> Result<()> {
let mut data = OpenOptions::new()
.read(true)
.write(false)
.open(&data_path)?;
let xml = OpenOptions::new().read(true).write(false).open(&xml_path)?;
let mut data = OpenOptions::new().read(true).write(false).open(data_path)?;
let xml = OpenOptions::new().read(true).write(false).open(xml_path)?;
let mut verifier = Verifier::new(&mut data, seed);
thin_visit(xml, &mut verifier)
}
Expand Down

0 comments on commit 71a4881

Please sign in to comment.