difftreelog
style fix clippy warnings
in: master
8 files changed
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -31,7 +31,6 @@
pathdiff = "0.2.0"
closure = "0.3.0"
-indexmap = "1.6"
md5 = "0.7.0"
base64 = "0.13.0"
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -585,8 +585,7 @@
name: &str,
args: &ArgsDesc,
) -> Result<Val> {
- if let Some(f) = BUILTINS.with(|builtins| builtins.get(name).copied()) {
- return Ok(f(context, loc, args)?);
- }
- throw!(IntrinsicNotFound(name.into()))
+ BUILTINS.with(|builtins| builtins.get(name).copied()).ok_or_else(||
+ IntrinsicNotFound(name.into())
+ )?(context, loc, args)
}
crates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -222,12 +222,12 @@
let future_this = FutureObjValue::new();
let context_creator = context_creator!(
closure!(clone context, clone new_bindings, |this: Option<ObjValue>, super_obj: Option<ObjValue>| {
- Ok(context.clone().extend_unbound(
+ context.clone().extend_unbound(
new_bindings.clone().unwrap(),
context.dollar().clone().or_else(||this.clone()),
Some(this.unwrap()),
super_obj
- )?)
+ )
})
);
{
@@ -327,12 +327,12 @@
let new_bindings = FutureNewBindings::new();
let context_creator = context_creator!(
closure!(clone context, clone new_bindings, |this: Option<ObjValue>, super_obj: Option<ObjValue>| {
- Ok(context.clone().extend_unbound(
+ context.clone().extend_unbound(
new_bindings.clone().unwrap(),
context.dollar().clone().or_else(||this.clone()),
None,
super_obj
- )?)
+ )
})
);
let mut bindings: HashMap<IStr, LazyBinding> = HashMap::new();
@@ -439,7 +439,7 @@
Var(name) => push(
loc.as_ref(),
|| format!("variable <{}>", name),
- || Ok(context.binding(name.clone())?.evaluate()?),
+ || context.binding(name.clone())?.evaluate(),
)?,
Index(value, index) => {
match (evaluate(context.clone(), value)?, evaluate(context, index)?) {
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -344,11 +344,11 @@
None,
|| "during TLA call".to_owned(),
|| {
- Ok(func.evaluate_map(
+ func.evaluate_map(
self.create_default_context()?,
&self.settings().tla_vars,
true,
- )?)
+ )
},
)?,
v => v,
@@ -432,7 +432,7 @@
Ok(self.settings().import_resolver.resolve_file(from, path)?)
}
pub fn load_file_contents(&self, path: &PathBuf) -> Result<IStr> {
- Ok(self.settings().import_resolver.load_file_contents(path)?)
+ self.settings().import_resolver.load_file_contents(path)
}
pub fn import_resolver(&self) -> Ref<dyn ImportResolver> {
@@ -548,8 +548,8 @@
.to_json(0)
.unwrap()
.replace("\n", "")
- })
- }};
+ })
+ }};
}
/// Asserts given code returns `true`
crates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed.rs
+++ b/crates/jrsonnet-evaluator/src/typed.rs
@@ -16,8 +16,8 @@
match $value {
$match(v) => v,
_ => unreachable!(),
- }
- }};
+ }
+ }};
}
#[derive(Debug, Error, Clone)]
@@ -177,7 +177,7 @@
None,
|| format!("array index {}", i),
|| ValuePathItem::Index(i as u64),
- || Ok(elem_type.check(&item.clone()?)?),
+ || elem_type.check(&item.clone()?),
)?;
}
Ok(())
@@ -191,7 +191,7 @@
None,
|| format!("array index {}", i),
|| ValuePathItem::Index(i as u64),
- || Ok(elem_type.check(&item.clone()?)?),
+ || elem_type.check(&item.clone()?),
)?;
}
Ok(())
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -343,7 +343,7 @@
match $e {
$p => $r,
_ => panic!("no match"),
- }
+ }
};
}
impl Val {
@@ -537,7 +537,7 @@
let ctx = s
.create_default_context()?
.with_var("__tmp__to_json__".into(), self.clone());
- Ok(evaluate(
+ evaluate(
ctx,
&el!(Expr::Apply(
el!(Expr::Index(
@@ -558,7 +558,7 @@
false
)),
)?
- .try_cast_str("to json")?)
+ .try_cast_str("to json")
})
}
}
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth1use jrsonnet_interner::IStr;2#[cfg(feature = "deserialize")]3use serde::Deserialize;4#[cfg(feature = "serialize")]5use serde::Serialize;6use std::{7 fmt::{Debug, Display},8 ops::Deref,9 path::PathBuf,10 rc::Rc,11};1213#[cfg_attr(feature = "serialize", derive(Serialize))]14#[cfg_attr(feature = "deserialize", derive(Deserialize))]15#[derive(Debug, PartialEq)]16pub enum FieldName {17 /// {fixed: 2}18 Fixed(IStr),19 /// {["dyn"+"amic"]: 3}20 Dyn(LocExpr),21}2223#[cfg_attr(feature = "serialize", derive(Serialize))]24#[cfg_attr(feature = "deserialize", derive(Deserialize))]25#[derive(Debug, Clone, Copy, PartialEq)]26pub enum Visibility {27 /// :28 Normal,29 /// ::30 Hidden,31 /// :::32 Unhide,33}3435impl Visibility {36 pub fn is_visible(&self) -> bool {37 matches!(self, Self::Normal | Self::Unhide)38 }39}4041#[cfg_attr(feature = "serialize", derive(Serialize))]42#[cfg_attr(feature = "deserialize", derive(Deserialize))]43#[derive(Debug, PartialEq)]44pub struct AssertStmt(pub LocExpr, pub Option<LocExpr>);4546#[cfg_attr(feature = "serialize", derive(Serialize))]47#[cfg_attr(feature = "deserialize", derive(Deserialize))]48#[derive(Debug, PartialEq)]49pub struct FieldMember {50 pub name: FieldName,51 pub plus: bool,52 pub params: Option<ParamsDesc>,53 pub visibility: Visibility,54 pub value: LocExpr,55}5657#[cfg_attr(feature = "serialize", derive(Serialize))]58#[cfg_attr(feature = "deserialize", derive(Deserialize))]59#[derive(Debug, PartialEq)]60pub enum Member {61 Field(FieldMember),62 BindStmt(BindSpec),63 AssertStmt(AssertStmt),64}6566#[cfg_attr(feature = "serialize", derive(Serialize))]67#[cfg_attr(feature = "deserialize", derive(Deserialize))]68#[derive(Debug, Clone, Copy, PartialEq)]69pub enum UnaryOpType {70 Plus,71 Minus,72 BitNot,73 Not,74}75impl Display for UnaryOpType {76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {77 use UnaryOpType::*;78 write!(79 f,80 "{}",81 match self {82 Plus => "+",83 Minus => "-",84 BitNot => "~",85 Not => "!",86 }87 )88 }89}9091#[cfg_attr(feature = "serialize", derive(Serialize))]92#[cfg_attr(feature = "deserialize", derive(Deserialize))]93#[derive(Debug, Clone, Copy, PartialEq)]94pub enum BinaryOpType {95 Mul,96 Div,9798 /// Implemented as intrinsic, put here for completeness99 Mod,100101 Add,102 Sub,103104 Lhs,105 Rhs,106107 Lt,108 Gt,109 Lte,110 Gte,111112 BitAnd,113 BitOr,114 BitXor,115116 And,117 Or,118}119impl Display for BinaryOpType {120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {121 use BinaryOpType::*;122 write!(123 f,124 "{}",125 match self {126 Mul => "*",127 Div => "/",128 Mod => "%",129 Add => "+",130 Sub => "-",131 Lhs => "<<",132 Rhs => ">>",133 Lt => "<",134 Gt => ">",135 Lte => "<=",136 Gte => ">=",137 BitAnd => "&",138 BitOr => "|",139 BitXor => "^",140 And => "&&",141 Or => "||",142 }143 )144 }145}146147/// name, default value148#[cfg_attr(feature = "serialize", derive(Serialize))]149#[cfg_attr(feature = "deserialize", derive(Deserialize))]150#[derive(Debug, PartialEq)]151pub struct Param(pub IStr, pub Option<LocExpr>);152153/// Defined function parameters154#[cfg_attr(feature = "serialize", derive(Serialize))]155#[cfg_attr(feature = "deserialize", derive(Deserialize))]156#[derive(Debug, Clone, PartialEq)]157pub struct ParamsDesc(pub Rc<Vec<Param>>);158impl Deref for ParamsDesc {159 type Target = Vec<Param>;160 fn deref(&self) -> &Self::Target {161 &self.0162 }163}164165#[cfg_attr(feature = "serialize", derive(Serialize))]166#[cfg_attr(feature = "deserialize", derive(Deserialize))]167#[derive(Debug, PartialEq)]168pub struct Arg(pub Option<String>, pub LocExpr);169170#[cfg_attr(feature = "serialize", derive(Serialize))]171#[cfg_attr(feature = "deserialize", derive(Deserialize))]172#[derive(Debug, PartialEq)]173pub struct ArgsDesc(pub Vec<Arg>);174impl Deref for ArgsDesc {175 type Target = Vec<Arg>;176 fn deref(&self) -> &Self::Target {177 &self.0178 }179}180181#[cfg_attr(feature = "serialize", derive(Serialize))]182#[cfg_attr(feature = "deserialize", derive(Deserialize))]183#[derive(Debug, Clone, PartialEq)]184pub struct BindSpec {185 pub name: IStr,186 pub params: Option<ParamsDesc>,187 pub value: LocExpr,188}189190#[cfg_attr(feature = "serialize", derive(Serialize))]191#[cfg_attr(feature = "deserialize", derive(Deserialize))]192#[derive(Debug, PartialEq)]193pub struct IfSpecData(pub LocExpr);194195#[cfg_attr(feature = "serialize", derive(Serialize))]196#[cfg_attr(feature = "deserialize", derive(Deserialize))]197#[derive(Debug, PartialEq)]198pub struct ForSpecData(pub IStr, pub LocExpr);199200#[cfg_attr(feature = "serialize", derive(Serialize))]201#[cfg_attr(feature = "deserialize", derive(Deserialize))]202#[derive(Debug, PartialEq)]203pub enum CompSpec {204 IfSpec(IfSpecData),205 ForSpec(ForSpecData),206}207208#[cfg_attr(feature = "serialize", derive(Serialize))]209#[cfg_attr(feature = "deserialize", derive(Deserialize))]210#[derive(Debug, PartialEq)]211pub struct ObjComp {212 pub pre_locals: Vec<BindSpec>,213 pub key: LocExpr,214 pub value: LocExpr,215 pub post_locals: Vec<BindSpec>,216 pub compspecs: Vec<CompSpec>,217}218219#[cfg_attr(feature = "serialize", derive(Serialize))]220#[cfg_attr(feature = "deserialize", derive(Deserialize))]221#[derive(Debug, PartialEq)]222pub enum ObjBody {223 MemberList(Vec<Member>),224 ObjComp(ObjComp),225}226227#[cfg_attr(feature = "serialize", derive(Serialize))]228#[cfg_attr(feature = "deserialize", derive(Deserialize))]229#[derive(Debug, PartialEq, Clone, Copy)]230pub enum LiteralType {231 This,232 Super,233 Dollar,234 Null,235 True,236 False,237}238239#[derive(Debug, PartialEq)]240pub struct SliceDesc {241 pub start: Option<LocExpr>,242 pub end: Option<LocExpr>,243 pub step: Option<LocExpr>,244}245246/// Syntax base247#[cfg_attr(feature = "serialize", derive(Serialize))]248#[cfg_attr(feature = "deserialize", derive(Deserialize))]249#[derive(Debug, PartialEq)]250pub enum Expr {251 Literal(LiteralType),252253 /// String value: "hello"254 Str(IStr),255 /// Number: 1, 2.0, 2e+20256 Num(f64),257 /// Variable name: test258 Var(IStr),259260 /// Array of expressions: [1, 2, "Hello"]261 Arr(Vec<LocExpr>),262 /// Array comprehension:263 /// ```jsonnet264 /// ingredients: [265 /// { kind: kind, qty: 4 / 3 }266 /// for kind in [267 /// 'Honey Syrup',268 /// 'Lemon Juice',269 /// 'Farmers Gin',270 /// ]271 /// ],272 /// ```273 ArrComp(LocExpr, Vec<CompSpec>),274275 /// Object: {a: 2}276 Obj(ObjBody),277 /// Object extension: var1 {b: 2}278 ObjExtend(LocExpr, ObjBody),279280 /// (obj)281 Parened(LocExpr),282283 /// -2284 UnaryOp(UnaryOpType, LocExpr),285 /// 2 - 2286 BinaryOp(LocExpr, BinaryOpType, LocExpr),287 /// assert 2 == 2 : "Math is broken"288 AssertExpr(AssertStmt, LocExpr),289 /// local a = 2; { b: a }290 LocalExpr(Vec<BindSpec>, LocExpr),291292 /// import "hello"293 Import(PathBuf),294 /// importStr "file.txt"295 ImportStr(PathBuf),296 /// error "I'm broken"297 ErrorStmt(LocExpr),298 /// a(b, c)299 Apply(LocExpr, ArgsDesc, bool),300 /// a[b]301 Index(LocExpr, LocExpr),302 /// function(x) x303 Function(ParamsDesc, LocExpr),304 /// std.primitiveEquals305 Intrinsic(IStr),306 /// if true == false then 1 else 2307 IfElse {308 cond: IfSpecData,309 cond_then: LocExpr,310 cond_else: Option<LocExpr>,311 },312}313314/// file, begin offset, end offset315#[cfg_attr(feature = "serialize", derive(Serialize))]316#[cfg_attr(feature = "deserialize", derive(Deserialize))]317#[derive(Clone, PartialEq)]318pub struct ExprLocation(pub Rc<PathBuf>, pub usize, pub usize);319impl Debug for ExprLocation {320 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {321 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)322 }323}324325/// Holds AST expression and its location in source file326#[cfg_attr(feature = "serialize", derive(Serialize))]327#[cfg_attr(feature = "deserialize", derive(Deserialize))]328#[derive(Clone, PartialEq)]329pub struct LocExpr(pub Rc<Expr>, pub Option<ExprLocation>);330impl Debug for LocExpr {331 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {332 write!(f, "{:?} from {:?}", self.0, self.1)333 }334}335336/// Creates LocExpr from Expr and ExprLocation components337#[macro_export]338macro_rules! loc_expr {339 ($expr:expr, $need_loc:expr,($name:expr, $start:expr, $end:expr)) => {340 LocExpr(341 std::rc::Rc::new($expr),342 if $need_loc {343 Some(ExprLocation($name, $start, $end))344 } else {345 None346 },347 )348 };349}350351/// Creates LocExpr without location info352#[macro_export]353macro_rules! loc_expr_todo {354 ($expr:expr) => {355 LocExpr(Rc::new($expr), None)356 };357}crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -319,8 +319,8 @@
&ParserSettings {
loc_data: false,
file_name: Rc::new(PathBuf::from("/test.jsonnet")),
- },
- )
+ },
+ )
.unwrap()
};
}