Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clippy checks to Travis-CI. #23

Merged
merged 6 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ branches:
- trying.tmp
before_script:
- rustup component add rustfmt
- rustup component add clippy
script:
- cargo fmt -- --check
# Ideally we would run CLippy on all targets, but benchmarks depend on an
# unstable feature and only work on nightly.
#- cargo clippy --all-targets -- -D warnings
- cargo clippy -- -D warnings
- cargo clippy --tests -- -D warnings
- cargo build --verbose
- cargo test --verbose
22 changes: 8 additions & 14 deletions src/decode/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ where
rangecoder: &mut rangecoder::RangeDecoder<'a, R>,
) -> error::Result<()> {
loop {
if let Some(_) = self.unpacked_size {
if rangecoder.is_finished_ok()? {
break;
}
if self.unpacked_size.is_some() && rangecoder.is_finished_ok()? {
break;
}

let pos_state = self.output.len() & ((1 << self.pb) - 1);
Expand All @@ -244,12 +242,10 @@ where

self.state = if self.state < 4 {
0
} else if self.state < 10 {
self.state - 3
} else {
if self.state < 10 {
self.state - 3
} else {
self.state - 6
}
self.state - 6
};
continue;
}
Expand All @@ -275,12 +271,10 @@ where
let idx: usize;
if !rangecoder.decode_bit(&mut self.is_rep_g1[self.state])? {
idx = 1;
} else if !rangecoder.decode_bit(&mut self.is_rep_g2[self.state])? {
idx = 2;
} else {
if !rangecoder.decode_bit(&mut self.is_rep_g2[self.state])? {
idx = 2;
} else {
idx = 3;
}
idx = 3;
}
// Update LRU
let dist = self.rep[idx];
Expand Down
10 changes: 4 additions & 6 deletions src/decode/rangecoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
#[inline]
fn normalize(&mut self) -> io::Result<()> {
trace!(" {{ range: {:08x}, code: {:08x} }}", self.range, self.code);
if self.range < 0x1000000 {
if self.range < 0x0100_0000 {
self.range <<= 8;
self.code = (self.code << 8) ^ (self.stream.read_u8()? as u32);

Expand Down Expand Up @@ -171,12 +171,10 @@ impl LenDecoder {
) -> io::Result<usize> {
if !rangecoder.decode_bit(&mut self.choice)? {
Ok(self.low_coder[pos_state].parse(rangecoder)? as usize)
} else if !rangecoder.decode_bit(&mut self.choice2)? {
Ok(self.mid_coder[pos_state].parse(rangecoder)? as usize + 8)
} else {
if !rangecoder.decode_bit(&mut self.choice2)? {
Ok(self.mid_coder[pos_state].parse(rangecoder)? as usize + 8)
} else {
Ok(self.high_coder.parse(rangecoder)? as usize + 16)
}
Ok(self.high_coder.parse(rangecoder)? as usize + 16)
}
}
}
2 changes: 1 addition & 1 deletion src/decode/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn read_tag<R: io::BufRead>(input: &mut R, tag: &[u8]) -> io::Result<bool> {

pub fn is_eof<R: io::BufRead>(input: &mut R) -> io::Result<bool> {
let buf = input.fill_buf()?;
Ok(buf.len() == 0)
Ok(buf.is_empty())
}

pub fn discard<R: io::Read>(input: &mut R, n: usize) -> io::Result<()> {
Expand Down
30 changes: 15 additions & 15 deletions src/decode/xz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ where
}

if !util::is_eof(input)? {
return Err(error::Error::XZError(format!(
"Unexpected data after last XZ block"
)));
return Err(error::Error::XZError(
"Unexpected data after last XZ block".to_string(),
));
}
Ok(())
}
Expand Down Expand Up @@ -193,9 +193,9 @@ where
for _ in 0..padding_size {
let byte = digested.read_u8()?;
if byte != 0 {
return Err(error::Error::XZError(format!(
"Invalid index padding, must be null bytes"
)));
return Err(error::Error::XZError(
"Invalid index padding, must be null bytes".to_string(),
));
}
}
}
Expand Down Expand Up @@ -314,9 +314,9 @@ where
for _ in 0..padding_size {
let byte = count_input.read_u8()?;
if byte != 0 {
return Err(error::Error::XZError(format!(
"Invalid block padding, must be null bytes"
)));
return Err(error::Error::XZError(
"Invalid block padding, must be null bytes".to_string(),
));
}
}
check_checksum(count_input, tmpbuf.as_slice(), check_method)?;
Expand Down Expand Up @@ -463,9 +463,9 @@ where
}

if !util::flush_zero_padding(input)? {
return Err(error::Error::XZError(format!(
"Invalid block header padding, must be null bytes"
)));
return Err(error::Error::XZError(
"Invalid block header padding, must be null bytes".to_string(),
));
}

Ok(BlockHeader {
Expand All @@ -488,7 +488,7 @@ where
}
}

Err(error::Error::XZError(format!(
"Invalid multi-byte encoding"
)))
Err(error::Error::XZError(
"Invalid multi-byte encoding".to_string(),
))
}
2 changes: 1 addition & 1 deletion src/encode/dumbencoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ where
W: io::Write,
{
pub fn from_stream(stream: &'a mut W, options: &Options) -> io::Result<Self> {
let dict_size = 0x800000;
let dict_size = 0x0080_0000;

// Properties
let props = (LC + 9 * (LP + 5 * PB)) as u8;
Expand Down
2 changes: 1 addition & 1 deletion src/encode/rangecoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
}

fn normalize(&mut self) -> io::Result<()> {
while self.range < 0x1000000 {
while self.range < 0x0100_0000 {
debug!(
"+ {{ range: {:08x}, low: {:010x}, cache: {:02x}, {} }}",
self.range, self.low, self.cache, self.cachesz
Expand Down
2 changes: 1 addition & 1 deletion tests/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn decompress_short_header() {
assert_eq!(
format!(
"{:?}",
lzma_rs::lzma_decompress(&mut "".as_bytes(), &mut decomp).unwrap_err()
lzma_rs::lzma_decompress(&mut (b"" as &[u8]), &mut decomp).unwrap_err()
),
String::from("LZMAError(\"LZMA header too short: failed to fill whole buffer\")")
)
Expand Down