Clippy automatic fixes

This commit is contained in:
Oscar Gustafsson 2023-09-26 13:23:08 +02:00
parent 5758e77371
commit 0795465c36
8 changed files with 41 additions and 41 deletions

View file

@ -6,15 +6,13 @@ use super::super::reader::{next_word, WordReader};
use super::types::ParseResult;
pub(super) fn digit(chr: u8) -> bool {
let zero = b'0' as u8;
let nine = b'9' as u8;
let zero = b'0';
let nine = b'9';
let between_zero_and_nine = (chr >= zero) && (nine >= chr);
return between_zero_and_nine;
(chr >= zero) && (nine >= chr)
}
pub(super) fn take_until<'a>(word: &'a str, pattern: u8) -> ParseResult<'a> {
pub(super) fn take_until(word: &str, pattern: u8) -> ParseResult<'_> {
let mut new_start = 0;
for chr in word.as_bytes() {
@ -25,13 +23,13 @@ pub(super) fn take_until<'a>(word: &'a str, pattern: u8) -> ParseResult<'a> {
}
}
return ParseResult {
ParseResult {
matched: &word[0..new_start],
residual: &word[new_start..],
};
}
}
pub(super) fn take_while<'a>(word: &'a str, cond: fn(u8) -> bool) -> ParseResult<'a> {
pub(super) fn take_while(word: &str, cond: fn(u8) -> bool) -> ParseResult<'_> {
let mut new_start = 0;
for chr in word.as_bytes() {
@ -42,10 +40,10 @@ pub(super) fn take_while<'a>(word: &'a str, cond: fn(u8) -> bool) -> ParseResult
}
}
return ParseResult {
ParseResult {
matched: &word[0..new_start],
residual: &word[new_start..],
};
}
}
pub(super) fn tag<'a>(word: &'a str, pattern: &'a str) -> ParseResult<'a> {
@ -63,10 +61,10 @@ pub(super) fn tag<'a>(word: &'a str, pattern: &'a str) -> ParseResult<'a> {
new_start += 1;
}
return ParseResult {
ParseResult {
matched: &word[0..new_start],
residual: &word[new_start..],
};
}
}
pub(super) fn ident<R: std::io::Read>(
@ -77,9 +75,9 @@ pub(super) fn ident<R: std::io::Read>(
let (word, cursor) = next_word!(word_reader)?;
if word == keyword {
return Ok(());
Ok(())
} else {
let err = format!("found keyword `{word}` but expected `{keyword}` on {cursor:?}");
return Err(err);
Err(err)
}
}

View file

@ -11,9 +11,9 @@ use super::super::signal::{LsbIdxOfTmstmpValOnTmln, SignalEnum};
use super::super::types::{SignalIdx, VCD};
use super::super::utilities::{binary_str_to_vec_u8, BinaryParserErrTypes};
pub(super) fn parse_events<'a, R: std::io::Read>(
pub(super) fn parse_events<R: std::io::Read>(
word_reader: &mut WordReader<R>,
vcd: &'a mut VCD,
vcd: &mut VCD,
signal_map: &mut HashMap<String, SignalIdx>,
) -> Result<(), String> {
let mut curr_tmstmp_lsb_idx = 0u32;

View file

@ -159,7 +159,7 @@ pub(super) fn parse_version<R: std::io::Read>(
return Ok(Version(version));
} else {
version.push_str(word);
version.push_str(" ");
version.push(' ');
}
}
}
@ -179,7 +179,7 @@ pub(super) fn parse_timescale<R: std::io::Read>(
.map_err(|e| format!("Error near {}:{}. {e}", file!(), line!()))?;
let timescale = {
if residual == "" {
if residual.is_empty() {
let (word, _) = next_word!(word_reader)?;
let unit = match word {
"fs" => Ok(Timescale::Fs),
@ -219,7 +219,7 @@ pub(super) fn parse_timescale<R: std::io::Read>(
let (word, _) = next_word!(word_reader)?;
tag(word, "$end").assert_match()?;
return Ok(timescale);
Ok(timescale)
}
pub(super) fn parse_metadata<R: std::io::Read>(
@ -331,5 +331,5 @@ pub(super) fn parse_metadata<R: std::io::Read>(
_ => {}
}
}
return Ok(metadata);
Ok(metadata)
}

View file

@ -14,10 +14,10 @@ use super::super::types::{Scope, ScopeIdx, SignalIdx, VCD};
use super::combinator_atoms::{ident, tag};
use super::types::ParseResult;
pub(super) fn parse_var<'a, R: std::io::Read>(
pub(super) fn parse_var<R: std::io::Read>(
word_reader: &mut WordReader<R>,
parent_scope_idx: ScopeIdx,
vcd: &'a mut VCD,
vcd: &mut VCD,
signal_map: &mut HashMap<String, SignalIdx>,
path: &Vec<String>,
) -> Result<(), String> {
@ -70,7 +70,9 @@ pub(super) fn parse_var<'a, R: std::io::Read>(
| SigType::Wire
| SigType::Tri1
| SigType::Time => {
let num_bits = word.parse::<usize>().expect(parse_err.as_str());
let num_bits = word
.parse::<usize>()
.unwrap_or_else(|_| panic!("{}", parse_err));
let num_bits = u16::try_from(num_bits).map_err(|_| {
format!(
"Error near {}:{} while parsing vcd file at {cursor:?}. \
@ -162,9 +164,9 @@ pub(super) fn parse_var<'a, R: std::io::Read>(
/// Sometimes, variables can be listed outside of scopes.
/// We call these orphaned vars.
fn parse_orphaned_vars<'a, R: std::io::Read>(
fn parse_orphaned_vars<R: std::io::Read>(
word_reader: &mut WordReader<R>,
vcd: &'a mut VCD,
vcd: &mut VCD,
signal_map: &mut HashMap<String, SignalIdx>,
) -> Result<(), String> {
// create scope for unscoped signals if such a scope does not
@ -225,10 +227,10 @@ fn parse_orphaned_vars<'a, R: std::io::Read>(
Ok(())
}
fn parse_scopes_inner<'a, R: std::io::Read>(
fn parse_scopes_inner<R: std::io::Read>(
word_reader: &mut WordReader<R>,
parent_scope_idx: Option<ScopeIdx>,
vcd: &'a mut VCD,
vcd: &mut VCD,
signal_map: &mut HashMap<String, SignalIdx>,
path: &Vec<String>,
) -> Result<(), String> {
@ -341,9 +343,9 @@ fn parse_scopes_inner<'a, R: std::io::Read>(
Ok(())
}
pub(super) fn parse_scopes<'a, R: std::io::Read>(
pub(super) fn parse_scopes<R: std::io::Read>(
word_reader: &mut WordReader<R>,
vcd: &'a mut VCD,
vcd: &mut VCD,
signal_map: &mut HashMap<String, SignalIdx>,
) -> Result<(), String> {
// get the current word

View file

@ -10,18 +10,18 @@ pub(super) struct ParseResult<'a> {
impl<'a> ParseResult<'a> {
pub(super) fn assert_match(&self) -> Result<&str, String> {
if self.matched == "" {
return Err("no match".to_string());
if self.matched.is_empty() {
Err("no match".to_string())
} else {
return Ok(self.matched);
Ok(self.matched)
}
}
pub(super) fn assert_residual(&self) -> Result<&str, String> {
if self.residual == "" {
return Err("no residual".to_string());
if self.residual.is_empty() {
Err("no residual".to_string())
} else {
return Ok(self.residual);
Ok(self.residual)
}
}
}

View file

@ -319,7 +319,7 @@ impl SignalEnum {
fn bits_required(&self) -> Option<u16> {
match self {
SignalEnum::Data { num_bits, .. } => num_bits.clone(),
SignalEnum::Data { num_bits, .. } => *num_bits,
// TODO: Follow aliases?
SignalEnum::Alias { .. } => None,
}

View file

@ -85,7 +85,7 @@ impl VCD {
let scope = &self.all_scopes[idx];
&scope.name
}
pub fn signal_from_signal_idx<'a>(&'a self, idx: SignalIdx) -> Signal<'a> {
pub fn signal_from_signal_idx(&self, idx: SignalIdx) -> Signal<'_> {
let SignalIdx(idx) = idx;
let signal_enum = &self.all_signals[idx];
return Signal(signal_enum);

View file

@ -38,7 +38,7 @@ fn base2_str_to_byte(word: &[u8]) -> Result<u8, BinaryParserErrTypes> {
for (idx, chr) in word.iter().rev().enumerate() {
match chr {
b'1' => val = bit_lut[idx] | val,
b'1' => val |= bit_lut[idx],
b'0' => {}
b'x' | b'X' => return Err(BinaryParserErrTypes::XValue),
b'z' | b'Z' => return Err(BinaryParserErrTypes::ZValue),
@ -73,13 +73,13 @@ pub(super) fn binary_str_to_vec_u8(binary_str: &str) -> Result<Vec<u8>, BinaryPa
if head_idx < 8 {
head_idx = 0
} else {
head_idx = head_idx - 8;
head_idx -= 8;
}
if tail_idx < 8 {
tail_idx = 0
} else {
tail_idx = tail_idx - 8;
tail_idx -= 8;
}
}
Ok(vec_u8)