difftreelog
style fix rustfmt and clippy warnings
in: master
4 files changed
crates/jsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- 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"
crates/jsonnet-evaluator/src/obj.rsdiffbeforeafterboth1use crate::{evaluate_binary_op, Binding, Val};2use jsonnet_parser::{BinaryOpType, Visibility};3use std::{4 collections::{BTreeMap, BTreeSet},5 fmt::Debug,6 rc::Rc,7};89#[derive(Debug)]10pub struct ObjMember {11 pub add: bool,12 pub visibility: Visibility,13 pub invoke: Binding,14}1516#[derive(Debug)]17pub struct ObjValueInternals {18 super_obj: Option<ObjValue>,19 this_entries: Rc<BTreeMap<String, ObjMember>>,20}21pub struct ObjValue(pub(crate) Rc<ObjValueInternals>);22impl Debug for ObjValue {23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {24 if let Some(super_obj) = self.0.super_obj.as_ref() {25 if f.alternate() {26 write!(f, "{:#?}", super_obj)?;27 } else {28 write!(f, "{:?}", super_obj)?;29 }30 write!(f, " + ")?;31 }32 let mut debug = f.debug_struct("ObjValue");33 debug.field("$ptr", &Rc::as_ptr(&self.0));34 for (name, member) in self.0.this_entries.iter() {35 debug.field(name, member);36 }37 debug.finish_non_exhaustive()38 // .field("fields", &self.fields())39 // .finish_non_exhaustive()40 }41}4243impl ObjValue {44 pub fn new(45 super_obj: Option<ObjValue>,46 this_entries: Rc<BTreeMap<String, ObjMember>>,47 ) -> ObjValue {48 ObjValue(Rc::new(ObjValueInternals {49 super_obj,50 this_entries,51 }))52 }53 pub fn with_super(&self, super_obj: ObjValue) -> ObjValue {54 match &self.0.super_obj {55 None => ObjValue::new(Some(super_obj), self.0.this_entries.clone()),56 Some(v) => ObjValue::new(Some(v.with_super(super_obj)), self.0.this_entries.clone()),57 }58 }59 pub fn fields(&self) -> BTreeSet<String> {60 let mut fields = BTreeSet::new();61 self.0.this_entries.keys().for_each(|k| {62 fields.insert(k.clone());63 });64 if self.0.super_obj.is_some() {65 for field in self.0.super_obj.clone().unwrap().fields() {66 fields.insert(field);67 }68 }69 fields70 }71 pub fn get(&self, key: &str) -> Option<Val> {72 // TODO: Cache get_raw result73 self.get_raw(key, self)74 }75 fn get_raw(&self, key: &str, real_this: &ObjValue) -> Option<Val> {76 match (self.0.this_entries.get(key), &self.0.super_obj) {77 (Some(k), None) => Some(k.invoke.0(78 Some(real_this.clone()),79 self.0.super_obj.clone(),80 )),81 (Some(k), Some(s)) => {82 let our = k.invoke.0(83 Some(real_this.clone()),84 self.0.super_obj.clone(),85 );86 if k.add {87 s.get_raw(key, real_this).map_or(Some(our.clone()), |v| {88 Some(evaluate_binary_op(&v, BinaryOpType::Add, &our))89 })90 } else {91 Some(our)92 }93 }94 (None, Some(s)) => s.get_raw(key, real_this),95 (None, None) => None,96 }97 }98}99impl Clone for ObjValue {100 fn clone(&self) -> Self {101 ObjValue(self.0.clone())102 }103}104impl PartialEq for ObjValue {105 fn eq(&self, other: &Self) -> bool {106 Rc::ptr_eq(&self.0, &other.0)107 }108}crates/jsonnet-parser/src/expr.rsdiffbeforeafterboth--- a/crates/jsonnet-parser/src/expr.rs
+++ b/crates/jsonnet-parser/src/expr.rs
@@ -83,11 +83,7 @@
pub struct ParamsDesc(pub Vec<Param>);
impl ParamsDesc {
pub fn with_defaults(&self) -> Vec<Param> {
- 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()
}
}
crates/jsonnet-parser/src/lib.rsdiffbeforeafterboth--- 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!("<comma>")
- 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]