difftreelog
refactor Option<&ExprLocation> -> &Option<_>
in: master
6 files changed
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -22,7 +22,7 @@
fn std_format(str: IStr, vals: Val) -> Result<Val> {
push(
- &Some(ExprLocation(Rc::from(PathBuf::from("std.jsonnet")), 0, 0)),
+ Some(&ExprLocation(Rc::from(PathBuf::from("std.jsonnet")), 0, 0)),
|| format!("std.format of {}", str),
|| {
Ok(match vals {
@@ -34,7 +34,7 @@
)
}
-type Builtin = fn(context: Context, loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val>;
+type Builtin = fn(context: Context, loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val>;
type BuiltinsType = HashMap<Box<str>, Builtin>;
@@ -78,7 +78,7 @@
};
}
-fn builtin_length(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_length(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "length", args, 1, [
0, x: ty!((string | object | array));
], {
@@ -96,7 +96,7 @@
})
}
-fn builtin_type(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_type(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "type", args, 1, [
0, x: ty!(any);
], {
@@ -106,7 +106,7 @@
fn builtin_make_array(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "makeArray", args, 2, [
@@ -126,7 +126,7 @@
fn builtin_codepoint(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "codepoint", args, 1, [
@@ -138,7 +138,7 @@
fn builtin_object_fields_ex(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "objectFieldsEx", args, 2, [
@@ -157,7 +157,7 @@
fn builtin_object_has_ex(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "objectHasEx", args, 3, [
@@ -175,7 +175,7 @@
}
// faster
-fn builtin_slice(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_slice(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "slice", args, 4, [
0, indexable: ty!((string | array));
1, index: ty!((number | null));
@@ -216,7 +216,7 @@
// faster
fn builtin_primitive_equals(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "primitiveEquals", args, 2, [
@@ -228,7 +228,7 @@
}
// faster
-fn builtin_equals(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_equals(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "equals", args, 2, [
0, a: ty!(any);
1, b: ty!(any);
@@ -237,7 +237,7 @@
})
}
-fn builtin_modulo(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_modulo(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "modulo", args, 2, [
0, a: ty!(number) => Val::Num;
1, b: ty!(number) => Val::Num;
@@ -246,7 +246,7 @@
})
}
-fn builtin_mod(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_mod(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "mod", args, 2, [
0, a: ty!((number | string));
1, b: ty!(any);
@@ -259,7 +259,7 @@
})
}
-fn builtin_floor(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_floor(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "floor", args, 1, [
0, x: ty!(number) => Val::Num;
], {
@@ -267,7 +267,7 @@
})
}
-fn builtin_log(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_log(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "log", args, 1, [
0, n: ty!(number) => Val::Num;
], {
@@ -275,7 +275,7 @@
})
}
-fn builtin_pow(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_pow(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "pow", args, 2, [
0, x: ty!(number) => Val::Num;
1, n: ty!(number) => Val::Num;
@@ -284,7 +284,7 @@
})
}
-fn builtin_ext_var(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_ext_var(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "extVar", args, 1, [
0, x: ty!(string) => Val::Str;
], {
@@ -292,7 +292,7 @@
})
}
-fn builtin_native(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_native(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "native", args, 1, [
0, x: ty!(string) => Val::Str;
], {
@@ -300,7 +300,7 @@
})
}
-fn builtin_filter(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_filter(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "filter", args, 2, [
0, func: ty!(function) => Val::Func;
1, arr: ty!(array) => Val::Arr;
@@ -318,7 +318,7 @@
})
}
-fn builtin_foldl(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_foldl(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "foldl", args, 3, [
0, func: ty!(function) => Val::Func;
1, arr: ty!(array) => Val::Arr;
@@ -332,7 +332,7 @@
})
}
-fn builtin_foldr(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_foldr(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "foldr", args, 3, [
0, func: ty!(function) => Val::Func;
1, arr: ty!(array) => Val::Arr;
@@ -349,7 +349,7 @@
#[allow(non_snake_case)]
fn builtin_sort_impl(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "sort", args, 2, [
@@ -364,7 +364,7 @@
}
// faster
-fn builtin_format(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_format(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "format", args, 2, [
0, str: ty!(string) => Val::Str;
1, vals: ty!(any)
@@ -373,7 +373,7 @@
})
}
-fn builtin_range(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_range(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "range", args, 2, [
0, from: ty!(number) => Val::Num;
1, to: ty!(number) => Val::Num;
@@ -386,7 +386,7 @@
})
}
-fn builtin_char(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_char(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "char", args, 1, [
0, n: ty!(number) => Val::Num;
], {
@@ -400,7 +400,7 @@
fn builtin_encode_utf8(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "encodeUTF8", args, 1, [
@@ -410,7 +410,7 @@
})
}
-fn builtin_md5(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_md5(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "md5", args, 1, [
0, str: ty!(string) => Val::Str;
], {
@@ -418,7 +418,7 @@
})
}
-fn builtin_trace(context: Context, loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_trace(context: Context, loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "trace", args, 2, [
0, str: ty!(string) => Val::Str;
1, rest: ty!(any);
@@ -435,7 +435,7 @@
})
}
-fn builtin_base64(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_base64(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "base64", args, 1, [
0, input: ty!((string | (Array<number>)));
], {
@@ -453,7 +453,7 @@
})
}
-fn builtin_join(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_join(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "join", args, 2, [
0, sep: ty!((string | array));
1, arr: ty!(array) => Val::Arr;
@@ -513,7 +513,7 @@
// faster
fn builtin_escape_string_json(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "escapeStringJson", args, 1, [
@@ -526,7 +526,7 @@
// faster
fn builtin_manifest_json_ex(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "manifestJsonEx", args, 2, [
@@ -541,7 +541,7 @@
}
// faster
-fn builtin_reverse(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_reverse(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "reverse", args, 1, [
0, value: ty!(array) => Val::Arr;
], {
@@ -549,7 +549,7 @@
})
}
-fn builtin_id(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
+fn builtin_id(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {
parse_args!(context, "id", args, 1, [
0, v: ty!(any);
], {
@@ -560,7 +560,7 @@
// faster
fn builtin_str_replace(
context: Context,
- _loc: &Option<ExprLocation>,
+ _loc: Option<&ExprLocation>,
args: &ArgsDesc,
) -> Result<Val> {
parse_args!(context, "strReplace", args, 3, [
@@ -583,10 +583,9 @@
})
}
-#[allow(clippy::cognitive_complexity)]
pub fn call_builtin(
context: Context,
- loc: &Option<ExprLocation>,
+ loc: Option<&ExprLocation>,
name: &str,
args: &ArgsDesc,
) -> Result<Val> {
crates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -385,7 +385,7 @@
context: Context,
value: &LocExpr,
args: &ArgsDesc,
- loc: &Option<ExprLocation>,
+ loc: Option<&ExprLocation>,
tailstrict: bool,
) -> Result<Val> {
let value = evaluate(context.clone(), value)?;
@@ -430,7 +430,7 @@
BinaryOp(v1, o, v2) => evaluate_binary_op_special(context, v1, *o, v2)?,
UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(context, v)?)?,
Var(name) => push(
- loc,
+ loc.as_ref(),
|| format!("variable <{}>", name),
|| Ok(context.binding(name.clone())?.evaluate()?),
)?,
@@ -448,7 +448,7 @@
(Val::Obj(v), Val::Str(s)) => {
let sn = s.clone();
push(
- loc,
+ loc.as_ref(),
|| format!("field <{}> access", sn),
|| {
if let Some(v) = v.get(s.clone())? {
@@ -540,14 +540,14 @@
&evaluate(context.clone(), s)?,
&Val::Obj(evaluate_object(context, t)?),
)?,
- Apply(value, args, tailstrict) => evaluate_apply(context, value, args, loc, *tailstrict)?,
+ Apply(value, args, tailstrict) => evaluate_apply(context, value, args, loc.as_ref(), *tailstrict)?,
Function(params, body) => {
evaluate_method(context, "anonymous".into(), params.clone(), body.clone())
}
Intrinsic(name) => Val::Func(Rc::new(FuncVal::Intrinsic(name.clone()))),
AssertExpr(AssertStmt(value, msg), returned) => {
let assertion_result = push(
- &value.1,
+ value.1.as_ref(),
|| "assertion condition".to_owned(),
|| {
evaluate(context.clone(), value)?
@@ -558,7 +558,7 @@
evaluate(context, returned)?
} else {
push(
- &value.1,
+ value.1.as_ref(),
|| "assertion failure".to_owned(),
|| {
if let Some(msg) = msg {
@@ -571,7 +571,7 @@
}
}
ErrorStmt(e) => push(
- loc,
+ loc.as_ref(),
|| "error statement".to_owned(),
|| {
throw!(RuntimeError(
@@ -585,7 +585,7 @@
cond_else,
} => {
if push(
- loc,
+ loc.as_ref(),
|| "if condition".to_owned(),
|| evaluate(context.clone(), &cond.0)?.try_cast_bool("in if condition"),
)? {
@@ -605,7 +605,7 @@
let import_location = Rc::make_mut(&mut tmp);
import_location.pop();
push(
- loc,
+ loc.as_ref(),
|| format!("import {:?}", path),
|| with_state(|s| s.import_file(import_location, path)),
)?
crates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -160,7 +160,7 @@
throw!(IntrinsicArgumentReorderingIsNotSupportedYet);
}
}
- let $name = push(&None, || format!("evaluating argument"), || {
+ let $name = push(None, || format!("evaluating argument"), || {
let value = evaluate($ctx.clone(), &$name.1)?;
$ty.check(&value)?;
Ok(value)
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth128 EVAL_STATE.with(|s| f(s.borrow().as_ref().unwrap()))128 EVAL_STATE.with(|s| f(s.borrow().as_ref().unwrap()))129}129}130pub(crate) fn push<T>(130pub(crate) fn push<T>(131 e: &Option<ExprLocation>,131 e: Option<&ExprLocation>,132 frame_desc: impl FnOnce() -> String,132 frame_desc: impl FnOnce() -> String,133 f: impl FnOnce() -> Result<T>,133 f: impl FnOnce() -> Result<T>,134) -> Result<T> {134) -> Result<T> {crates/jrsonnet-evaluator/src/typed.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed.rs
+++ b/crates/jrsonnet-evaluator/src/typed.rs
@@ -78,7 +78,7 @@
}
fn push_type(
- location: &Option<ExprLocation>,
+ location: Option<&ExprLocation>,
error_reason: impl Fn() -> String,
path: impl Fn() -> ValuePathItem,
item: impl Fn() -> Result<()>,
@@ -162,7 +162,7 @@
Val::Arr(a) => {
for (i, item) in a.iter().enumerate() {
push_type(
- &None,
+ None,
|| format!("array index {}", i),
|| ValuePathItem::Index(i as u64),
|| Ok(elem_type.check(&item.clone()?)?),
@@ -176,7 +176,7 @@
Val::Arr(a) => {
for (i, item) in a.iter().enumerate() {
push_type(
- &None,
+ None,
|| format!("array index {}", i),
|| ValuePathItem::Index(i as u64),
|| Ok(elem_type.check(&item.clone()?)?),
@@ -191,7 +191,7 @@
for (k, v) in elems.iter() {
if let Some(got_v) = obj.get((*k).into())? {
push_type(
- &None,
+ None,
|| format!("property {}", k),
|| ValuePathItem::Field((*k).into()),
|| v.check(&got_v),
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -102,7 +102,7 @@
pub fn evaluate(
&self,
call_ctx: Context,
- loc: &Option<ExprLocation>,
+ loc: Option<&ExprLocation>,
args: &ArgsDesc,
tailstrict: bool,
) -> Result<Val> {