Skip to content

Commit a1dab88

Browse files
committed
style: fix clippy warnings.
With the change to edition 2024 clippy finds a bunch of new warnings. Most of them are related to chained `if let` statements.
1 parent 74360e5 commit a1dab88

32 files changed

Lines changed: 165 additions & 274 deletions

File tree

cli/src/commands/deps.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn exec_deps(args: &ArgMatches) -> anyhow::Result<()> {
8585

8686
for dep in dep_tree.iter() {
8787
let mut output = String::new();
88-
write_tree(&mut output, &dep)?;
88+
write_tree(&mut output, dep)?;
8989
println!("{output}");
9090
}
9191

@@ -100,7 +100,7 @@ fn generate_dep_tree(
100100

101101
for (rule, deps) in dep_map.iter() {
102102
if requested_rules.is_empty() || requested_rules.contains(rule) {
103-
nodes.push(tree_for_rule(rule, &deps, &dep_map));
103+
nodes.push(tree_for_rule(rule, deps, dep_map));
104104
}
105105
}
106106

cli/src/commands/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,14 @@ impl Component for CompileState {
354354
) -> anyhow::Result<Lines> {
355355
let mut lines = Lines::new();
356356

357-
if mode == superconsole::DrawMode::Normal {
358-
if let Some(file) = &self.file_in_progress {
357+
if mode == superconsole::DrawMode::Normal
358+
&& let Some(file) = &self.file_in_progress {
359359
lines.push(Line::from_iter([Span::new_unstyled(format!(
360360
"{} {}...",
361361
"Compiling".paint(Green).bold(),
362362
file.display(),
363363
))?]));
364364
}
365-
}
366365

367366
Ok(lines)
368367
}

cli/src/commands/scan.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use clap::{
1111
Arg, ArgAction, ArgMatches, Command, ValueEnum, arg, value_parser,
1212
};
1313
use crossbeam::channel::Sender;
14-
use dunce;
1514
use itertools::Itertools;
1615
use superconsole::style::Stylize;
1716
use superconsole::{Component, Line, Lines, Span};
@@ -436,11 +435,10 @@ pub fn exec_scan(args: &ArgMatches, config: &Config) -> anyhow::Result<()> {
436435
let _ = output.send(Message::Error(msg));
437436

438437
// In case of timeout walk is aborted.
439-
if let Ok(scan_err) = err.downcast::<ScanError>() {
440-
if matches!(scan_err, ScanError::Timeout) {
438+
if let Ok(scan_err) = err.downcast::<ScanError>()
439+
&& matches!(scan_err, ScanError::Timeout) {
441440
return Err(scan_err.into());
442441
}
443-
}
444442

445443
Ok(())
446444
},
@@ -756,14 +754,13 @@ mod output_handler {
756754
let mut result = false;
757755

758756
for matching_rule in scan_results {
759-
if let Some(ref only_tag) = self.output_options.only_tag {
760-
if !matching_rule
757+
if let Some(ref only_tag) = self.output_options.only_tag
758+
&& !matching_rule
761759
.tags()
762760
.any(|tag| tag.identifier() == only_tag)
763761
{
764762
continue;
765763
}
766-
}
767764

768765
result = true;
769766

@@ -1066,7 +1063,7 @@ mod output_handler {
10661063
scan_results: &mut dyn ExactSizeIterator<Item = Rule>,
10671064
_output: &Sender<Message>,
10681065
) -> bool {
1069-
let path = dunce::canonicalize(&file_path)
1066+
let path = dunce::canonicalize(file_path)
10701067
.ok()
10711068
.as_ref()
10721069
.and_then(|absolute| absolute.to_str())

cli/src/walk.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,10 @@ impl<'a> Walker<'a> {
155155
self.walk_file_list(f, e)
156156
} else {
157157
if metadata.is_file() {
158-
if self.pass_metadata_filter(metadata) {
159-
if let Err(err) = f(self.path) {
158+
if self.pass_metadata_filter(metadata)
159+
&& let Err(err) = f(self.path) {
160160
return e(err);
161-
}
162-
};
161+
};
163162
return Ok(());
164163
}
165164
self.walk_dir(f, e)
@@ -185,11 +184,10 @@ impl<'a> Walker<'a> {
185184
Err(err) => return Err(err),
186185
},
187186
};
188-
if self.pass_metadata_filter(metadata) {
189-
if let Err(err) = f(&path) {
187+
if self.pass_metadata_filter(metadata)
188+
&& let Err(err) = f(&path) {
190189
e(err)?
191190
}
192-
}
193191
}
194192

195193
Ok(())
@@ -246,11 +244,10 @@ impl<'a> Walker<'a> {
246244

247245
match entry.metadata() {
248246
Ok(metadata) => {
249-
if self.pass_metadata_filter(metadata) {
250-
if let Err(err) = f(entry.path()) {
247+
if self.pass_metadata_filter(metadata)
248+
&& let Err(err) = f(entry.path()) {
251249
e(err)?
252250
}
253-
}
254251
}
255252
Err(err) => e(err.into())?,
256253
}
@@ -455,12 +452,11 @@ impl<'a> ParWalker<'a> {
455452
path.to_path_buf(),
456453
&mut per_thread_obj,
457454
);
458-
if let Err(err) = res {
459-
if error(err, &msg_send).is_err() {
455+
if let Err(err) = res
456+
&& error(err, &msg_send).is_err() {
460457
let _ = msg_send.send(Message::Abort);
461458
break;
462459
}
463-
}
464460
}
465461
finalize(&per_thread_obj, &msg_send);
466462
}));
@@ -490,11 +486,10 @@ impl<'a> ParWalker<'a> {
490486
},
491487
);
492488

493-
if let Err(err) = res {
494-
if error(err, &msg_send).is_err() {
489+
if let Err(err) = res
490+
&& error(err, &msg_send).is_err() {
495491
let _ = msg_send.send(Message::Abort);
496492
}
497-
}
498493
}));
499494

500495
let mut console = if cfg!(feature = "logging") {
@@ -594,12 +589,11 @@ fn output_messages<S>(
594589
Err(RecvTimeoutError::Timeout) => {}
595590
}
596591

597-
if let Some(console) = console.as_mut() {
598-
if Instant::elapsed(&last_render) > render_period {
592+
if let Some(console) = console.as_mut()
593+
&& Instant::elapsed(&last_render) > render_period {
599594
console.render(state.as_ref()).unwrap();
600595
last_render = Instant::now();
601596
}
602-
}
603597
}
604598
}
605599

fmt/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,9 +918,9 @@ impl Formatter {
918918
};
919919

920920
let tokens = AddIndentation::new(tokens, self.indentation);
921-
let tokens = RemoveTrailingSpaces::new(tokens);
921+
922922

923-
tokens
923+
RemoveTrailingSpaces::new(tokens)
924924
}
925925

926926
/// Indents the sections (meta, strings, condition) of a rule one level up.

fmt/src/processor/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,10 @@ where
411411
// start or the end of a rule.
412412
if let Token::Begin(rule) = token {
413413
self.stack.push(rule)
414-
} else if let Token::End(rule) = token {
415-
if let Some(top) = self.stack.pop() {
414+
} else if let Token::End(rule) = token
415+
&& let Some(top) = self.stack.pop() {
416416
assert_eq!(top, rule);
417417
}
418-
}
419418
self.output.push_back(token);
420419
} else {
421420
break;

lib/build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,11 @@ fn generate_proto_code() {
179179
proto_compiler.include(path);
180180
proto_parser.include(path);
181181
}
182-
if let Some(extension) = path.extension() {
183-
if extension == "proto" {
182+
if let Some(extension) = path.extension()
183+
&& extension == "proto" {
184184
proto_compiler.input(path);
185185
proto_parser.input(path);
186186
}
187-
}
188187
}
189188

190189
// The environment variable `YRX_EXTRA_PROTOS` allows passing a list of

lib/src/compiler/emit.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,10 @@ fn emit_expr(
398398
// field in the lookup list doesn't belong to the
399399
// root structure, we know that the stack already
400400
// contains the object.
401-
if let Some((_, true)) = ctx.lookup_list.first() {
402-
if func.is_method() {
401+
if let Some((_, true)) = ctx.lookup_list.first()
402+
&& func.is_method() {
403403
emit_lookup_object(ctx, instr);
404404
}
405-
}
406405
ctx.lookup_list.clear();
407406
}
408407
TypeValue::Regexp(_) => {
@@ -955,12 +954,11 @@ fn emit_field_access(
955954
// will be emitted, encompassing all the lookups in a single call to
956955
// Rust code.
957956
for operand in field_access.operands.iter().dropping_back(1) {
958-
if let Expr::Symbol(symbol) = ir.get(*operand) {
959-
if let Symbol::Field { index, is_root, .. } = symbol.as_ref() {
957+
if let Expr::Symbol(symbol) = ir.get(*operand)
958+
&& let Symbol::Field { index, is_root, .. } = symbol.as_ref() {
960959
ctx.lookup_list.push((*index as i32, *is_root));
961960
continue;
962961
}
963-
}
964962
emit_expr(ctx, ir, *operand, instr);
965963
}
966964

0 commit comments

Comments
 (0)