difftreelog
style fix clippy warnings
in: master
8 files changed
crates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -1,7 +1,4 @@
-use std::{
- any::Any,
- num::{NonZeroU32, NonZeroUsize},
-};
+use std::{any::Any, num::NonZeroU32};
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IBytes;
crates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -110,7 +110,11 @@
fn get(self: Box<Self>) -> Result<Self::Output> {
let full = self.full.evaluate()?;
let to = full.len() - self.end;
- Ok(Val::Arr(full.slice(Some(self.start as i32), Some(to as i32), None)))
+ Ok(Val::Arr(full.slice(
+ Some(self.start as i32),
+ Some(to as i32),
+ None,
+ )))
}
}
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -2,7 +2,7 @@
cell::RefCell,
fmt::{self, Debug, Display},
mem::replace,
- num::{NonZeroU32, NonZeroUsize},
+ num::NonZeroU32,
rc::Rc,
};
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -218,8 +218,7 @@
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let attr = parse_macro_input!(attr as BuiltinAttrs);
- let item_fn = item.clone();
- let item_fn: ItemFn = parse_macro_input!(item_fn);
+ let item_fn = parse_macro_input!(item as ItemFn);
match builtin_inner(attr, item_fn) {
Ok(v) => v.into(),
crates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/manifest/toml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/toml.rs
@@ -4,7 +4,7 @@
bail,
manifest::{escape_string_json_buf, ManifestFormat},
val::ArrValue,
- IStr, ObjValue, Result, ResultExt, Val, State,
+ IStr, ObjValue, Result, ResultExt, State, Val,
};
pub struct TomlFormat<'s> {
crates/jrsonnet-stdlib/src/manifest/xml.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/manifest/xml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/xml.rs
@@ -1,9 +1,9 @@
use jrsonnet_evaluator::{
bail,
manifest::{ManifestFormat, ToStringFormat},
- typed::{ComplexValType, Either2, Either4, Typed, ValType},
- val::{ArrValue, IndexableVal},
- Either, ObjValue, Result, ResultExt, Val, State,
+ typed::{ComplexValType, Either2, Typed, ValType},
+ val::ArrValue,
+ Either, ObjValue, Result, ResultExt, State, Val,
};
pub struct XmlJsonmlFormat {
@@ -39,20 +39,20 @@
fn from_untyped(untyped: Val) -> Result<Self> {
let val = <Either![ArrValue, String]>::from_untyped(untyped)
- .with_description(|| format!("parsing JSONML value (an array or string)"))?;
+ .description("parsing JSONML value (an array or string)")?;
let arr = match val {
Either2::A(a) => a,
Either2::B(s) => return Ok(Self::String(s)),
};
- if arr.len() < 1 {
+ if arr.is_empty() {
bail!("JSONML value should have tag (array length should be >=1)");
};
let tag = String::from_untyped(
arr.get(0)
- .with_description(|| "getting JSONML tag")?
+ .description("getting JSONML tag")?
.expect("length checked"),
)
- .with_description(|| format!("parsing JSONML tag"))?;
+ .description("parsing JSONML tag")?;
let (has_attrs, attrs) = if arr.len() >= 2 {
let maybe_attrs = arr
@@ -71,7 +71,7 @@
tag,
attrs,
children: State::push_description(
- || format!("parsing children"),
+ || "parsing children".to_owned(),
|| {
Typed::from_untyped(Val::Arr(arr.slice(
Some(if has_attrs { 2 } else { 1 }),
@@ -100,7 +100,7 @@
} => {
let has_children = !children.is_empty();
buf.push('<');
- buf.push_str(&tag);
+ buf.push_str(tag);
attrs.run_assertions()?;
for (key, value) in attrs.iter(
// Not much sense to preserve order here
@@ -125,12 +125,12 @@
}
buf.push('>');
for child in children {
- manifest_jsonml(&child, buf, opts)?;
+ manifest_jsonml(child, buf, opts)?;
}
if has_children || opts.force_closing {
buf.push('<');
buf.push('/');
- buf.push_str(&tag);
+ buf.push_str(tag);
buf.push('>');
}
Ok(())
@@ -177,8 +177,8 @@
}
if !found {
// No match - no escapes required
- out.push_str(&str);
+ out.push_str(str);
return;
}
- out.push_str(&remaining);
+ out.push_str(remaining);
}
crates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth1use std::{cell::RefCell, rc::Rc};23use jrsonnet_evaluator::{4 bail,5 error::{ErrorKind::*, Result},6 function::{builtin, ArgLike, CallLocation, FuncVal},7 manifest::JsonFormat,8 typed::{Either2, Either4},9 val::{equals, ArrValue},10 Context, Either, IStr, ObjValue, Thunk, Val,11};1213use crate::{extvar_source, Settings};1415#[builtin]16pub fn builtin_length(x: Either![IStr, ArrValue, ObjValue, FuncVal]) -> usize {17 use Either4::*;18 match x {19 A(x) => x.chars().count(),20 B(x) => x.len(),21 C(x) => x.len(),22 D(f) => f.params_len(),23 }24}2526#[builtin]27pub fn builtin_get(28 o: ObjValue,29 f: IStr,30 default: Option<Thunk<Val>>,31 #[default(true)]32 inc_hidden: bool,33) -> Result<Val> {34 let do_default = move || {35 let Some(default) = default else {36 return Ok(Val::Null);37 };38 default.evaluate()39 };40 // Happy path for invisible fields41 if !inc_hidden && !o.has_field_ex(f.clone(), false) {42 return do_default();43 }44 let Some(v) = o.get(f)? else {45 return do_default();46 };47 Ok(v)48}4950#[builtin(fields(51 settings: Rc<RefCell<Settings>>,52))]53pub fn builtin_ext_var(this: &builtin_ext_var, ctx: Context, x: IStr) -> Result<Val> {54 let ctx = ctx.state().create_default_context(extvar_source(&x, ""));55 this.settings56 .borrow()57 .ext_vars58 .get(&x)59 .cloned()60 .ok_or_else(|| UndefinedExternalVariable(x))?61 .evaluate_arg(ctx, true)?62 .evaluate()63}6465#[builtin(fields(66 settings: Rc<RefCell<Settings>>,67))]68pub fn builtin_native(this: &builtin_native, x: IStr) -> Val {69 this.settings70 .borrow()71 .ext_natives72 .get(&x)73 .cloned()74 .map_or(Val::Null, Val::Func)75}7677#[builtin(fields(78 settings: Rc<RefCell<Settings>>,79))]80pub fn builtin_trace(81 this: &builtin_trace,82 loc: CallLocation,83 str: Val,84 rest: Option<Thunk<Val>>,85) -> Result<Val> {86 this.settings.borrow().trace_printer.print_trace(87 loc,88 match &str {89 Val::Str(s) => s.clone().into_flat(),90 Val::Func(f) => format!("{f:?}").into(),91 v => v.manifest(JsonFormat::debug())?.into(),92 },93 );94 rest.map_or_else(|| Ok(str), |rest| rest.evaluate())95}9697#[allow(clippy::comparison_chain)]98#[builtin]99pub fn builtin_starts_with(a: Either![IStr, ArrValue], b: Either![IStr, ArrValue]) -> Result<bool> {100 Ok(match (a, b) {101 (Either2::A(a), Either2::A(b)) => a.starts_with(b.as_str()),102 (Either2::B(a), Either2::B(b)) => {103 if b.len() > a.len() {104 return Ok(false);105 } else if b.len() == a.len() {106 return equals(&Val::Arr(a), &Val::Arr(b));107 }108 for (a, b) in a.iter().take(b.len()).zip(b.iter()) {109 let a = a?;110 let b = b?;111 if !equals(&a, &b)? {112 return Ok(false);113 }114 }115 true116 }117 _ => bail!("both arguments should be of the same type"),118 })119}120121#[allow(clippy::comparison_chain)]122#[builtin]123pub fn builtin_ends_with(a: Either![IStr, ArrValue], b: Either![IStr, ArrValue]) -> Result<bool> {124 Ok(match (a, b) {125 (Either2::A(a), Either2::A(b)) => a.ends_with(b.as_str()),126 (Either2::B(a), Either2::B(b)) => {127 if b.len() > a.len() {128 return Ok(false);129 } else if b.len() == a.len() {130 return equals(&Val::Arr(a), &Val::Arr(b));131 }132 let a_len = a.len();133 for (a, b) in a.iter().skip(a_len - b.len()).zip(b.iter()) {134 let a = a?;135 let b = b?;136 if !equals(&a, &b)? {137 return Ok(false);138 }139 }140 true141 }142 _ => bail!("both arguments should be of the same type"),143 })144}crates/jrsonnet-stdlib/src/objects.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/objects.rs
+++ b/crates/jrsonnet-stdlib/src/objects.rs
@@ -57,8 +57,7 @@
o: ObjValue,
include_hidden: bool,
- #[cfg(feature = "exp-preserve-order")]
- preserve_order: bool,
+ #[cfg(feature = "exp-preserve-order")] preserve_order: bool,
) -> ArrValue {
o.values_ex(
include_hidden,
@@ -101,8 +100,7 @@
o: ObjValue,
include_hidden: bool,
- #[cfg(feature = "exp-preserve-order")]
- preserve_order: bool,
+ #[cfg(feature = "exp-preserve-order")] preserve_order: bool,
) -> ArrValue {
o.key_values_ex(
include_hidden,