--- a/crates/jsonnet-evaluator/src/evaluate.rs +++ b/crates/jsonnet-evaluator/src/evaluate.rs @@ -152,7 +152,7 @@ context.clone().extend( new_bindings.clone().unwrap(), context.clone().dollar().clone().or_else(||this.clone()), - Some(this.clone().unwrap()), + Some(this.unwrap()), super_obj ) }) @@ -347,7 +347,7 @@ } ("std", "codepoint") => { assert_eq!(args.len(), 1); - if let Val::Str(s) = evaluate(context.clone(), &args[0].1) { + if let Val::Str(s) = evaluate(context, &args[0].1) { assert!( s.chars().count() == 1, "std.codepoint should receive single char string" --- a/crates/jsonnet-evaluator/src/obj.rs +++ b/crates/jsonnet-evaluator/src/obj.rs @@ -79,10 +79,7 @@ self.0.super_obj.clone(), )), (Some(k), Some(s)) => { - let our = k.invoke.0( - Some(real_this.clone()), - self.0.super_obj.clone(), - ); + let our = k.invoke.0(Some(real_this.clone()), self.0.super_obj.clone()); if k.add { s.get_raw(key, real_this).map_or(Some(our.clone()), |v| { Some(evaluate_binary_op(&v, BinaryOpType::Add, &our)) --- a/crates/jsonnet-parser/src/expr.rs +++ b/crates/jsonnet-parser/src/expr.rs @@ -83,11 +83,7 @@ pub struct ParamsDesc(pub Vec); impl ParamsDesc { pub fn with_defaults(&self) -> Vec { - self.0 - .iter() - .filter(|e| e.1.is_some()) - .map(|e| e.clone()) - .collect() + self.0.iter().filter(|e| e.1.is_some()).cloned().collect() } } --- a/crates/jsonnet-parser/src/lib.rs +++ b/crates/jsonnet-parser/src/lib.rs @@ -23,8 +23,8 @@ /// For comma-delimited elements rule comma() = quiet!{_ "," _} / expected!("") - rule alpha() -> char = c:$(['_' | 'a'..='z' | 'A'..='Z']) {c.chars().nth(0).unwrap()} - rule digit() -> char = d:$(['0'..='9']) {d.chars().nth(0).unwrap()} + rule alpha() -> char = c:$(['_' | 'a'..='z' | 'A'..='Z']) {c.chars().next().unwrap()} + rule digit() -> char = d:$(['0'..='9']) {d.chars().next().unwrap()} rule end_of_ident() = !['0'..='9' | '_' | 'a'..='z' | 'A'..='Z'] /// Sequence of digits rule uint() -> u32 = a:$(digit()+) { a.parse().unwrap() } @@ -106,7 +106,7 @@ value, post_locals, first, - rest: rest.unwrap_or(Vec::new()), + rest: rest.unwrap_or_default(), } } / members:(member() ** comma()) comma()? {expr::ObjBody::MemberList(members)} @@ -119,7 +119,7 @@ pub rule parened_expr() -> Expr = "(" e:boxed_expr() ")" {Expr::Parened(e)} pub rule obj_expr() -> Expr = "{" _ body:objinside() _ "}" {Expr::Obj(body)} pub rule array_expr() -> Expr = "[" _ elems:(expr() ** comma()) _ comma()? "]" {Expr::Arr(elems)} - pub rule array_comp_expr() -> Expr = "[" _ expr:boxed_expr() _ comma()? _ forspec:forspec() _ others:(others: compspec() _ {others})? "]" {Expr::ArrComp(expr, forspec, others.unwrap_or(vec![]))} + pub rule array_comp_expr() -> Expr = "[" _ expr:boxed_expr() _ comma()? _ forspec:forspec() _ others:(others: compspec() _ {others})? "]" {Expr::ArrComp(expr, forspec, others.unwrap_or_default())} pub rule index_expr() -> Expr = val:boxed_expr() "." idx:id() {Expr::Index(val, Box::new(Expr::Str(idx)))} / val:boxed_expr() "[" key:boxed_expr() "]" {Expr::Index(val, key)} @@ -390,11 +390,14 @@ #[test] fn infix_precedence() { use Expr::*; - assert_eq!(parse("!a && !b").unwrap(), BinaryOp( - box UnaryOp(UnaryOpType::Not, box Var("a".to_owned())), - BinaryOpType::And, - box UnaryOp(UnaryOpType::Not, box Var("b".to_owned())) - )); + assert_eq!( + parse("!a && !b").unwrap(), + BinaryOp( + box UnaryOp(UnaryOpType::Not, box Var("a".to_owned())), + BinaryOpType::And, + box UnaryOp(UnaryOpType::Not, box Var("b".to_owned())) + ) + ); } #[test]