Skip to content

Commit 6a35963

Browse files
author
Eli Rosenthal
committed
fix clippy lints
More to come
1 parent 39ba5b9 commit 6a35963

File tree

11 files changed

+99
-135
lines changed

11 files changed

+99
-135
lines changed

src/arena.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ pub struct Arena(bumpalo::Bump);
1616
pub type Vec<'a, T> = bumpalo::collections::Vec<'a, T>;
1717

1818
impl Arena {
19-
pub fn vec_with_capacity<'a, T>(&'a self, capacity: usize) -> Vec<'a, T> {
19+
pub fn vec_with_capacity<T>(&self, capacity: usize) -> Vec<T> {
2020
Vec::with_capacity_in(capacity, &self.0)
2121
}
22-
pub fn new_vec<'a, T>(&'a self) -> Vec<'a, T> {
22+
pub fn new_vec<T>(&self) -> Vec<T> {
2323
Vec::new_in(&self.0)
2424
}
2525
pub fn new_vec_from_slice<'a, T: Clone>(&'a self, elts: &[T]) -> Vec<'a, T> {

src/ast.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn parse_header<'a, 'b, I: From<&'b str> + Clone>(
7878
) {
7979
use {self::Expr::*, Stmt::*};
8080
// Pick an illegal frawk identifier.
81-
const LOOP_VAR: &'static str = "--";
81+
const LOOP_VAR: &str = "--";
8282
// Append the following to begin:
8383
// if (getline > 0) {
8484
// for (LOOP_VAR=1; LOOP_VAR <= NF; ++LOOP_VAR)
@@ -185,7 +185,7 @@ impl<'a, 'b, I: From<&'b str> + Clone> Prog<'a, 'b, I> {
185185
}
186186

187187
// Set argc, argv
188-
if self.argv.len() > 0 {
188+
if !self.argv.is_empty() {
189189
begin.push(arena.alloc(Expr(arena.alloc(Assign(
190190
arena.alloc(Var("ARGC".into())),
191191
arena.alloc(ILit(self.argv.len() as i64)),
@@ -282,23 +282,23 @@ impl<'a, 'b, I: From<&'b str> + Clone> Prog<'a, 'b, I> {
282282
}
283283
}
284284

285-
if self.end.len() > 0 || self.prepare.len() > 0 || inner.len() > init_len {
285+
if !self.end.is_empty() || !self.prepare.is_empty() || inner.len() > init_len {
286286
// Wrap the whole thing in a while((getline) > 0) { } statement.
287287
let main_portion = arena.alloc(While(
288288
/*is_toplevel=*/ true,
289289
arena.alloc(Binop(GT, arena.alloc(ReadStdin), arena.alloc(ILit(0)))),
290290
arena.alloc(Block(inner)),
291291
));
292-
main_loop = Some(if self.prepare.len() > 0 {
292+
main_loop = Some(if self.prepare.is_empty() {
293+
main_portion
294+
} else {
293295
let mut block = arena.vec_with_capacity(self.prepare.len() + 1);
294296
block.push(main_portion);
295297
block.extend(self.prepare.iter().cloned());
296298
arena.alloc(Stmt::Block(block))
297-
} else {
298-
main_portion
299299
});
300300
}
301-
if self.end.len() > 0 {
301+
if !self.end.is_empty() {
302302
end = Some(arena.alloc(Stmt::Block(self.end.clone())));
303303
}
304304
match self.stage {
@@ -307,10 +307,10 @@ impl<'a, 'b, I: From<&'b str> + Clone> Prog<'a, 'b, I> {
307307
Stage::Main(arena.alloc(Stmt::Block(begin)))
308308
}
309309
Stage::Par { .. } => Stage::Par {
310-
begin: if begin.len() > 0 {
311-
Some(arena.alloc(Stmt::Block(begin)))
312-
} else {
310+
begin: if begin.is_empty() {
313311
None
312+
} else {
313+
Some(arena.alloc(Stmt::Block(begin)))
314314
},
315315
main_loop,
316316
end,

src/builtins.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl Function {
359359
(Str, Str) => smallvec![Str; 2],
360360
(Int, Int) | (Null, Int) | (Int, Null) | (Null, Null) => smallvec![Int; 2],
361361
(_, Str) | (Str, _) | (Float, _) | (_, Float) => smallvec![Float; 2],
362-
_ => return err!("invalid input spec for comparison op: {:?}", &incoming[..]),
362+
_ => return err!("invalid input spec for comparison op: {:?}", incoming),
363363
},
364364
Int,
365365
),
@@ -370,12 +370,12 @@ impl Function {
370370
Contains => match incoming[0] {
371371
MapIntInt | MapIntStr | MapIntFloat => (smallvec![incoming[0], Int], Int),
372372
MapStrInt | MapStrStr | MapStrFloat => (smallvec![incoming[0], Str], Int),
373-
_ => return err!("invalid input spec fo Contains: {:?}", &incoming[..]),
373+
_ => return err!("invalid input spec fo Contains: {:?}", incoming),
374374
},
375375
Delete => match incoming[0] {
376376
MapIntInt | MapIntStr | MapIntFloat => (smallvec![incoming[0], Int], Int),
377377
MapStrInt | MapStrStr | MapStrFloat => (smallvec![incoming[0], Str], Int),
378-
_ => return err!("invalid input spec fo Delete: {:?}", &incoming[..]),
378+
_ => return err!("invalid input spec fo Delete: {:?}", incoming),
379379
},
380380
IncMap => {
381381
let map = incoming[0];
@@ -396,10 +396,7 @@ impl Function {
396396
if incoming.len() == 1 && incoming[0].is_array() {
397397
(smallvec![incoming[0]], Int)
398398
} else {
399-
return err!(
400-
"invalid input spec for delete (of a map): {:?}",
401-
&incoming[..]
402-
);
399+
return err!("invalid input spec for delete (of a map): {:?}", incoming);
403400
}
404401
}
405402
Srand => (smallvec![Int], Int),
@@ -437,7 +434,7 @@ impl Function {
437434
if let MapIntStr | MapStrStr = incoming[1] {
438435
(smallvec![Str, incoming[1], Str], Int)
439436
} else {
440-
return err!("invalid input spec for split: {:?}", &incoming[..]);
437+
return err!("invalid input spec for split: {:?}", incoming);
441438
}
442439
}
443440
JoinCols => (smallvec![Int, Int, Str], Str),
@@ -589,7 +586,7 @@ impl<'a> Variables<'a> {
589586

590587
pub fn store_int(&mut self, var: Variable, i: Int) -> Result<()> {
591588
use Variable::*;
592-
Ok(match var {
589+
match var {
593590
ARGC => self.argc = i,
594591
NF => self.nf = i,
595592
NR => self.nr = i,
@@ -598,7 +595,8 @@ impl<'a> Variables<'a> {
598595
RLENGTH => self.rlength = i,
599596
PID => self.pid = i,
600597
FI | ORS | OFS | FS | RS | FILENAME | ARGV => return err!("var {} not an int", var),
601-
})
598+
}
599+
Ok(())
602600
}
603601

604602
pub fn load_str(&self, var: Variable) -> Result<Str<'a>> {
@@ -617,7 +615,7 @@ impl<'a> Variables<'a> {
617615

618616
pub fn store_str(&mut self, var: Variable, s: Str<'a>) -> Result<()> {
619617
use Variable::*;
620-
Ok(match var {
618+
match var {
621619
FS => self.fs = s,
622620
OFS => self.ofs = s,
623621
ORS => self.ors = s,
@@ -626,7 +624,8 @@ impl<'a> Variables<'a> {
626624
FI | PID | ARGC | ARGV | NF | NR | FNR | RSTART | RLENGTH => {
627625
return err!("var {} not a string", var)
628626
}
629-
})
627+
};
628+
Ok(())
630629
}
631630

632631
pub fn load_intmap(&self, var: Variable) -> Result<IntMap<Str<'a>>> {
@@ -642,7 +641,10 @@ impl<'a> Variables<'a> {
642641
pub fn store_intmap(&mut self, var: Variable, m: IntMap<Str<'a>>) -> Result<()> {
643642
use Variable::*;
644643
match var {
645-
ARGV => Ok(self.argv = m),
644+
ARGV => {
645+
self.argv = m;
646+
Ok(())
647+
}
646648
FI | PID | ORS | OFS | ARGC | NF | NR | FNR | FS | RS | FILENAME | RSTART | RLENGTH => {
647649
err!("var {} is not an int-keyed map", var)
648650
}

0 commit comments

Comments
 (0)