difftreelog
style fix clippy warnings
in: master
17 files changed
crates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth1use std::{any::Any, cell::RefCell, fmt::Debug, iter, mem::replace};23use jrsonnet_gcmodule::{Cc, Trace};4use jrsonnet_interner::{IBytes, IStr};5use jrsonnet_parser::LocExpr;67use super::ArrValue;8use crate::{9 error::ErrorKind::InfiniteRecursionDetected, evaluate, function::FuncVal, typed::Typed,10 val::ThunkValue, Context, Error, ObjValue, Result, Thunk, Val,11};1213pub trait ArrayLike: Any + Trace + Debug {14 fn len(&self) -> usize;15 fn is_empty(&self) -> bool {16 self.len() == 017 }18 fn get(&self, index: usize) -> Result<Option<Val>>;19 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>>;20 fn get_cheap(&self, index: usize) -> Option<Val>;2122 fn is_cheap(&self) -> bool;23}2425#[derive(Debug, Trace)]26pub struct SliceArray {27 pub(crate) inner: ArrValue,28 pub(crate) from: u32,29 pub(crate) to: u32,30 pub(crate) step: u32,31}3233impl SliceArray {34 fn iter(&self) -> impl Iterator<Item = Result<Val>> + '_ {35 self.inner36 .iter()37 .skip(self.from as usize)38 .take((self.to - self.from) as usize)39 .step_by(self.step as usize)40 }4142 fn iter_lazy(&self) -> impl Iterator<Item = Thunk<Val>> + '_ {43 self.inner44 .iter_lazy()45 .skip(self.from as usize)46 .take((self.to - self.from) as usize)47 .step_by(self.step as usize)48 }4950 fn iter_cheap(&self) -> Option<impl crate::arr::ArrayLikeIter<Val> + '_> {51 Some(52 self.inner53 .iter_cheap()?54 .skip(self.from as usize)55 .take((self.to - self.from) as usize)56 .step_by(self.step as usize),57 )58 }59}60impl ArrayLike for SliceArray {61 fn len(&self) -> usize {62 iter::repeat(())63 .take((self.to - self.from) as usize)64 .step_by(self.step as usize)65 .count()66 }6768 fn get(&self, index: usize) -> Result<Option<Val>> {69 self.iter().nth(index).transpose()70 }7172 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {73 self.iter_lazy().nth(index)74 }7576 fn get_cheap(&self, index: usize) -> Option<Val> {77 self.iter_cheap()?.nth(index)78 }79 fn is_cheap(&self) -> bool {80 self.inner.is_cheap()81 }82}8384#[derive(Trace, Debug)]85pub struct CharArray(pub Vec<char>);86impl ArrayLike for CharArray {87 fn len(&self) -> usize {88 self.0.len()89 }9091 fn get(&self, index: usize) -> Result<Option<Val>> {92 Ok(self.get_cheap(index))93 }9495 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {96 self.get_cheap(index).map(Thunk::evaluated)97 }9899 fn get_cheap(&self, index: usize) -> Option<Val> {100 self.0.get(index).map(|v| Val::string(*v))101 }102 fn is_cheap(&self) -> bool {103 true104 }105}106107#[derive(Trace, Debug)]108pub struct BytesArray(pub IBytes);109impl ArrayLike for BytesArray {110 fn len(&self) -> usize {111 self.0.len()112 }113114 fn get(&self, index: usize) -> Result<Option<Val>> {115 Ok(self.get_cheap(index))116 }117118 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {119 self.get_cheap(index).map(Thunk::evaluated)120 }121122 fn get_cheap(&self, index: usize) -> Option<Val> {123 self.0.get(index).map(|v| Val::Num(f64::from(*v)))124 }125 fn is_cheap(&self) -> bool {126 true127 }128}129130#[derive(Debug, Trace, Clone)]131enum ArrayThunk<T: 'static + Trace> {132 Computed(Val),133 Errored(Error),134 Waiting(T),135 Pending,136}137138#[derive(Debug, Trace, Clone)]139pub struct ExprArray {140 ctx: Context,141 cached: Cc<RefCell<Vec<ArrayThunk<LocExpr>>>>,142}143impl ExprArray {144 pub fn new(ctx: Context, items: impl IntoIterator<Item = LocExpr>) -> Self {145 Self {146 ctx,147 cached: Cc::new(RefCell::new(148 items.into_iter().map(ArrayThunk::Waiting).collect(),149 )),150 }151 }152}153impl ArrayLike for ExprArray {154 fn len(&self) -> usize {155 self.cached.borrow().len()156 }157 fn get(&self, index: usize) -> Result<Option<Val>> {158 if index >= self.len() {159 return Ok(None);160 }161 match &self.cached.borrow()[index] {162 ArrayThunk::Computed(c) => return Ok(Some(c.clone())),163 ArrayThunk::Errored(e) => return Err(e.clone()),164 ArrayThunk::Pending => return Err(InfiniteRecursionDetected.into()),165 ArrayThunk::Waiting(..) => {}166 };167168 let ArrayThunk::Waiting(expr) =169 replace(&mut self.cached.borrow_mut()[index], ArrayThunk::Pending)170 else {171 unreachable!()172 };173174 let new_value = match evaluate(self.ctx.clone(), &expr) {175 Ok(v) => v,176 Err(e) => {177 self.cached.borrow_mut()[index] = ArrayThunk::Errored(e.clone());178 return Err(e);179 }180 };181 self.cached.borrow_mut()[index] = ArrayThunk::Computed(new_value.clone());182 Ok(Some(new_value))183 }184 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {185 #[derive(Trace)]186 struct ArrayElement {187 arr_thunk: ExprArray,188 index: usize,189 }190191 impl ThunkValue for ArrayElement {192 type Output = Val;193194 fn get(self: Box<Self>) -> Result<Self::Output> {195 self.arr_thunk196 .get(self.index)197 .transpose()198 .expect("index checked")199 }200 }201202 if index >= self.len() {203 return None;204 }205 match &self.cached.borrow()[index] {206 ArrayThunk::Computed(c) => return Some(Thunk::evaluated(c.clone())),207 ArrayThunk::Errored(e) => return Some(Thunk::errored(e.clone())),208 ArrayThunk::Waiting(_) | ArrayThunk::Pending => {}209 };210211 Some(Thunk::new(ArrayElement {212 arr_thunk: self.clone(),213 index,214 }))215 }216 fn get_cheap(&self, _index: usize) -> Option<Val> {217 None218 }219 fn is_cheap(&self) -> bool {220 false221 }222}223224#[derive(Trace, Debug)]225pub struct ExtendedArray {226 pub a: ArrValue,227 pub b: ArrValue,228 split: usize,229 len: usize,230}231impl ExtendedArray {232 pub fn new(a: ArrValue, b: ArrValue) -> Self {233 let a_len = a.len();234 let b_len = b.len();235 Self {236 a,237 b,238 split: a_len,239 len: a_len.checked_add(b_len).expect("too large array value"),240 }241 }242}243244struct WithExactSize<I>(I, usize);245impl<I, T> Iterator for WithExactSize<I>246where247 I: Iterator<Item = T>,248{249 type Item = T;250251 fn next(&mut self) -> Option<Self::Item> {252 self.0.next()253 }254 fn nth(&mut self, n: usize) -> Option<Self::Item> {255 self.0.nth(n)256 }257 fn size_hint(&self) -> (usize, Option<usize>) {258 (self.1, Some(self.1))259 }260}261impl<I> DoubleEndedIterator for WithExactSize<I>262where263 I: DoubleEndedIterator,264{265 fn next_back(&mut self) -> Option<Self::Item> {266 self.0.next_back()267 }268 fn nth_back(&mut self, n: usize) -> Option<Self::Item> {269 self.0.nth_back(n)270 }271}272impl<I> ExactSizeIterator for WithExactSize<I>273where274 I: Iterator,275{276 fn len(&self) -> usize {277 self.1278 }279}280impl ArrayLike for ExtendedArray {281 fn get(&self, index: usize) -> Result<Option<Val>> {282 if self.split > index {283 self.a.get(index)284 } else {285 self.b.get(index - self.split)286 }287 }288 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {289 if self.split > index {290 self.a.get_lazy(index)291 } else {292 self.b.get_lazy(index - self.split)293 }294 }295296 fn len(&self) -> usize {297 self.len298 }299300 fn get_cheap(&self, index: usize) -> Option<Val> {301 if self.split > index {302 self.a.get_cheap(index)303 } else {304 self.b.get_cheap(index - self.split)305 }306 }307 fn is_cheap(&self) -> bool {308 self.a.is_cheap() && self.b.is_cheap()309 }310}311312#[derive(Trace, Debug)]313pub struct LazyArray(pub Vec<Thunk<Val>>);314impl ArrayLike for LazyArray {315 fn len(&self) -> usize {316 self.0.len()317 }318 fn get(&self, index: usize) -> Result<Option<Val>> {319 let Some(v) = self.0.get(index) else {320 return Ok(None);321 };322 v.evaluate().map(Some)323 }324 fn get_cheap(&self, _index: usize) -> Option<Val> {325 None326 }327 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {328 self.0.get(index).cloned()329 }330 fn is_cheap(&self) -> bool {331 false332 }333}334335#[derive(Trace, Debug)]336pub struct EagerArray(pub Vec<Val>);337impl ArrayLike for EagerArray {338 fn len(&self) -> usize {339 self.0.len()340 }341342 fn get(&self, index: usize) -> Result<Option<Val>> {343 Ok(self.0.get(index).cloned())344 }345346 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {347 self.0.get(index).cloned().map(Thunk::evaluated)348 }349350 fn get_cheap(&self, index: usize) -> Option<Val> {351 self.0.get(index).cloned()352 }353 fn is_cheap(&self) -> bool {354 true355 }356}357358/// Inclusive range type359#[derive(Debug, Trace, PartialEq, Eq)]360pub struct RangeArray {361 start: i32,362 end: i32,363}364impl RangeArray {365 pub fn empty() -> Self {366 Self::new_exclusive(0, 0)367 }368 pub fn new_exclusive(start: i32, end: i32) -> Self {369 end.checked_sub(1)370 .map_or_else(Self::empty, |end| Self { start, end })371 }372 pub fn new_inclusive(start: i32, end: i32) -> Self {373 Self { start, end }374 }375 fn range(&self) -> impl Iterator<Item = i32> + ExactSizeIterator + DoubleEndedIterator {376 WithExactSize(377 self.start..=self.end,378 (self.end as usize)379 .wrapping_sub(self.start as usize)380 .wrapping_add(1),381 )382 }383}384385impl ArrayLike for RangeArray {386 fn len(&self) -> usize {387 self.range().len()388 }389 fn is_empty(&self) -> bool {390 self.range().len() == 0391 }392393 fn get(&self, index: usize) -> Result<Option<Val>> {394 Ok(self.get_cheap(index))395 }396397 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {398 self.get_cheap(index).map(Thunk::evaluated)399 }400401 fn get_cheap(&self, index: usize) -> Option<Val> {402 self.range().nth(index).map(|i| Val::Num(f64::from(i)))403 }404 fn is_cheap(&self) -> bool {405 true406 }407}408409#[derive(Debug, Trace)]410pub struct ReverseArray(pub ArrValue);411impl ArrayLike for ReverseArray {412 fn len(&self) -> usize {413 self.0.len()414 }415416 fn get(&self, index: usize) -> Result<Option<Val>> {417 self.0.get(self.0.len() - index - 1)418 }419420 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {421 self.0.get_lazy(self.0.len() - index - 1)422 }423424 fn get_cheap(&self, index: usize) -> Option<Val> {425 self.0.get_cheap(self.0.len() - index - 1)426 }427 fn is_cheap(&self) -> bool {428 self.0.is_cheap()429 }430}431432#[derive(Trace, Debug, Clone)]433pub struct MappedArray {434 inner: ArrValue,435 cached: Cc<RefCell<Vec<ArrayThunk<()>>>>,436 mapper: FuncVal,437}438impl MappedArray {439 pub fn new(inner: ArrValue, mapper: FuncVal) -> Self {440 let len = inner.len();441 Self {442 inner,443 cached: Cc::new(RefCell::new(vec![ArrayThunk::Waiting(()); len])),444 mapper,445 }446 }447}448impl ArrayLike for MappedArray {449 fn len(&self) -> usize {450 self.cached.borrow().len()451 }452453 fn get(&self, index: usize) -> Result<Option<Val>> {454 if index >= self.len() {455 return Ok(None);456 }457 match &self.cached.borrow()[index] {458 ArrayThunk::Computed(c) => return Ok(Some(c.clone())),459 ArrayThunk::Errored(e) => return Err(e.clone()),460 ArrayThunk::Pending => return Err(InfiniteRecursionDetected.into()),461 ArrayThunk::Waiting(..) => {}462 };463464 let ArrayThunk::Waiting(_) =465 replace(&mut self.cached.borrow_mut()[index], ArrayThunk::Pending)466 else {467 unreachable!()468 };469470 let val = self471 .inner472 .get(index)473 .transpose()474 .expect("index checked")475 .and_then(|r| self.mapper.evaluate_simple(&(r,), false));476477 let new_value = match val {478 Ok(v) => v,479 Err(e) => {480 self.cached.borrow_mut()[index] = ArrayThunk::Errored(e.clone());481 return Err(e);482 }483 };484 self.cached.borrow_mut()[index] = ArrayThunk::Computed(new_value.clone());485 Ok(Some(new_value))486 }487 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {488 #[derive(Trace)]489 struct ArrayElement {490 arr_thunk: MappedArray,491 index: usize,492 }493494 impl ThunkValue for ArrayElement {495 type Output = Val;496497 fn get(self: Box<Self>) -> Result<Self::Output> {498 self.arr_thunk499 .get(self.index)500 .transpose()501 .expect("index checked")502 }503 }504505 if index >= self.len() {506 return None;507 }508 match &self.cached.borrow()[index] {509 ArrayThunk::Computed(c) => return Some(Thunk::evaluated(c.clone())),510 ArrayThunk::Errored(e) => return Some(Thunk::errored(e.clone())),511 ArrayThunk::Waiting(_) | ArrayThunk::Pending => {}512 };513514 Some(Thunk::new(ArrayElement {515 arr_thunk: self.clone(),516 index,517 }))518 }519520 fn get_cheap(&self, _index: usize) -> Option<Val> {521 None522 }523 fn is_cheap(&self) -> bool {524 false525 }526}527528#[derive(Trace, Debug)]529pub struct RepeatedArray {530 data: ArrValue,531 repeats: usize,532 total_len: usize,533}534impl RepeatedArray {535 pub fn new(data: ArrValue, repeats: usize) -> Option<Self> {536 let total_len = data.len().checked_mul(repeats)?;537 Some(Self {538 data,539 repeats,540 total_len,541 })542 }543}544545impl ArrayLike for RepeatedArray {546 fn len(&self) -> usize {547 self.total_len548 }549550 fn get(&self, index: usize) -> Result<Option<Val>> {551 if index > self.total_len {552 return Ok(None);553 }554 self.data.get(index % self.data.len())555 }556557 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {558 if index > self.total_len {559 return None;560 }561 self.data.get_lazy(index % self.data.len())562 }563564 fn get_cheap(&self, index: usize) -> Option<Val> {565 if index > self.total_len {566 return None;567 }568 self.data.get_cheap(index % self.data.len())569 }570 fn is_cheap(&self) -> bool {571 self.data.is_cheap()572 }573}574575#[derive(Trace, Debug)]576pub struct PickObjectValues {577 obj: ObjValue,578 keys: Vec<IStr>,579}580581impl PickObjectValues {582 pub fn new(obj: ObjValue, keys: Vec<IStr>) -> Self {583 Self { obj, keys }584 }585}586587impl ArrayLike for PickObjectValues {588 fn len(&self) -> usize {589 self.keys.len()590 }591592 fn get(&self, index: usize) -> Result<Option<Val>> {593 let Some(key) = self.keys.get(index) else {594 return Ok(None);595 };596 Ok(Some(self.obj.get_or_bail(key.clone())?))597 }598599 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {600 let Some(key) = self.keys.get(index) else {601 return None;602 };603 Some(self.obj.get_lazy_or_bail(key.clone()))604 }605606 fn get_cheap(&self, _index: usize) -> Option<Val> {607 None608 }609610 fn is_cheap(&self) -> bool {611 false612 }613}614615#[derive(Trace, Debug)]616pub struct PickObjectKeyValues {617 obj: ObjValue,618 keys: Vec<IStr>,619}620621impl PickObjectKeyValues {622 pub fn new(obj: ObjValue, keys: Vec<IStr>) -> Self {623 Self { obj, keys }624 }625}626627#[derive(Typed)]628pub struct KeyValue {629 key: IStr,630 value: Thunk<Val>,631}632633impl ArrayLike for PickObjectKeyValues {634 fn len(&self) -> usize {635 self.keys.len()636 }637638 fn get(&self, index: usize) -> Result<Option<Val>> {639 let Some(key) = self.keys.get(index) else {640 return Ok(None);641 };642 Ok(Some(643 KeyValue::into_untyped(KeyValue {644 key: key.clone(),645 value: Thunk::evaluated(self.obj.get_or_bail(key.clone())?),646 })647 .expect("convertible"),648 ))649 }650651 fn get_lazy(&self, index: usize) -> Option<Thunk<Val>> {652 let Some(key) = self.keys.get(index) else {653 return None;654 };655 // Nothing can fail in the key part, yet value is still656 // lazy-evaluated657 Some(Thunk::evaluated(658 KeyValue::into_untyped(KeyValue {659 key: key.clone(),660 value: self.obj.get_lazy_or_bail(key.clone()),661 })662 .expect("convertible"),663 ))664 }665666 fn get_cheap(&self, _index: usize) -> Option<Val> {667 None668 }669670 fn is_cheap(&self) -> bool {671 false672 }673}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.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -449,25 +449,21 @@
}
fn from_untyped(value: Val) -> Result<Self> {
- match &value {
- Val::Arr(a) => {
- if let Some(bytes) = a.as_any().downcast_ref::<BytesArray>() {
- return Ok(bytes.0.as_slice().into());
- };
- <Self as Typed>::TYPE.check(&value)?;
- // Any::downcast_ref::<ByteArray>(&a);
- let mut out = Vec::with_capacity(a.len());
- for e in a.iter() {
- let r = e?;
- out.push(u8::from_untyped(r)?);
- }
- Ok(out.as_slice().into())
- }
- _ => {
- <Self as Typed>::TYPE.check(&value)?;
- unreachable!()
- }
+ let Val::Arr(a) = &value else {
+ <Self as Typed>::TYPE.check(&value)?;
+ unreachable!()
+ };
+ if let Some(bytes) = a.as_any().downcast_ref::<BytesArray>() {
+ return Ok(bytes.0.as_slice().into());
+ };
+ <Self as Typed>::TYPE.check(&value)?;
+ // Any::downcast_ref::<ByteArray>(&a);
+ let mut out = Vec::with_capacity(a.len());
+ for e in a.iter() {
+ let r = e?;
+ out.push(u8::from_untyped(r)?);
}
+ Ok(out.as_slice().into())
}
}
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 {};