Skip to content

Commit d81eae3

Browse files
author
Eli Rosenthal
committed
fix more clippy lints
1 parent 6a35963 commit d81eae3

File tree

11 files changed

+60
-58
lines changed

11 files changed

+60
-58
lines changed

src/builtins.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,10 @@ impl<'a> Variables<'a> {
664664
pub fn store_strmap(&mut self, var: Variable, m: StrMap<'a, Int>) -> Result<()> {
665665
use Variable::*;
666666
match var {
667-
FI => Ok(self.fi = m),
667+
FI => {
668+
self.fi = m;
669+
Ok(())
670+
}
668671
ARGV | PID | ORS | OFS | ARGC | NF | NR | FNR | FS | RS | FILENAME | RSTART
669672
| RLENGTH => {
670673
err!("var {} is not a string-keyed map", var)

src/bytecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl<'a> Instr<'a> {
698698
if let Some((path_reg, _)) = output {
699699
path_reg.accum(&mut f);
700700
}
701-
for reg in args.iter().cloned() {
701+
for reg in args {
702702
reg.accum(&mut f)
703703
}
704704
}

src/cfg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ where
15731573
Ok((h, b_start, b_end, f))
15741574
}
15751575

1576+
#[allow(clippy::wrong_self_convention)]
15761577
fn to_val(&mut self, exp: PrimExpr<'b>, current_open: NodeIx) -> Result<PrimVal<'b>> {
15771578
Ok(if let PrimExpr::Val(v) = exp {
15781579
v

src/codegen/clif.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -726,14 +726,12 @@ impl<'a> View<'a> {
726726
}
727727
Ret(reg, ty) => {
728728
let mut v = self.get_val((*reg, *ty))?;
729-
if matches!(
730-
self.f.vars.get_mut(&(*reg, *ty)).map(|x| {
731-
// if this is a local, we want to avoid dropping it.
732-
x.kind.skip_drop();
733-
&x.kind
734-
}),
735-
Some(VarKind::Param) | Some(VarKind::Global)
736-
) {
729+
let test = self.f.vars.get_mut(&(*reg, *ty)).map(|x| {
730+
// if this is a local, we want to avoid dropping it.
731+
x.kind.skip_drop();
732+
&x.kind
733+
});
734+
if let Some(VarKind::Param) | Some(VarKind::Global) = test {
737735
// This was passed in as a parameter, so us returning it will introduce a new
738736
// reference.
739737
self.ref_val(*ty, v);
@@ -801,7 +799,7 @@ impl<'a> View<'a> {
801799
}
802800

803801
fn execute_actions(&mut self) -> Result<()> {
804-
let header_actions = mem::replace(&mut self.f.header_actions, Default::default());
802+
let header_actions = mem::take(&mut self.f.header_actions);
805803
for EntryDeclaration { var, ty } in header_actions {
806804
use compile::Ty::*;
807805
let cl_ty = self.get_ty(ty);
@@ -1349,7 +1347,8 @@ impl<'a> CodeGenerator for View<'a> {
13491347
}
13501348

13511349
fn call_void(&mut self, func: *const u8, args: &mut [Self::Val]) -> Result<()> {
1352-
Ok(self.call_external_void(func, args))
1350+
self.call_external_void(func, args);
1351+
Ok(())
13531352
}
13541353

13551354
// TODO We may eventually want to remove the `Result` return value here
@@ -1384,7 +1383,7 @@ impl<'a> CodeGenerator for View<'a> {
13841383
args: &[Ref],
13851384
) -> Result<()> {
13861385
// For empty args, just delegate to print_all
1387-
if args.len() == 0 {
1386+
if args.is_empty() {
13881387
return self.print_all(output, &[*fmt]);
13891388
}
13901389
let (arg_slot, type_slot, num_args) = self.bundle_printf_args(args)?;
@@ -1413,7 +1412,7 @@ impl<'a> CodeGenerator for View<'a> {
14131412

14141413
fn sprintf(&mut self, dst: &StrReg, fmt: &StrReg, args: &[Ref]) -> Result<()> {
14151414
// For empty args, just move fmt into dst.
1416-
if args.len() == 0 {
1415+
if args.is_empty() {
14171416
return self.mov(compile::Ty::Str, dst.reflect().0, fmt.reflect().0);
14181417
}
14191418

src/codegen/intrinsics.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ pub(crate) unsafe extern "C" fn split_str(
579579
if let Err(e) = runtime
580580
.core
581581
.regexes
582-
.split_regex_strmap(&pat, &to_split, &into_arr)
582+
.split_regex_strmap(pat, to_split, &into_arr)
583583
{
584584
fail!(runtime, "failed to split string: {}", e);
585585
}
@@ -710,8 +710,7 @@ pub(crate) unsafe extern "C" fn set_col(runtime: *mut c_void, col: Int, s: *mut
710710

711711
pub(crate) unsafe extern "C" fn str_len(s: *mut c_void) -> usize {
712712
let s = &*(s as *mut Str);
713-
let res = s.len();
714-
res
713+
s.len()
715714
}
716715

717716
pub(crate) unsafe extern "C" fn starts_with_const(
@@ -895,7 +894,7 @@ pub(crate) unsafe extern "C" fn float_to_str(f: Float) -> U128 {
895894

896895
pub(crate) unsafe extern "C" fn str_to_int(s: *mut c_void) -> Int {
897896
let s = &*(s as *mut Str);
898-
runtime::convert::<&Str, Int>(&s)
897+
runtime::convert::<&Str, Int>(s)
899898
}
900899

901900
pub(crate) unsafe extern "C" fn hex_str_to_int(s: *mut c_void) -> Int {

src/codegen/llvm/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl IntrinsicMap {
4949
MapStrInt => Some(self.get(external!(drop_strint))),
5050
MapStrFloat => Some(self.get(external!(drop_strfloat))),
5151
MapStrStr => Some(self.get(external!(drop_strstr))),
52-
_ => return None,
52+
_ => None,
5353
}
5454
}
5555

@@ -96,7 +96,7 @@ impl IntrinsicMap {
9696
LLVMAddSymbol(intr.name, intr.func);
9797
let func = LLVMAddFunction(self.module, intr.name, ty);
9898
LLVMSetLinkage(func, llvm_sys::LLVMLinkage::LLVMExternalLinkage);
99-
if intr.attrs.len() > 0 {
99+
if !intr.attrs.is_empty() {
100100
attr::add_function_attrs(self.ctx, func, &intr.attrs[..]);
101101
}
102102
*val = Either::Right(func);

src/codegen/llvm/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a> Backend for View<'a> {
111111
) -> Result<()> {
112112
let f_ty = unsafe {
113113
LLVMFunctionType(
114-
sig.ret.unwrap_or(LLVMVoidTypeInContext(self.ctx)),
114+
sig.ret.unwrap_or_else(|| LLVMVoidTypeInContext(self.ctx)),
115115
sig.args.as_mut_ptr(),
116116
sig.args.len() as u32,
117117
0,
@@ -847,10 +847,8 @@ impl<'a, 'b> Generator<'a, 'b> {
847847
);
848848
self.type_map
849849
.init(Ty::Float, make(LLVMDoubleTypeInContext(self.ctx)));
850-
self.type_map.init(
851-
Ty::Str,
852-
make(LLVMIntTypeInContext(self.ctx, 128 as libc::c_uint)),
853-
);
850+
self.type_map
851+
.init(Ty::Str, make(LLVMIntTypeInContext(self.ctx, 128)));
854852
self.type_map.init(Ty::MapIntInt, make(voidptr));
855853
self.type_map.init(Ty::MapIntFloat, make(voidptr));
856854
self.type_map.init(Ty::MapIntStr, make(voidptr));
@@ -1153,7 +1151,7 @@ impl<'a, 'b> Generator<'a, 'b> {
11531151
while let Some(e) = walker.next_edge(&frame.cfg) {
11541152
let (_, t) = frame.cfg.edge_endpoints(e).unwrap();
11551153
let bb = bbs[t.index()];
1156-
if let Some(e) = frame.cfg.edge_weight(e).unwrap().clone() {
1154+
if let Some(e) = *frame.cfg.edge_weight(e).unwrap() {
11571155
tcase = Some((e, bb));
11581156
} else {
11591157
// NB, we used to disallow duplicate unconditional branches outbound from a

src/codegen/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a> MainFunction<'a> {
130130

131131
pub(crate) trait Jit: Sized {
132132
fn main_pointers(&mut self) -> Result<Stage<*const u8>>;
133-
fn main_functions<'a>(&'a mut self) -> Result<Stage<MainFunction<'a>>> {
133+
fn main_functions(&mut self) -> Result<Stage<MainFunction>> {
134134
Ok(self.main_pointers()?.map(MainFunction::from_ptr))
135135
}
136136
}
@@ -154,7 +154,10 @@ where
154154
let mut rt = stdin.into_runtime(ff, used_fields, named_columns, cancel_signal.clone());
155155
let main = jit.main_functions()?;
156156
match main {
157-
Stage::Main(m) => Ok(m.invoke(&mut rt)),
157+
Stage::Main(m) => {
158+
m.invoke(&mut rt);
159+
Ok(())
160+
}
158161
Stage::Par {
159162
begin,
160163
main_loop,
@@ -165,7 +168,7 @@ where
165168
// pretty awful; It may be worth a RefCell just to clean up.
166169
with_input!(&mut rt.input_data, |(_, read_files)| {
167170
let reads = read_files.try_resize(num_workers.saturating_sub(1));
168-
if num_workers <= 1 || reads.len() == 0 || main_loop.is_none() {
171+
if num_workers <= 1 || reads.is_empty() || main_loop.is_none() {
169172
// execute serially.
170173
for main in begin.into_iter().chain(main_loop).chain(end) {
171174
main.invoke(&mut rt);
@@ -185,7 +188,7 @@ where
185188
if let Some(begin) = begin {
186189
begin.invoke(&mut rt);
187190
}
188-
if let Err(_) = rt.core.write_files.flush_stdout() {
191+
if rt.core.write_files.flush_stdout().is_err() {
189192
return Ok(());
190193
}
191194

@@ -204,7 +207,7 @@ where
204207
})
205208
.collect();
206209
with_input!(&mut rt.input_data, |(_, read_files)| {
207-
let old_read_files = mem::replace(&mut read_files.inputs, Default::default());
210+
let old_read_files = mem::take(&mut read_files.inputs);
208211
let main_loop_fn = main_loop.unwrap();
209212
let scope_res = crossbeam::scope(|s| {
210213
for (reader, sender, shuttle) in launch_data.into_iter() {
@@ -229,7 +232,7 @@ where
229232
rt.core.vars.pid = 1;
230233
let r = receiver.clone();
231234
rt.cleanup =
232-
Cleanup::<Runtime>::new(move |_| while let Ok(_) = r.recv() {});
235+
Cleanup::<Runtime>::new(move |_| while r.recv().is_ok() {});
233236
main_loop_fn.invoke(&mut rt);
234237
rt.cleanup.cancel();
235238
}
@@ -250,7 +253,7 @@ where
250253
}
251254
});
252255
});
253-
if let Err(_) = scope_res {
256+
if scope_res.is_err() {
254257
return err!("failed to execute parallel script");
255258
}
256259
});

src/compile.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ impl Default for Ty {
7373

7474
impl Ty {
7575
fn is_iter(self) -> bool {
76-
if let Ty::IterInt | Ty::IterStr = self {
77-
true
78-
} else {
79-
false
80-
}
76+
matches!(self, Ty::IterInt | Ty::IterStr)
8177
}
8278

8379
pub(crate) fn key_iter(self) -> Result<Ty> {
@@ -457,7 +453,7 @@ struct View<'a, 'b> {
457453
stream: &'b mut Node<'a>,
458454
}
459455

460-
fn pop_var<'a>(instrs: &mut Vec<LL<'a>>, reg: NumTy, ty: Ty) -> Result<()> {
456+
fn pop_var(instrs: &mut Vec<LL>, reg: NumTy, ty: Ty) -> Result<()> {
461457
use Ty::*;
462458
instrs.push(match ty {
463459
Null => return Ok(()),
@@ -468,7 +464,7 @@ fn pop_var<'a>(instrs: &mut Vec<LL<'a>>, reg: NumTy, ty: Ty) -> Result<()> {
468464
Ok(())
469465
}
470466

471-
fn push_var<'a>(instrs: &mut Vec<LL<'a>>, reg: NumTy, ty: Ty) -> Result<()> {
467+
fn push_var(instrs: &mut Vec<LL>, reg: NumTy, ty: Ty) -> Result<()> {
472468
use Ty::*;
473469
match ty {
474470
Null => Ok(()),
@@ -506,7 +502,7 @@ fn mov<'a>(dst_reg: u32, src_reg: u32, ty: Ty) -> Result<Option<LL<'a>>> {
506502
Ok(Some(res))
507503
}
508504

509-
fn accum<'a>(inst: &Instr<'a>, mut f: impl FnMut(NumTy, Ty)) {
505+
fn accum(inst: &Instr, mut f: impl FnMut(NumTy, Ty)) {
510506
use {Either::*, HighLevel::*};
511507
match inst {
512508
Left(ll) => ll.accum(f),
@@ -551,6 +547,7 @@ impl<'a> Typer<'a> {
551547
}
552548

553549
// At initialization time, we generate Either<LL, HL>, this function lowers the HL into LL.
550+
#[allow(clippy::wrong_self_convention)]
554551
fn to_bytecode(&mut self) -> Result<Vec<Vec<LL<'a>>>> {
555552
let mut res = vec![vec![]; self.frames.len()];
556553
let ret_regs: Vec<_> = (0..self.frames.len())
@@ -697,7 +694,7 @@ impl<'a> Typer<'a> {
697694
edges.reverse();
698695
for eix in edges.iter().cloned() {
699696
let dst = frame.cfg.edge_endpoints(eix).unwrap().1.index();
700-
if let Some(reg) = frame.cfg.edge_weight(eix).unwrap().clone() {
697+
if let Some(reg) = *frame.cfg.edge_weight(eix).unwrap() {
701698
jmps.push(instrs.len());
702699
instrs.push(LL::JmpIf(reg.into(), dst.into()));
703700
} else if dst != j + 1 {
@@ -860,7 +857,7 @@ impl<'a> Typer<'a> {
860857
if strs.len() != 1 {
861858
continue;
862859
}
863-
let text = std::str::from_utf8(&strs[0]).map_err(|e| {
860+
let text = std::str::from_utf8(strs[0]).map_err(|e| {
864861
CompileError(format!("regex patterns must be valid UTF-8: {}", e))
865862
})?;
866863
let re = Arc::new(Regex::new(text).map_err(|err| {
@@ -1101,7 +1098,7 @@ impl<'a, 'b> View<'a, 'b> {
11011098
(self.regs.globals[id], RegStatus::Global)
11021099
} else {
11031100
match self.frame.locals.get(id) {
1104-
Some(x) => (x.clone(), RegStatus::Local),
1101+
Some(x) => (*x, RegStatus::Local),
11051102
// In some degenerate cases, we'll run into an uninitialized local. These are
11061103
// always null.
11071104
None if id.sub == 0 => ((NULL_REG, Ty::Null), RegStatus::Local),
@@ -1212,8 +1209,8 @@ impl<'a, 'b> View<'a, 'b> {
12121209
);
12131210
}
12141211
};
1215-
1216-
Ok(self.pushl(res))
1212+
self.pushl(res);
1213+
Ok(())
12171214
}
12181215

12191216
// Store values into a register at a given type, converting if necessary.
@@ -1596,7 +1593,7 @@ impl<'a, 'b> View<'a, 'b> {
15961593
| Ty::MapStrFloat => LL::Len {
15971594
map_ty: conv_tys[0],
15981595
map: conv_regs[0],
1599-
dst: res_reg.into(),
1596+
dst: res_reg,
16001597
},
16011598
Ty::Str => LL::LenStr(res_reg.into(), conv_regs[0].into()),
16021599
_ => return err!("invalid input type for length: {:?}", &conv_tys[..]),
@@ -2020,9 +2017,7 @@ fn extract_anchored_literal(text: &str) -> Option<Arc<[u8]>> {
20202017
continue;
20212018
}
20222019
let cur = bs.len();
2023-
for _ in 0..l.c.len_utf8() {
2024-
bs.push(0);
2025-
}
2020+
bs.resize(cur + l.c.len_utf8(), 0);
20262021
l.c.encode_utf8(&mut bs[cur..]);
20272022
} else {
20282023
return None;

src/dataflow.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ impl<K: Eq + Hash, J: JoinSemiLattice> Analysis<J, K> {
6060
}
6161
fn get_node(&mut self, k: impl Into<K>) -> NodeIx {
6262
let graph = &mut self.graph;
63-
self.nodes
63+
*self
64+
.nodes
6465
.entry(k.into())
6566
.or_insert_with(|| graph.add_node(J::bottom()))
66-
.clone()
6767
}
6868
pub(crate) fn add_query(&mut self, k: impl Into<K>) {
6969
let ix = self.get_node(k);
@@ -120,6 +120,10 @@ impl<K: Eq + Hash, J: JoinSemiLattice> Analysis<J, K> {
120120
}
121121

122122
#[derive(Eq, PartialEq, Hash, Clone, Copy, Debug)]
123+
#[allow(clippy::enum_variant_names)]
124+
// "Key" as an enum variant refers to "key for an array value" whereas "Key" as the datatype name
125+
// refers to "Key" key associated with the value of a dataflow analysis (e.g. some particular
126+
// lattice).
123127
pub(crate) enum Key {
124128
Reg(NumTy, Ty),
125129
MapKey(NumTy, Ty),
@@ -164,9 +168,9 @@ pub(crate) mod boilerplate {
164168
args,
165169
} => {
166170
let dst_key = Key::Reg(*dst_reg, *dst_ty);
167-
f(dst_key.clone(), Some(Key::Func(*func_id)));
171+
f(dst_key, Some(Key::Func(*func_id)));
168172
for (reg, ty) in args.iter().cloned() {
169-
f(dst_key.clone(), Some(Key::Reg(reg, ty)));
173+
f(dst_key, Some(Key::Reg(reg, ty)));
170174
}
171175
}
172176
Ret(reg, ty) => {

0 commit comments

Comments
 (0)