cargo clippy
This commit is contained in:
parent
89a2a077c0
commit
5d84b017b9
4 changed files with 25 additions and 23 deletions
|
@ -50,9 +50,8 @@ fn calculate_votes(mut que: Vec<Box<[u8]>>) -> Vec<BTreeMap<Box<[u8]>, VoteEntry
|
|||
.take(que.iter().map(|i| sum(&i[..])).max().map(|i| i.checked_add(1).unwrap()).unwrap_or(0))
|
||||
.collect::<Vec<BTreeMap<Box<[u8]>, VoteEntry>>>();
|
||||
|
||||
for i in core::mem::replace(&mut que, Vec::new()) {
|
||||
let mut l = &mut levels[sum(&i[..])];
|
||||
l.insert(i, VoteEntry {
|
||||
for i in core::mem::take(&mut que) {
|
||||
levels[sum(&i[..])].insert(i, VoteEntry {
|
||||
votes: 1,
|
||||
best_parent: 0,
|
||||
is_used: true,
|
||||
|
@ -62,9 +61,9 @@ fn calculate_votes(mut que: Vec<Box<[u8]>>) -> Vec<BTreeMap<Box<[u8]>, VoteEntry
|
|||
// process levels (start from largest)
|
||||
for (lid, i) in levels.iter_mut().enumerate().rev() {
|
||||
// insert queued items into this level
|
||||
for j in core::mem::replace(&mut que, Vec::new()) {
|
||||
let mut v = i.entry(j).or_default();
|
||||
v.votes = v.votes.checked_add(1).unwrap();
|
||||
for j in core::mem::take(&mut que) {
|
||||
let votes = &mut i.entry(j).or_default().votes;
|
||||
*votes = votes.checked_add(1).unwrap();
|
||||
}
|
||||
|
||||
// handle all items in this level
|
||||
|
@ -138,9 +137,9 @@ pub fn fullfill_links(que: Vec<Link>) -> Vec<Vec<Vec<(Box<[u8]>, u16)>>> {
|
|||
let mut ret = vec![Vec::new(); max_vid];
|
||||
|
||||
for (vid, que) in g {
|
||||
let mut votes = calculate_votes(que.clone());
|
||||
let mut ret = &mut ret[usize::from(vid)];
|
||||
ret.resize_with(votes.len(), || Vec::new());
|
||||
let votes = calculate_votes(que.clone());
|
||||
let ret = &mut ret[usize::from(vid)];
|
||||
ret.resize_with(votes.len(), Vec::new);
|
||||
|
||||
for (i, j) in ret.iter_mut().zip(votes.into_iter()) {
|
||||
for (k, l) in j.into_iter() {
|
||||
|
|
|
@ -104,7 +104,7 @@ impl System {
|
|||
#[derive(Clone, Debug, PartialEq, thiserror::Error)]
|
||||
pub enum ParseError {
|
||||
#[error("unexpected end of expression")]
|
||||
EmptyExpr,
|
||||
UnexpectedEol,
|
||||
|
||||
#[error("unexpected invalid char '{0}'")]
|
||||
InvalidChar(char),
|
||||
|
@ -131,14 +131,14 @@ pub enum ParseError {
|
|||
Float(#[from] std::num::ParseFloatError),
|
||||
}
|
||||
|
||||
trait ParseLink: Sized {
|
||||
pub trait ParseLink: Sized {
|
||||
fn parse_link(slb: &mut StrLexerBase<'_>) -> Result<Option<Self>, ParseError>;
|
||||
}
|
||||
|
||||
impl ParseLink for () {
|
||||
fn parse_link(slb: &mut StrLexerBase<'_>) -> Result<Option<Self>, ParseError> {
|
||||
if slb.inp.is_empty() {
|
||||
Err(ParseError::EmptyExpr)
|
||||
Err(ParseError::UnexpectedEol)
|
||||
} else if slb.inp.starts_with('.') {
|
||||
slb.consume(1);
|
||||
Ok(Some(()))
|
||||
|
@ -151,9 +151,9 @@ impl ParseLink for () {
|
|||
impl ParseLink for Link {
|
||||
fn parse_link(slb: &mut StrLexerBase<'_>) -> Result<Option<Self>, ParseError> {
|
||||
if slb.inp.is_empty() {
|
||||
Err(ParseError::EmptyExpr)
|
||||
Err(ParseError::UnexpectedEol)
|
||||
} else {
|
||||
let mut new_slb = (*slb).clone();
|
||||
let mut new_slb = *slb;
|
||||
let var = new_slb.consume_select(|i| i.is_ascii_digit());
|
||||
if var.is_empty() {
|
||||
return Ok(None);
|
||||
|
@ -188,7 +188,7 @@ fn parse_expr<L: Clone + ParseLink>(slb: &mut StrLexerBase<'_>) -> Result<Expr<L
|
|||
|
||||
if slb.inp.starts_with(|i: char| i == '-' || i.is_ascii_digit()) {
|
||||
// float
|
||||
let mut new_slb = (*slb).clone();
|
||||
let mut new_slb = *slb;
|
||||
|
||||
let neg = new_slb.inp.bytes().next() == Some(b'-');
|
||||
if neg {
|
||||
|
@ -205,7 +205,7 @@ fn parse_expr<L: Clone + ParseLink>(slb: &mut StrLexerBase<'_>) -> Result<Expr<L
|
|||
|
||||
let ident = slb.consume_select(|i| i.is_ascii_alphanumeric());
|
||||
if slb.inp.is_empty() {
|
||||
return Err(ParseError::EmptyExpr);
|
||||
return Err(ParseError::UnexpectedEol);
|
||||
}
|
||||
if ident.is_empty() {
|
||||
let c = slb.inp.chars().next().unwrap();
|
||||
|
@ -213,7 +213,7 @@ fn parse_expr<L: Clone + ParseLink>(slb: &mut StrLexerBase<'_>) -> Result<Expr<L
|
|||
}
|
||||
|
||||
// parse nesting...
|
||||
if slb.inp.chars().next() != Some('(') {
|
||||
if !slb.inp.starts_with('(') {
|
||||
let c = slb.inp.chars().next().unwrap();
|
||||
return Err(ParseError::InvalidChar(c));
|
||||
}
|
||||
|
@ -223,13 +223,17 @@ fn parse_expr<L: Clone + ParseLink>(slb: &mut StrLexerBase<'_>) -> Result<Expr<L
|
|||
loop {
|
||||
args.push(parse_expr::<L>(slb)?);
|
||||
slb.consume_select(|i| i.is_whitespace());
|
||||
if slb.inp.chars().next() != Some(',') {
|
||||
if !slb.inp.starts_with(',') {
|
||||
break;
|
||||
}
|
||||
slb.consume(1);
|
||||
}
|
||||
|
||||
if slb.inp.chars().next() != Some(')') {
|
||||
if slb.inp.is_empty() {
|
||||
return Err(ParseError::UnexpectedEol);
|
||||
}
|
||||
|
||||
if !slb.inp.starts_with(')') {
|
||||
let c = slb.inp.chars().next().unwrap();
|
||||
return Err(ParseError::InvalidChar(c));
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ fn main() {
|
|||
// parse system
|
||||
let system = {
|
||||
let system = std::fs::read(&cli.system).expect("unable to read system to render");
|
||||
let system = std::str::from_utf8(&*system).expect("unable to interpret system description as UTF-8");
|
||||
let system = std::str::from_utf8(&system).expect("unable to interpret system description as UTF-8");
|
||||
expr::parse_system(system).expect("unable to parse system")
|
||||
};
|
||||
|
||||
|
|
|
@ -21,13 +21,12 @@ impl<F: FnMut(&[u16])> ForEachStencilData<'_, F> {
|
|||
let prefix: usize = self.buf.len().checked_sub(shape.len()).expect("buffer too small");
|
||||
|
||||
// recurse over `this`
|
||||
if let Some(&fi) = shape.get(0) {
|
||||
if let Some(&fi) = shape.first() {
|
||||
let shnext = &shape[1..];
|
||||
for i in self.stencil_start .. (fi + 1 - self.stencil_end) {
|
||||
self.buf[prefix] = i;
|
||||
self.fe_st_intern(shnext);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
(*self.f)(self.buf);
|
||||
}
|
||||
|
@ -68,7 +67,7 @@ impl Shape {
|
|||
return None;
|
||||
}
|
||||
// (v, acc) = (x % s, x / s)
|
||||
Some(acc.checked_mul(s)?.checked_add(v)?)
|
||||
acc.checked_mul(s)?.checked_add(v)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue