From 2626697d24fc6b975371eb7a81ec033099b46012 Mon Sep 17 00:00:00 2001 From: Kavi Gupta Date: Mon, 28 Jul 2025 17:18:34 -0400 Subject: [PATCH] lint --- src/domains/prim_lists.rs | 6 +++--- src/parse_expr.rs | 34 +++++++++++++++++----------------- src/parse_type.rs | 6 +++--- src/slow_types.rs | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/domains/prim_lists.rs b/src/domains/prim_lists.rs index 4b444d8..1b60df4 100644 --- a/src/domains/prim_lists.rs +++ b/src/domains/prim_lists.rs @@ -239,7 +239,7 @@ pub static FIX: Lazy = Lazy::new(|| PrimFun(CurriedFn::new(Symbol::from("fi fn fix(mut args: Env, handle: &Evaluator) -> VResult { handle.data.borrow_mut().fix_counter += 1; if handle.data.borrow().fix_counter > MAX_FIX_INVOCATIONS { - return Err(format!("Exceeded max number of fix invocations. Max was {}", MAX_FIX_INVOCATIONS)); + return Err(format!("Exceeded max number of fix invocations. Max was {MAX_FIX_INVOCATIONS}")); } load_args!(args, fn_val: Val, x: Val); @@ -247,7 +247,7 @@ fn fix(mut args: Env, handle: &Evaluator) -> VResult { let fixf = handle.apply(FIX.clone(), fn_val.clone()).unwrap(); let res = match handle.apply(fn_val, fixf) { Ok(ffixf) => handle.apply(ffixf, x), - Err(err) => Err(format!("Could not apply fixf to f: {}",err)) + Err(err) => Err(format!("Could not apply fixf to f: {err}")) }; handle.data.borrow_mut().fix_counter -= 1; res @@ -336,6 +336,6 @@ mod tests { assert_error::( "(fix1 $0 (lam (lam (if (empty? $0) $0 (cons (+ 1 (car $0)) ($1 $0))))))", &[arg], - format!("Exceeded max number of fix invocations. Max was {}", MAX_FIX_INVOCATIONS)); + format!("Exceeded max number of fix invocations. Max was {MAX_FIX_INVOCATIONS}")); } } \ No newline at end of file diff --git a/src/parse_expr.rs b/src/parse_expr.rs index c80b818..eb6a78f 100644 --- a/src/parse_expr.rs +++ b/src/parse_expr.rs @@ -17,22 +17,22 @@ impl Display for Node { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { Self::Var(i, tag) => { - write!(f, "${}", i)?; + write!(f, "${i}")?; if *tag != -1 { - write!(f, "_{}", tag)?; + write!(f, "_{tag}")?; } Ok(()) }, - Self::Prim(p) => write!(f,"{}",p), + Self::Prim(p) => write!(f,"{p}"), Self::App(_,_) => write!(f,"app"), Self::Lam(_, tag) => { write!(f,"lam")?; if *tag != -1 { - write!(f, "_{}", tag)?; + write!(f, "_{tag}")?; } Ok(()) }, - Self::IVar(i) => write!(f,"#{}",i), + Self::IVar(i) => write!(f,"#{i}"), } } } @@ -57,7 +57,7 @@ impl<'a> Display for Expr<'a> { Node::Lam(b, tag) => { write!(f,"(lam")?; if *tag != -1 { - write!(f, "_{}", tag)?; + write!(f, "_{tag}")?; } write!(f," ")?; fmt_local(e.get(*b), false, f)?; @@ -92,7 +92,7 @@ impl ExprSet { let next = s.chars().last().unwrap(); if next == '(' { s = &s[..s.len()-1]; - let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {}",s_init))?; + let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {s_init}"))?; if num_items == 0 { continue } @@ -110,7 +110,7 @@ impl ExprSet { if let Some(num_items) = items_of_depth.last_mut() { *num_items += 1; } else { - return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init)); + return Err(format!("ExprSet parse error: mismatched parens in: {s_init}")); } continue } @@ -151,37 +151,37 @@ impl ExprSet { split.next().unwrap(); // strip "lam" tag = split.next().unwrap().parse::().map_err(|e|e.to_string())?; if tag < 0 { - return Err(format!("ExprSet parse error: lambda tag must be non-negative: {}", s_init)) + return Err(format!("ExprSet parse error: lambda tag must be non-negative: {s_init}")) } } // println!("remainder: {}",s); let mut eof = false; if let Some(c) = s.chars().last() { if c != '(' { - return Err(format!("ExprSet parse error: `lam` must always have an immediately preceding parenthesis like so `(lam` unless its at the start of the parsed string: {}",s_init)) + return Err(format!("ExprSet parse error: `lam` must always have an immediately preceding parenthesis like so `(lam` unless its at the start of the parsed string: {s_init}")) } s = &s[..s.len()-1]; // strip "(" } else { eof = true; }; - let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {}",s_init))?; + let num_items = items_of_depth.pop().ok_or_else(||format!("ExprSet parse error: mismatched parens in: {s_init}"))?; if num_items != 1 { - return Err(format!("ExprSet parse error: `lam` must always be applied to exactly one argument, like `(lam (foo bar))`: {}",s_init)) + return Err(format!("ExprSet parse error: `lam` must always be applied to exactly one argument, like `(lam (foo bar))`: {s_init}")) } let b: Idx = items.pop().unwrap(); items.push(self.add(Node::Lam(b, tag))); // println!("added lam"); if eof { if items.len() != 1 { - return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init)); + return Err(format!("ExprSet parse error: mismatched parens in: {s_init}")); } return Ok(items.pop().unwrap()) } if let Some(num_items) = items_of_depth.last_mut() { *num_items += 1; } else { - return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init)); + return Err(format!("ExprSet parse error: mismatched parens in: {s_init}")); } continue } @@ -195,7 +195,7 @@ impl ExprSet { rest = split.next().unwrap(); tag = split.next().unwrap().parse::().map_err(|e|e.to_string())?; if tag < 0 { - return Err(format!("ExprSet parse error: variable tag must be non-negative: {}", s_init)) + return Err(format!("ExprSet parse error: variable tag must be non-negative: {s_init}")) } } Node::Var(rest.parse::().map_err(|e|e.to_string())?, tag) @@ -214,7 +214,7 @@ impl ExprSet { } if items_of_depth.len() != 1 { - return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init)); + return Err(format!("ExprSet parse error: mismatched parens in: {s_init}")); } let num_items = items_of_depth.pop().unwrap(); @@ -226,7 +226,7 @@ impl ExprSet { items.push(self.add(Node::App(f, x))) } if items.len() != 1 { - return Err(format!("ExprSet parse error: mismatched parens in: {}",s_init)); + return Err(format!("ExprSet parse error: mismatched parens in: {s_init}")); } if self.order == Order::ParentFirst { diff --git a/src/parse_type.rs b/src/parse_type.rs index 7b26d46..2e89cfb 100644 --- a/src/parse_type.rs +++ b/src/parse_type.rs @@ -6,9 +6,9 @@ use crate::*; /// this gets used by pub fn parse(s: &str) -> Result { - let (ty, s_left) = parse_aux(s).map_err(|e| format!("{}\n when parsing: {}", e, s))?; + let (ty, s_left) = parse_aux(s).map_err(|e| format!("{e}\n when parsing: {s}"))?; if !s_left.is_empty() { - return Err(format!("Type parse() error: extra closeparen\n when parsing: {}",s)) + return Err(format!("Type parse() error: extra closeparen\n when parsing: {s}")) } Ok(ty) } @@ -81,7 +81,7 @@ fn parse_aux(mut s: &str) -> Result<(SlowType, &str), String> { } // arrows are a low prio operator so group everything before into one term - let ty_left = finish(res).map_err(|s| format!("during arrow rearranging: {}",s))?; + let ty_left = finish(res).map_err(|s| format!("during arrow rearranging: {s}"))?; // parse everything to the right let (ty_right, s_new) = parse_aux(&s[1..])?; s = s_new; diff --git a/src/slow_types.rs b/src/slow_types.rs index 0577bcd..eb3d05c 100644 --- a/src/slow_types.rs +++ b/src/slow_types.rs @@ -170,10 +170,10 @@ impl std::fmt::Display for SlowType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn helper(ty: &SlowType, f: &mut std::fmt::Formatter<'_>, arrow_parens: bool) -> std::fmt::Result { match ty { - SlowType::Var(i) => write!(f,"t{}", i), + SlowType::Var(i) => write!(f,"t{i}"), SlowType::Term(name, args) => { if args.is_empty() { - write!(f, "{}", name) + write!(f, "{name}") } else if *name == *ARROW_SYM { assert_eq!(args.len(), 2); // write!(f, "({} {} {})", &args[0], name, &args[1]) @@ -188,7 +188,7 @@ impl std::fmt::Display for SlowType { } Ok(()) } else { - write!(f, "({}", name)?; + write!(f, "({name}")?; for arg in args.iter() { write!(f, " ")?; helper(arg, f, true)?; @@ -380,7 +380,7 @@ impl std::fmt::Display for Context { for (i, item) in self.subst_unionfind.iter().enumerate() { if let Some(ty) = item { if !first { write!(f, ", ")? } else { first = false } - write!(f, "{}:{}", i, ty)? + write!(f, "{i}:{ty}")? } } write!(f,"}}")