Skip to content

Commit 77ebc55

Browse files
committed
Fix new rustc and clippy warnings
1 parent 90e6080 commit 77ebc55

File tree

11 files changed

+147
-148
lines changed

11 files changed

+147
-148
lines changed

src-rs/dep.rs

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -283,26 +283,28 @@ impl RuleMerger {
283283
);
284284
}
285285

286-
if let Some(primary_rule) = &mut self.primary_rule {
287-
if !r.cmds.is_empty() && !is_suffix_rule(&output) && !r.is_double_colon {
288-
if FLAGS.werror_overriding_commands {
289-
error_loc!(
290-
r.cmd_loc.as_ref(),
291-
"*** overriding commands for target `{output}', previously defined at {}",
292-
primary_rule.cmd_loc.clone().unwrap_or_default()
293-
);
294-
} else {
295-
warn_loc!(
296-
r.cmd_loc.as_ref(),
297-
"warning: overriding commands for target `{output}'"
298-
);
299-
warn_loc!(
300-
primary_rule.cmd_loc.as_ref(),
301-
"warning: ignoring old commands for target `{output}'"
302-
)
303-
}
304-
*primary_rule = r.clone();
286+
if let Some(primary_rule) = &mut self.primary_rule
287+
&& !r.cmds.is_empty()
288+
&& !is_suffix_rule(&output)
289+
&& !r.is_double_colon
290+
{
291+
if FLAGS.werror_overriding_commands {
292+
error_loc!(
293+
r.cmd_loc.as_ref(),
294+
"*** overriding commands for target `{output}', previously defined at {}",
295+
primary_rule.cmd_loc.clone().unwrap_or_default()
296+
);
297+
} else {
298+
warn_loc!(
299+
r.cmd_loc.as_ref(),
300+
"warning: overriding commands for target `{output}'"
301+
);
302+
warn_loc!(
303+
primary_rule.cmd_loc.as_ref(),
304+
"warning: ignoring old commands for target `{output}'"
305+
)
305306
}
307+
*primary_rule = r.clone();
306308
}
307309
if self.primary_rule.is_none() && !r.cmds.is_empty() {
308310
self.primary_rule = Some(r.clone());
@@ -329,10 +331,10 @@ impl RuleMerger {
329331

330332
fn fill_dep_node_loc(&self, r: &Rule, n: &mut DepNode) {
331333
n.loc = Some(r.loc.clone());
332-
if !r.cmds.is_empty() {
333-
if let Some(cmd_loc) = r.cmd_loc.clone() {
334-
n.loc = Some(cmd_loc);
335-
}
334+
if !r.cmds.is_empty()
335+
&& let Some(cmd_loc) = r.cmd_loc.clone()
336+
{
337+
n.loc = Some(cmd_loc);
336338
}
337339
}
338340

@@ -355,10 +357,10 @@ impl RuleMerger {
355357
}
356358

357359
for r in &self.rules {
358-
if let Some(primary_rule) = &self.primary_rule {
359-
if Arc::ptr_eq(r, primary_rule) {
360-
continue;
361-
}
360+
if let Some(primary_rule) = &self.primary_rule
361+
&& Arc::ptr_eq(r, primary_rule)
362+
{
363+
continue;
362364
}
363365
self.fill_dep_node_from_rule(output, r, &mut n);
364366
if n.loc.is_none() {
@@ -761,18 +763,18 @@ impl<'a> DepBuilder<'a> {
761763
fn pick_rule(&mut self, output: Symbol, n: &Arc<Mutex<DepNode>>) -> Option<PickedRuleInfo> {
762764
let rule_merger = self.lookup_rule_merger(output);
763765
let vars = self.lookup_rule_vars(output);
764-
if let Some(rule_merger) = &rule_merger {
765-
if rule_merger.lock().primary_rule.is_some() {
766-
let mut vars = vars;
767-
for (sym, _) in &rule_merger.lock().implicit_outputs {
768-
vars = self.merge_implicit_rule_vars(*sym, vars);
769-
}
770-
return Some(PickedRuleInfo {
771-
merger: Some(rule_merger.clone()),
772-
pattern_rule: None,
773-
vars,
774-
});
766+
if let Some(rule_merger) = &rule_merger
767+
&& rule_merger.lock().primary_rule.is_some()
768+
{
769+
let mut vars = vars;
770+
for (sym, _) in &rule_merger.lock().implicit_outputs {
771+
vars = self.merge_implicit_rule_vars(*sym, vars);
775772
}
773+
return Some(PickedRuleInfo {
774+
merger: Some(rule_merger.clone()),
775+
pattern_rule: None,
776+
vars,
777+
});
776778
}
777779

778780
let irules = self.implicit_rules.get(&output.as_bytes());
@@ -891,17 +893,17 @@ impl<'a> DepBuilder<'a> {
891893
let Some(mut picked_rule_info) = self.pick_rule(output, &n) else {
892894
return Ok(n);
893895
};
894-
if let Some(merger) = &picked_rule_info.merger {
895-
if merger.lock().parent.is_some() {
896-
output = merger.lock().parent_sym.unwrap();
897-
self.done.insert(output, n.clone());
898-
n.lock().output = output;
899-
let Some(new_picked_rule_info) = self.pick_rule(output, &n) else {
900-
return Ok(n);
901-
};
902-
// Update the picked_rule_info with the new values
903-
picked_rule_info = new_picked_rule_info;
904-
}
896+
if let Some(merger) = &picked_rule_info.merger
897+
&& merger.lock().parent.is_some()
898+
{
899+
output = merger.lock().parent_sym.unwrap();
900+
self.done.insert(output, n.clone());
901+
n.lock().output = output;
902+
let Some(new_picked_rule_info) = self.pick_rule(output, &n) else {
903+
return Ok(n);
904+
};
905+
// Update the picked_rule_info with the new values
906+
picked_rule_info = new_picked_rule_info;
905907
}
906908
let output_str = output.as_bytes();
907909

src-rs/eval.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ impl IncludeGraph {
217217
if frame.frame_type == FrameType::Parse {
218218
self.nodes.entry(frame.name.clone()).or_default();
219219

220-
if let Some(parent_frame) = self.include_stack.last() {
221-
if let Some(parent_node) = self.nodes.get_mut(&parent_frame.name) {
222-
parent_node.includes.insert(frame.name.clone());
223-
}
220+
if let Some(parent_frame) = self.include_stack.last()
221+
&& let Some(parent_node) = self.nodes.get_mut(&parent_frame.name)
222+
{
223+
parent_node.includes.insert(frame.name.clone());
224224
}
225225

226226
self.include_stack.push(frame.clone());
@@ -464,10 +464,8 @@ impl Evaluator {
464464
if let Some(prev) = prev {
465465
let prev = prev.read();
466466
prev.used(self, &lhs)?;
467-
if needs_assign {
468-
if let Some(deprecated) = &prev.deprecated {
469-
result.write().deprecated = Some(deprecated.clone());
470-
}
467+
if needs_assign && let Some(deprecated) = &prev.deprecated {
468+
result.write().deprecated = Some(deprecated.clone());
471469
}
472470
}
473471

@@ -686,17 +684,11 @@ impl Evaluator {
686684

687685
// If variable name is not empty, we have rule- or target-specific
688686
// variable assignment.
689-
if separator == Some(b'=') {
690-
if let Some(separator_pos) = separator_pos {
691-
if separator_pos > 0 {
692-
return self.eval_rule_specific_assign(
693-
&targets,
694-
stmt,
695-
&after_targets,
696-
separator_pos,
697-
);
698-
}
699-
}
687+
if separator == Some(b'=')
688+
&& let Some(separator_pos) = separator_pos
689+
&& separator_pos > 0
690+
{
691+
return self.eval_rule_specific_assign(&targets, stmt, &after_targets, separator_pos);
700692
}
701693

702694
if separator_pos == Some(0) {
@@ -914,17 +906,17 @@ impl Evaluator {
914906
for tok in word_scanner(&exports) {
915907
let equal_index = memchr(b'=', tok);
916908
let lhs;
917-
if equal_index.is_none() {
918-
lhs = tok;
919-
} else if equal_index == Some(0)
909+
if equal_index == Some(0)
920910
|| (equal_index == Some(1)
921911
&& (tok.starts_with(b":") || tok.starts_with(b"?") || tok.starts_with(b"+")))
922912
{
923913
// Do not export tokens after an assignment.
924914
break;
925-
} else {
926-
let assign = parse_assign_statement(tok, equal_index.unwrap());
915+
} else if let Some(equal_index) = equal_index {
916+
let assign = parse_assign_statement(tok, equal_index);
927917
lhs = assign.lhs;
918+
} else {
919+
lhs = tok;
928920
}
929921
let sym = intern(exports.slice_ref(lhs));
930922
self.exports.insert(sym, stmt.is_export);

src-rs/expr.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,15 @@ fn parse_dollar(loc: &mut Loc, s: Bytes, end_paren: bool) -> Result<(usize, Arc<
331331
if t.first() == Some(&cp) || (end_paren && t.is_empty() && cp == b')') {
332332
if let Value::Literal(_, lit) = &*vname {
333333
let sym = intern(lit.clone());
334-
if FLAGS.enable_kati_warnings {
335-
if let Some(found) = sym.to_string().find([' ', '(', '{']) {
336-
kati_warn_loc!(
337-
Some(&start_loc),
338-
"*warning*: variable lookup with '{}': {}",
339-
&sym.to_string()[found..found + 1],
340-
String::from_utf8_lossy(&s)
341-
)
342-
}
334+
if FLAGS.enable_kati_warnings
335+
&& let Some(found) = sym.to_string().find([' ', '(', '{'])
336+
{
337+
kati_warn_loc!(
338+
Some(&start_loc),
339+
"*warning*: variable lookup with '{}': {}",
340+
&sym.to_string()[found..found + 1],
341+
String::from_utf8_lossy(&s)
342+
)
343343
}
344344
return Ok((i + 1, Arc::new(Value::SymRef(start_loc, sym))));
345345
}
@@ -477,10 +477,11 @@ pub fn parse_expr_impl_ext(
477477

478478
let remaining = &s[i..];
479479
let c = remaining[0];
480-
if let Some(terms) = terms {
481-
if save_paren.is_none() && terms[terms_ignored..].contains(&c) {
482-
break;
483-
}
480+
if let Some(terms) = terms
481+
&& save_paren.is_none()
482+
&& terms[terms_ignored..].contains(&c)
483+
{
484+
break;
484485
}
485486

486487
// Handle a comment
@@ -515,15 +516,15 @@ pub fn parse_expr_impl_ext(
515516
continue;
516517
}
517518

518-
if let Some(terms) = terms {
519-
if terms[terms_ignored..].contains(&remaining[1]) {
520-
let val = Arc::new(Value::Literal(None, Bytes::from_static(b"$")));
521-
if list.is_empty() {
522-
return Ok((i + 1, val));
523-
}
524-
list.push(val);
525-
return Ok((i + 1, Arc::new(Value::List(Some(item_loc), list))));
519+
if let Some(terms) = terms
520+
&& terms[terms_ignored..].contains(&remaining[1])
521+
{
522+
let val = Arc::new(Value::Literal(None, Bytes::from_static(b"$")));
523+
if list.is_empty() {
524+
return Ok((i + 1, val));
526525
}
526+
list.push(val);
527+
return Ok((i + 1, Arc::new(Value::List(Some(item_loc), list))));
527528
}
528529

529530
let (n, v) = parse_dollar(loc, s.slice(i..), end_paren)?;
@@ -572,10 +573,10 @@ pub fn parse_expr_impl_ext(
572573
}
573574
if n == b'\r' || n == b'\n' {
574575
loc.line += 1;
575-
if let Some(terms) = terms {
576-
if terms.contains(&b' ') {
577-
break;
578-
}
576+
if let Some(terms) = terms
577+
&& terms.contains(&b' ')
578+
{
579+
break;
579580
}
580581
if i > b {
581582
list.push(Arc::new(Value::Literal(

src-rs/find.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ impl DirentNode {
199199
d: i32,
200200
out: &mut Vec<Vec<u8>>,
201201
) {
202-
if let Some(print_cond) = &fc.print_cond {
203-
if !print_cond.is_true(path, typ) {
204-
return;
205-
}
202+
if let Some(print_cond) = &fc.print_cond
203+
&& !print_cond.is_true(path, typ)
204+
{
205+
return;
206206
}
207207
if d < fc.mindepth {
208208
return;
@@ -1155,11 +1155,11 @@ impl FindEmulator {
11551155
loc: &Loc,
11561156
out: &mut BytesMut,
11571157
) -> Result<bool> {
1158-
if let Some(chdir) = &fc.chdir {
1159-
if !Self::can_handle(chdir) {
1160-
log!("FindEmulator: Cannot handle chdir ({chdir:?}): {cmd:?}");
1161-
return Ok(false);
1162-
}
1158+
if let Some(chdir) = &fc.chdir
1159+
&& !Self::can_handle(chdir)
1160+
{
1161+
log!("FindEmulator: Cannot handle chdir ({chdir:?}): {cmd:?}");
1162+
return Ok(false);
11631163
}
11641164

11651165
if let Some(testdir) = &fc.testdir {

src-rs/func.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ use crate::{
5151

5252
type MakeFuncImpl = fn(&[Arc<Value>], &mut Evaluator, &mut dyn BufMut) -> Result<()>;
5353

54-
#[derive(PartialEq)]
5554
pub struct FuncInfo {
5655
pub name: &'static [u8],
5756
pub func: MakeFuncImpl,
@@ -63,6 +62,13 @@ pub struct FuncInfo {
6362
pub trim_right_space_1st: bool,
6463
}
6564

65+
// Function pointers are not comparable, so just compare by name
66+
impl PartialEq for FuncInfo {
67+
fn eq(&self, other: &Self) -> bool {
68+
self.name == other.name
69+
}
70+
}
71+
6672
impl Debug for FuncInfo {
6773
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6874
write!(f, "Func({})", String::from_utf8_lossy(self.name))
@@ -556,12 +562,11 @@ fn shell_func_impl(
556562
) -> Result<(i32, Bytes, Option<FindCommand>)> {
557563
log!("ShellFunc: {:?}", cmd);
558564

559-
if FLAGS.use_find_emulator {
560-
if let Some(fc) = crate::find::parse(cmd)? {
561-
if let Some(out) = crate::find::find(cmd, &fc, loc)? {
562-
return Ok((0, out, Some(fc)));
563-
}
564-
}
565+
if FLAGS.use_find_emulator
566+
&& let Some(fc) = crate::find::parse(cmd)?
567+
&& let Some(out) = crate::find::find(cmd, &fc, loc)?
568+
{
569+
return Ok((0, out, Some(fc)));
565570
}
566571

567572
collect_stats_with_slow_report!("func shell time", OsStr::from_bytes(cmd));

src-rs/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ fn main() {
363363
}
364364
}
365365

366-
if let Some(working_dir) = &FLAGS.working_dir {
367-
if let Err(e) = std::env::set_current_dir(working_dir) {
368-
eprintln!("*** {}: {}", working_dir.to_string_lossy(), e);
369-
std::process::exit(1);
370-
}
366+
if let Some(working_dir) = &FLAGS.working_dir
367+
&& let Err(e) = std::env::set_current_dir(working_dir)
368+
{
369+
eprintln!("*** {}: {}", working_dir.to_string_lossy(), e);
370+
std::process::exit(1);
371371
}
372372
let orig_args = std::env::args_os()
373373
.collect::<Vec<OsString>>()

src-rs/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ pub struct ParsedAssign<'a> {
668668
pub rhs: &'a [u8],
669669
pub op: AssignOp,
670670
}
671-
pub fn parse_assign_statement(line: &[u8], sep: usize) -> ParsedAssign {
671+
pub fn parse_assign_statement(line: &[u8], sep: usize) -> ParsedAssign<'_> {
672672
assert!(sep != 0);
673673
let mut op = AssignOp::Eq;
674674
let mut lhs = &line[..sep];

0 commit comments

Comments
 (0)