difftreelog
style fix clippy warnings
in: master
17 files changed
crates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -372,7 +372,7 @@
pub fn new_inclusive(start: i32, end: i32) -> Self {
Self { start, end }
}
- fn range(&self) -> impl Iterator<Item = i32> + ExactSizeIterator + DoubleEndedIterator {
+ fn range(&self) -> impl ExactSizeIterator<Item = i32> + DoubleEndedIterator {
WithExactSize(
self.start..=self.end,
(self.end as usize)
@@ -461,7 +461,7 @@
ArrayThunk::Waiting(..) => {}
};
- let ArrayThunk::Waiting(_) =
+ let ArrayThunk::Waiting(()) =
replace(&mut self.cached.borrow_mut()[index], ArrayThunk::Pending)
else {
unreachable!()
@@ -508,7 +508,7 @@
match &self.cached.borrow()[index] {
ArrayThunk::Computed(c) => return Some(Thunk::evaluated(c.clone())),
ArrayThunk::Errored(e) => return Some(Thunk::errored(e.clone())),
- ArrayThunk::Waiting(_) | ArrayThunk::Pending => {}
+ ArrayThunk::Waiting(()) | ArrayThunk::Pending => {}
};
Some(Thunk::new(ArrayElement {
@@ -597,9 +597,7 @@
}
fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
- let Some(key) = self.keys.get(index) else {
- return None;
- };
+ let key = self.keys.get(index)?;
Some(self.obj.get_lazy_or_bail(key.clone()))
}
@@ -649,9 +647,7 @@
}
fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {
- let Some(key) = self.keys.get(index) else {
- return None;
- };
+ let key = self.keys.get(index)?;
// Nothing can fail in the key part, yet value is still
// lazy-evaluated
Some(Thunk::evaluated(
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -89,7 +89,7 @@
specs: &[CompSpec],
callback: &mut impl FnMut(Context) -> Result<()>,
) -> Result<()> {
- match specs.get(0) {
+ match specs.first() {
None => callback(ctx)?,
Some(CompSpec::IfSpec(IfSpecData(cond))) => {
if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {
crates/jrsonnet-evaluator/src/function/builtin.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/builtin.rs
+++ b/crates/jrsonnet-evaluator/src/function/builtin.rs
@@ -6,8 +6,8 @@
use super::{arglike::ArgsLike, parse::parse_builtin_call, CallLocation};
use crate::{gc::TraceBox, tb, Context, Result, Val};
-/// Can't have str | IStr, because constant BuiltinParam causes
-/// E0492: constant functions cannot refer to interior mutable data
+/// Can't have `str` | `IStr`, because constant `BuiltinParam` causes
+/// `E0492: constant functions cannot refer to interior mutable data`
#[derive(Clone, Trace)]
pub struct ParamName(Option<Cow<'static, str>>);
impl ParamName {
@@ -27,10 +27,9 @@
}
impl PartialEq<IStr> for ParamName {
fn eq(&self, other: &IStr) -> bool {
- match &self.0 {
- Some(s) => s.as_bytes() == other.as_bytes(),
- None => false,
- }
+ self.0
+ .as_ref()
+ .map_or(false, |s| s.as_bytes() == other.as_bytes())
}
}
@@ -87,7 +86,7 @@
params: params
.into_iter()
.map(|n| BuiltinParam {
- name: ParamName::new_dynamic(n.to_string()),
+ name: ParamName::new_dynamic(n),
has_default: false,
})
.collect(),
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -159,11 +159,11 @@
Val::Null => serializer.serialize_none(),
Val::Str(s) => serializer.serialize_str(&s.clone().into_flat()),
Val::Num(n) => {
- if n.fract() != 0.0 {
- serializer.serialize_f64(*n)
- } else {
+ if n.fract() == 0.0 {
let n = *n as i64;
serializer.serialize_i64(n)
+ } else {
+ serializer.serialize_f64(*n)
}
}
#[cfg(feature = "exp-bigint")]
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -41,10 +41,12 @@
clippy::missing_const_for_fn,
// too many false-positives with .expect() calls
clippy::missing_panics_doc,
- // false positive for IStr type. There is an configuration option for
- // such cases, but it doesn't work:
- // https://github.com/rust-lang/rust-clippy/issues/9801
- clippy::mutable_key_type,
+ // false positive for IStr type. There is an configuration option for
+ // such cases, but it doesn't work:
+ // https://github.com/rust-lang/rust-clippy/issues/9801
+ clippy::mutable_key_type,
+ // false positives
+ clippy::redundant_pub_crate,
)]
// For jrsonnet-macros
crates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -175,6 +175,8 @@
manifest_json_ex_buf(val, &mut out, &mut String::new(), options)?;
Ok(out)
}
+
+#[allow(clippy::too_many_lines)]
fn manifest_json_ex_buf(
val: &Val,
buf: &mut String,
crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -171,7 +171,7 @@
// .field("assertions_ran", &self.assertions_ran)
.field("this_entries", &self.this_entries)
// .field("value_cache", &self.value_cache)
- .finish()
+ .finish_non_exhaustive()
}
}
@@ -347,7 +347,7 @@
out.with_super(self);
let mut member = out.field(key);
if value.flags.add() {
- member = member.add()
+ member = member.add();
}
if let Some(loc) = value.location {
member = member.with_location(loc);
@@ -395,7 +395,7 @@
pub fn get(&self, key: IStr) -> Result<Option<Val>> {
self.run_assertions()?;
- self.get_for(key, self.0.this().unwrap_or(self.clone()))
+ self.get_for(key, self.0.this().unwrap_or_else(|| self.clone()))
}
pub fn get_for(&self, key: IStr, this: ObjValue) -> Result<Option<Val>> {
@@ -474,7 +474,7 @@
type Output = Val;
fn get(self: Box<Self>) -> Result<Self::Output> {
- Ok(self.obj.get_or_bail(self.key)?)
+ self.obj.get_or_bail(self.key)
}
}
@@ -495,7 +495,7 @@
SuperDepth::default(),
&mut |depth, index, name, visibility| {
let new_sort_key = FieldSortKey::new(depth, index);
- let entry = out.entry(name.clone());
+ let entry = out.entry(name);
let (visible, _) = entry.or_insert((true, new_sort_key));
match visibility {
Visibility::Normal => {}
@@ -634,7 +634,7 @@
SuperDepth::default(),
&mut |depth, index, name, visibility| {
let new_sort_key = FieldSortKey::new(depth, index);
- let entry = out.entry(name.clone());
+ let entry = out.entry(name);
let (visible, _) = entry.or_insert((true, new_sort_key));
match visibility {
Visibility::Normal => {}
crates/jrsonnet-evaluator/src/stdlib/format.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/stdlib/format.rs
+++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs
@@ -248,7 +248,7 @@
let (cflags, str) = try_parse_cflags(str)?;
let (width, str) = try_parse_field_width(str)?;
let (precision, str) = try_parse_precision(str)?;
- let (_, str) = try_parse_length_modifier(str)?;
+ let ((), str) = try_parse_length_modifier(str)?;
let (convtype, str) = parse_conversion_type(str)?;
Ok((
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth1use std::{collections::BTreeMap, marker::PhantomData, ops::Deref};23use jrsonnet_gcmodule::{Cc, Trace};4use jrsonnet_interner::{IBytes, IStr};5pub use jrsonnet_macros::Typed;6use jrsonnet_types::{ComplexValType, ValType};78use crate::{9 arr::{ArrValue, BytesArray},10 bail,11 function::{native::NativeDesc, FuncDesc, FuncVal},12 typed::CheckType,13 val::{IndexableVal, StrValue, ThunkMapper},14 ObjValue, ObjValueBuilder, Result, Thunk, Val,15};1617#[derive(Trace)]18struct FromUntyped<K: Trace>(PhantomData<fn() -> K>);19impl<K> ThunkMapper<Val> for FromUntyped<K>20where21 K: Typed + Trace,22{23 type Output = K;2425 fn map(self, from: Val) -> Result<Self::Output> {26 K::from_untyped(from)27 }28}29impl<K: Trace> Default for FromUntyped<K> {30 fn default() -> Self {31 Self(PhantomData)32 }33}3435pub trait TypedObj: Typed {36 fn serialize(self, out: &mut ObjValueBuilder) -> Result<()>;37 fn parse(obj: &ObjValue) -> Result<Self>;38 fn into_object(self) -> Result<ObjValue> {39 let mut builder = ObjValueBuilder::new();40 self.serialize(&mut builder)?;41 Ok(builder.build())42 }43}4445pub trait Typed: Sized {46 const TYPE: &'static ComplexValType;47 fn into_untyped(typed: Self) -> Result<Val>;48 fn into_lazy_untyped(typed: Self) -> Thunk<Val> {49 Thunk::from(Self::into_untyped(typed))50 }51 fn from_untyped(untyped: Val) -> Result<Self>;52 fn from_lazy_untyped(lazy: Thunk<Val>) -> Result<Self> {53 Self::from_untyped(lazy.evaluate()?)54 }5556 // Whatever caller should use `into_lazy_untyped` instead of `into_untyped`57 fn provides_lazy() -> bool {58 false59 }6061 // Whatever caller should use `from_lazy_untyped` instead of `from_untyped` when possible62 fn wants_lazy() -> bool {63 false64 }6566 /// Hack to make builtins be able to return non-result values, and make macros able to convert those values to result67 /// This method returns identity in impl Typed for Result, and should not be overriden68 #[doc(hidden)]69 fn into_result(typed: Self) -> Result<Val> {70 let value = Self::into_untyped(typed)?;71 Ok(value)72 }73}7475impl<T> Typed for Thunk<T>76where77 T: Typed + Trace + Clone,78{79 const TYPE: &'static ComplexValType = &ComplexValType::Lazy(T::TYPE);8081 fn into_untyped(typed: Self) -> Result<Val> {82 T::into_untyped(typed.evaluate()?)83 }8485 fn from_untyped(untyped: Val) -> Result<Self> {86 Self::from_lazy_untyped(Thunk::evaluated(untyped))87 }8889 fn provides_lazy() -> bool {90 true91 }9293 fn into_lazy_untyped(inner: Self) -> Thunk<Val> {94 #[derive(Trace)]95 struct IntoUntyped<K: Trace>(PhantomData<fn() -> K>);96 impl<K> ThunkMapper<K> for IntoUntyped<K>97 where98 K: Typed + Trace,99 {100 type Output = Val;101102 fn map(self, from: K) -> Result<Self::Output> {103 K::into_untyped(from)104 }105 }106 impl<K: Trace> Default for IntoUntyped<K> {107 fn default() -> Self {108 Self(PhantomData)109 }110 }111 inner.map(<IntoUntyped<T>>::default())112 }113114 fn wants_lazy() -> bool {115 true116 }117118 fn from_lazy_untyped(inner: Thunk<Val>) -> Result<Self> {119 Ok(inner.map(<FromUntyped<T>>::default()))120 }121}122123const MAX_SAFE_INTEGER: f64 = ((1u64 << (f64::MANTISSA_DIGITS + 1)) - 1) as f64;124125macro_rules! impl_int {126 ($($ty:ty)*) => {$(127 impl Typed for $ty {128 const TYPE: &'static ComplexValType =129 &ComplexValType::BoundedNumber(Some(Self::MIN as f64), Some(Self::MAX as f64));130 fn from_untyped(value: Val) -> Result<Self> {131 <Self as Typed>::TYPE.check(&value)?;132 match value {133 Val::Num(n) => {134 #[allow(clippy::float_cmp)]135 if n.trunc() != n {136 bail!(137 "cannot convert number with fractional part to {}",138 stringify!($ty)139 )140 }141 Ok(n as Self)142 }143 _ => unreachable!(),144 }145 }146 fn into_untyped(value: Self) -> Result<Val> {147 Ok(Val::Num(value as f64))148 }149 }150 )*};151}152153impl_int!(i8 u8 i16 u16 i32 u32);154155macro_rules! impl_bounded_int {156 ($($name:ident = $ty:ty)*) => {$(157 #[derive(Clone, Copy)]158 pub struct $name<const MIN: $ty, const MAX: $ty>($ty);159 impl<const MIN: $ty, const MAX: $ty> $name<MIN, MAX> {160 pub const fn new(value: $ty) -> Option<$name<MIN, MAX>> {161 if value >= MIN && value <= MAX {162 Some(Self(value))163 } else {164 None165 }166 }167 pub const fn value(self) -> $ty {168 self.0169 }170 }171 impl<const MIN: $ty, const MAX: $ty> Deref for $name<MIN, MAX> {172 type Target = $ty;173 fn deref(&self) -> &Self::Target {174 &self.0175 }176 }177178 impl<const MIN: $ty, const MAX: $ty> Typed for $name<MIN, MAX> {179 const TYPE: &'static ComplexValType =180 &ComplexValType::BoundedNumber(181 Some(MIN as f64),182 Some(MAX as f64),183 );184185 fn from_untyped(value: Val) -> Result<Self> {186 <Self as Typed>::TYPE.check(&value)?;187 match value {188 Val::Num(n) => {189 #[allow(clippy::float_cmp)]190 if n.trunc() != n {191 bail!(192 "cannot convert number with fractional part to {}",193 stringify!($ty)194 )195 }196 Ok(Self(n as $ty))197 }198 _ => unreachable!(),199 }200 }201202 fn into_untyped(value: Self) -> Result<Val> {203 Ok(Val::Num(value.0 as f64))204 }205 }206 )*};207}208209impl_bounded_int!(210 BoundedI8 = i8211 BoundedI16 = i16212 BoundedI32 = i32213 BoundedI64 = i64214 BoundedUsize = usize215);216217impl Typed for f64 {218 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Num);219220 fn into_untyped(value: Self) -> Result<Val> {221 Ok(Val::Num(value))222 }223224 fn from_untyped(value: Val) -> Result<Self> {225 <Self as Typed>::TYPE.check(&value)?;226 match value {227 Val::Num(n) => Ok(n),228 _ => unreachable!(),229 }230 }231}232233pub struct PositiveF64(pub f64);234impl Typed for PositiveF64 {235 const TYPE: &'static ComplexValType = &ComplexValType::BoundedNumber(Some(0.0), None);236237 fn into_untyped(value: Self) -> Result<Val> {238 Ok(Val::Num(value.0))239 }240241 fn from_untyped(value: Val) -> Result<Self> {242 <Self as Typed>::TYPE.check(&value)?;243 match value {244 Val::Num(n) => Ok(Self(n)),245 _ => unreachable!(),246 }247 }248}249impl Typed for usize {250 const TYPE: &'static ComplexValType =251 &ComplexValType::BoundedNumber(Some(0.0), Some(MAX_SAFE_INTEGER));252253 fn into_untyped(value: Self) -> Result<Val> {254 if value > MAX_SAFE_INTEGER as Self {255 bail!("number is too large")256 }257 Ok(Val::Num(value as f64))258 }259260 fn from_untyped(value: Val) -> Result<Self> {261 <Self as Typed>::TYPE.check(&value)?;262 match value {263 Val::Num(n) => {264 #[allow(clippy::float_cmp)]265 if n.trunc() != n {266 bail!("cannot convert number with fractional part to usize")267 }268 Ok(n as Self)269 }270 _ => unreachable!(),271 }272 }273}274275impl Typed for IStr {276 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Str);277278 fn into_untyped(value: Self) -> Result<Val> {279 Ok(Val::string(value))280 }281282 fn from_untyped(value: Val) -> Result<Self> {283 <Self as Typed>::TYPE.check(&value)?;284 match value {285 Val::Str(s) => Ok(s.into_flat()),286 _ => unreachable!(),287 }288 }289}290291impl Typed for String {292 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Str);293294 fn into_untyped(value: Self) -> Result<Val> {295 Ok(Val::string(value))296 }297298 fn from_untyped(value: Val) -> Result<Self> {299 <Self as Typed>::TYPE.check(&value)?;300 match value {301 Val::Str(s) => Ok(s.to_string()),302 _ => unreachable!(),303 }304 }305}306307impl Typed for StrValue {308 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Str);309310 fn into_untyped(value: Self) -> Result<Val> {311 Ok(Val::Str(value))312 }313314 fn from_untyped(value: Val) -> Result<Self> {315 <Self as Typed>::TYPE.check(&value)?;316 match value {317 Val::Str(s) => Ok(s),318 _ => unreachable!(),319 }320 }321}322323impl Typed for char {324 const TYPE: &'static ComplexValType = &ComplexValType::Char;325326 fn into_untyped(value: Self) -> Result<Val> {327 Ok(Val::string(value))328 }329330 fn from_untyped(value: Val) -> Result<Self> {331 <Self as Typed>::TYPE.check(&value)?;332 match value {333 Val::Str(s) => Ok(s.into_flat().chars().next().unwrap()),334 _ => unreachable!(),335 }336 }337}338339impl<T> Typed for Vec<T>340where341 T: Typed,342{343 const TYPE: &'static ComplexValType = &ComplexValType::ArrayRef(T::TYPE);344345 fn into_untyped(value: Self) -> Result<Val> {346 Ok(Val::Arr(347 value348 .into_iter()349 .map(T::into_untyped)350 .collect::<Result<ArrValue>>()?,351 ))352 }353354 fn from_untyped(value: Val) -> Result<Self> {355 let Val::Arr(a) = value else {356 <Self as Typed>::TYPE.check(&value)?;357 unreachable!("typecheck should fail")358 };359 a.iter()360 .map(|r| r.and_then(T::from_untyped))361 .collect::<Result<Vec<T>>>()362 }363}364365impl<K: Typed + Ord, V: Typed> Typed for BTreeMap<K, V> {366 const TYPE: &'static ComplexValType = &ComplexValType::AttrsOf(V::TYPE);367368 fn into_untyped(typed: Self) -> Result<Val> {369 let mut out = ObjValueBuilder::with_capacity(typed.len());370 for (k, v) in typed {371 let Some(key) = K::into_untyped(k)?.as_str() else {372 bail!("map key should serialize to string");373 };374 let value = V::into_untyped(v)?;375 out.field(key).value(value);376 }377 Ok(Val::Obj(out.build()))378 }379380 fn from_untyped(value: Val) -> Result<Self> {381 Self::TYPE.check(&value)?;382 let obj = value.as_obj().expect("typecheck should fail");383384 let mut out = BTreeMap::new();385 if V::wants_lazy() {386 for key in obj.fields_ex(387 false,388 #[cfg(feature = "exp-preserve-order")]389 false,390 ) {391 let value = obj.get_lazy(key.clone()).expect("field exists");392 let value = V::from_lazy_untyped(value)?;393 let key = K::from_untyped(Val::Str(key.into()))?;394 let _ = out.insert(key, value);395 }396 } else {397 for (key, value) in obj.iter(398 #[cfg(feature = "exp-preserve-order")]399 false,400 ) {401 let key = K::from_untyped(Val::Str(key.into()))?;402 let value = V::from_untyped(value?)?;403 let _ = out.insert(key, value);404 }405 }406 Ok(out)407 }408}409410impl Typed for Val {411 const TYPE: &'static ComplexValType = &ComplexValType::Any;412413 fn into_untyped(typed: Self) -> Result<Val> {414 Ok(typed)415 }416 fn from_untyped(untyped: Val) -> Result<Self> {417 Ok(untyped)418 }419}420421// Hack422#[doc(hidden)]423impl<T> Typed for Result<T>424where425 T: Typed,426{427 const TYPE: &'static ComplexValType = &ComplexValType::Any;428429 fn into_untyped(_typed: Self) -> Result<Val> {430 panic!("do not use this conversion")431 }432433 fn from_untyped(_untyped: Val) -> Result<Self> {434 panic!("do not use this conversion")435 }436437 fn into_result(typed: Self) -> Result<Val> {438 typed.map(T::into_untyped)?439 }440}441442/// Specialization443impl Typed for IBytes {444 const TYPE: &'static ComplexValType =445 &ComplexValType::ArrayRef(&ComplexValType::BoundedNumber(Some(0.0), Some(255.0)));446447 fn into_untyped(value: Self) -> Result<Val> {448 Ok(Val::Arr(ArrValue::bytes(value)))449 }450451 fn from_untyped(value: Val) -> Result<Self> {452 match &value {453 Val::Arr(a) => {454 if let Some(bytes) = a.as_any().downcast_ref::<BytesArray>() {455 return Ok(bytes.0.as_slice().into());456 };457 <Self as Typed>::TYPE.check(&value)?;458 // Any::downcast_ref::<ByteArray>(&a);459 let mut out = Vec::with_capacity(a.len());460 for e in a.iter() {461 let r = e?;462 out.push(u8::from_untyped(r)?);463 }464 Ok(out.as_slice().into())465 }466 _ => {467 <Self as Typed>::TYPE.check(&value)?;468 unreachable!()469 }470 }471 }472}473474pub struct M1;475impl Typed for M1 {476 const TYPE: &'static ComplexValType = &ComplexValType::BoundedNumber(Some(-1.0), Some(-1.0));477478 fn into_untyped(_: Self) -> Result<Val> {479 Ok(Val::Num(-1.0))480 }481482 fn from_untyped(value: Val) -> Result<Self> {483 <Self as Typed>::TYPE.check(&value)?;484 Ok(Self)485 }486}487488macro_rules! decl_either {489 ($($name: ident, $($id: ident)*);*) => {$(490 #[derive(Clone)]491 pub enum $name<$($id),*> {492 $($id($id)),*493 }494 impl<$($id),*> Typed for $name<$($id),*>495 where496 $($id: Typed,)*497 {498 const TYPE: &'static ComplexValType = &ComplexValType::UnionRef(&[$($id::TYPE),*]);499500 fn into_untyped(value: Self) -> Result<Val> {501 match value {$(502 $name::$id(v) => $id::into_untyped(v)503 ),*}504 }505506 fn from_untyped(value: Val) -> Result<Self> {507 $(508 if $id::TYPE.check(&value).is_ok() {509 $id::from_untyped(value).map(Self::$id)510 } else511 )* {512 <Self as Typed>::TYPE.check(&value)?;513 unreachable!()514 }515 }516 }517 )*}518}519decl_either!(520 Either1, A;521 Either2, A B;522 Either3, A B C;523 Either4, A B C D;524 Either5, A B C D E;525 Either6, A B C D E F;526 Either7, A B C D E F G527);528#[macro_export]529macro_rules! Either {530 ($a:ty) => {$crate::typed::Either1<$a>};531 ($a:ty, $b:ty) => {$crate::typed::Either2<$a, $b>};532 ($a:ty, $b:ty, $c:ty) => {$crate::typed::Either3<$a, $b, $c>};533 ($a:ty, $b:ty, $c:ty, $d:ty) => {$crate::typed::Either4<$a, $b, $c, $d>};534 ($a:ty, $b:ty, $c:ty, $d:ty, $e:ty) => {$crate::typed::Either5<$a, $b, $c, $d, $e>};535 ($a:ty, $b:ty, $c:ty, $d:ty, $e:ty, $f:ty) => {$crate::typed::Either6<$a, $b, $c, $d, $e, $f>};536 ($a:ty, $b:ty, $c:ty, $d:ty, $e:ty, $f:ty, $g:ty) => {$crate::typed::Either7<$a, $b, $c, $d, $e, $f, $g>};537}538pub use Either;539540pub type MyType = Either![u32, f64, String];541542impl Typed for ArrValue {543 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Arr);544545 fn into_untyped(value: Self) -> Result<Val> {546 Ok(Val::Arr(value))547 }548549 fn from_untyped(value: Val) -> Result<Self> {550 <Self as Typed>::TYPE.check(&value)?;551 match value {552 Val::Arr(a) => Ok(a),553 _ => unreachable!(),554 }555 }556}557558impl Typed for FuncVal {559 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Func);560561 fn into_untyped(value: Self) -> Result<Val> {562 Ok(Val::Func(value))563 }564565 fn from_untyped(value: Val) -> Result<Self> {566 <Self as Typed>::TYPE.check(&value)?;567 match value {568 Val::Func(a) => Ok(a),569 _ => unreachable!(),570 }571 }572}573574impl Typed for Cc<FuncDesc> {575 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Func);576577 fn into_untyped(value: Self) -> Result<Val> {578 Ok(Val::Func(FuncVal::Normal(value)))579 }580581 fn from_untyped(value: Val) -> Result<Self> {582 <Self as Typed>::TYPE.check(&value)?;583 match value {584 Val::Func(FuncVal::Normal(desc)) => Ok(desc),585 Val::Func(_) => bail!("expected normal function, not builtin"),586 _ => unreachable!(),587 }588 }589}590591impl Typed for ObjValue {592 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Obj);593594 fn into_untyped(value: Self) -> Result<Val> {595 Ok(Val::Obj(value))596 }597598 fn from_untyped(value: Val) -> Result<Self> {599 <Self as Typed>::TYPE.check(&value)?;600 match value {601 Val::Obj(a) => Ok(a),602 _ => unreachable!(),603 }604 }605}606607impl Typed for bool {608 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Bool);609610 fn into_untyped(value: Self) -> Result<Val> {611 Ok(Val::Bool(value))612 }613614 fn from_untyped(value: Val) -> Result<Self> {615 <Self as Typed>::TYPE.check(&value)?;616 match value {617 Val::Bool(a) => Ok(a),618 _ => unreachable!(),619 }620 }621}622impl Typed for IndexableVal {623 const TYPE: &'static ComplexValType = &ComplexValType::UnionRef(&[624 &ComplexValType::Simple(ValType::Arr),625 &ComplexValType::Simple(ValType::Str),626 ]);627628 fn into_untyped(value: Self) -> Result<Val> {629 match value {630 IndexableVal::Str(s) => Ok(Val::string(s)),631 IndexableVal::Arr(a) => Ok(Val::Arr(a)),632 }633 }634635 fn from_untyped(value: Val) -> Result<Self> {636 <Self as Typed>::TYPE.check(&value)?;637 value.into_indexable()638 }639}640641pub struct Null;642impl Typed for Null {643 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Null);644645 fn into_untyped(_: Self) -> Result<Val> {646 Ok(Val::Null)647 }648649 fn from_untyped(value: Val) -> Result<Self> {650 <Self as Typed>::TYPE.check(&value)?;651 Ok(Self)652 }653}654655pub struct NativeFn<D: NativeDesc>(D::Value);656impl<D: NativeDesc> Deref for NativeFn<D> {657 type Target = D::Value;658659 fn deref(&self) -> &Self::Target {660 &self.0661 }662}663impl<D: NativeDesc> Typed for NativeFn<D> {664 const TYPE: &'static ComplexValType = &ComplexValType::Simple(ValType::Func);665666 fn into_untyped(_typed: Self) -> Result<Val> {667 bail!("can only convert functions from jsonnet to native")668 }669670 fn from_untyped(untyped: Val) -> Result<Self> {671 Ok(Self(672 untyped673 .as_func()674 .expect("shape is checked")675 .into_native::<D>(),676 ))677 }678}crates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/mod.rs
+++ b/crates/jrsonnet-evaluator/src/typed/mod.rs
@@ -90,7 +90,7 @@
item: impl Fn() -> Result<()>,
) -> Result<()> {
State::push_description(error_reason, || match item() {
- Ok(_) => Ok(()),
+ Ok(()) => Ok(()),
Err(mut e) => {
if let ErrorKind::TypeError(e) = &mut e.error_mut() {
(e.1).0.push(path());
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -351,6 +351,8 @@
}
}
impl PartialEq for StrValue {
+ // False positive, into_flat returns not StrValue, but IStr, thus no infinite recursion here.
+ #[allow(clippy::unconditional_recursion)]
fn eq(&self, other: &Self) -> bool {
let a = self.clone().into_flat();
let b = other.clone().into_flat();
crates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -6,7 +6,7 @@
#![warn(clippy::pedantic, clippy::nursery)]
#![allow(clippy::missing_const_for_fn)]
use std::{
- borrow::{Borrow, Cow},
+ borrow::Cow,
cell::RefCell,
fmt::{self, Display},
hash::{BuildHasherDefault, Hash, Hasher},
@@ -14,7 +14,7 @@
str,
};
-use hashbrown::HashMap;
+use hashbrown::{hash_map::RawEntryMut, HashMap};
use jrsonnet_gcmodule::Trace;
use rustc_hash::FxHasher;
@@ -57,17 +57,6 @@
}
}
-impl Borrow<str> for IStr {
- fn borrow(&self) -> &str {
- self.as_str()
- }
-}
-impl Borrow<[u8]> for IStr {
- fn borrow(&self) -> &[u8] {
- self.as_bytes()
- }
-}
-
impl PartialEq for IStr {
fn eq(&self, other: &Self) -> bool {
// all IStr should be inlined into same pool
@@ -142,12 +131,6 @@
type Target = [u8];
fn deref(&self) -> &Self::Target {
- self.0.as_slice()
- }
-}
-
-impl Borrow<[u8]> for IBytes {
- fn borrow(&self) -> &[u8] {
self.0.as_slice()
}
}
@@ -285,9 +268,9 @@
let mut pool = pool.borrow_mut();
let entry = pool.raw_entry_mut().from_key(bytes);
match entry {
- hashbrown::hash_map::RawEntryMut::Occupied(i) => IBytes(i.get_key_value().0.clone()),
- hashbrown::hash_map::RawEntryMut::Vacant(e) => {
- let (k, _) = e.insert(Inner::new_bytes(bytes), ());
+ RawEntryMut::Occupied(i) => IBytes(i.get_key_value().0.clone()),
+ RawEntryMut::Vacant(e) => {
+ let (k, ()) = e.insert(Inner::new_bytes(bytes), ());
IBytes(k.clone())
}
}
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -374,6 +374,7 @@
fn params(&self) -> &[BuiltinParam] {
PARAMS
}
+ #[allow(unused_variable)]
fn call(&self, ctx: Context, location: CallLocation, args: &dyn ArgsLike) -> Result<Val> {
let parsed = parse_builtin_call(ctx.clone(), &PARAMS, args, false)?;
crates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/encoding.rs
+++ b/crates/jrsonnet-stdlib/src/encoding.rs
@@ -39,5 +39,5 @@
let bytes = STANDARD
.decode(str.as_bytes())
.map_err(|e| runtime_error!("invalid base64: {e}"))?;
- Ok(String::from_utf8(bytes).map_err(|_| runtime_error!("bad utf8"))?)
+ String::from_utf8(bytes).map_err(|_| runtime_error!("bad utf8"))
}
crates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -47,7 +47,7 @@
.ext_natives
.get(&x)
.cloned()
- .map_or(Val::Null, |v| Val::Func(v))
+ .map_or(Val::Null, Val::Func)
}
#[builtin(fields(
flake.lockdiffbeforeafterboth--- a/flake.lock
+++ b/flake.lock
@@ -5,11 +5,11 @@
"systems": "systems"
},
"locked": {
- "lastModified": 1694529238,
- "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
+ "lastModified": 1705309234,
+ "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
- "rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
+ "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
@@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1701376520,
- "narHash": "sha256-U3iGiOZqgu7wvVzgfoQzGGFMqNsDj/q/6zPIjCy7ajg=",
+ "lastModified": 1705391267,
+ "narHash": "sha256-gGVm9QudiRtYTX8PN9cTTy7uuJcL4I2lRMoPx496kXk=",
"owner": "nixos",
"repo": "nixpkgs",
- "rev": "c74cc3c3db2ed5e68895953d75c397797d499133",
+ "rev": "41a9a7f170c740acb24f3390323877d11c69d5ee",
"type": "github"
},
"original": {
@@ -50,11 +50,11 @@
]
},
"locked": {
- "lastModified": 1701310566,
- "narHash": "sha256-CL9J3xUR2Ejni4LysrEGX0IdO+Y4BXCiH/By0lmF3eQ=",
+ "lastModified": 1705371439,
+ "narHash": "sha256-P1kulUXpYWkcrjiX3sV4j8ACJZh9XXSaaD+jDLBDLKo=",
"owner": "oxalica",
"repo": "rust-overlay",
- "rev": "6d3c6e185198b8bf7ad639f22404a75aa9a09bff",
+ "rev": "b21f3c0d5bf0f0179f5f0140e8e0cd099618bd04",
"type": "github"
},
"original": {
flake.nixdiffbeforeafterboth--- a/flake.nix
+++ b/flake.nix
@@ -25,14 +25,14 @@
lib = pkgs.lib;
rust =
(pkgs.rustChannelOf {
- date = "2023-10-28";
+ date = "2024-01-10";
channel = "nightly";
})
.default
.override {
extensions = ["rust-src" "miri" "rust-analyzer" "clippy"];
};
- in rec {
+ in {
packages = rec {
go-jsonnet = pkgs.callPackage ./nix/go-jsonnet.nix {};
sjsonnet = pkgs.callPackage ./nix/sjsonnet.nix {};