Skip to content

Commit 900defd

Browse files
committed
chore: resolve Clippy warnings
1 parent 14be01a commit 900defd

File tree

10 files changed

+38
-42
lines changed

10 files changed

+38
-42
lines changed

crates/jrsonnet-evaluator/src/arr/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use jrsonnet_parser::LocExpr;
77
use crate::{function::FuncVal, gc::TraceBox, tb, Context, Result, Thunk, Val};
88

99
mod spec;
10-
pub use spec::ArrayLike;
11-
pub(crate) use spec::*;
10+
pub use spec::{ArrayLike, *};
1211

1312
/// Represents a Jsonnet array value.
1413
#[derive(Debug, Clone, Trace)]

crates/jrsonnet-evaluator/src/arr/spec.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl ArrayLike for ExprArray {
205205
match &self.cached.borrow()[index] {
206206
ArrayThunk::Computed(c) => return Some(Thunk::evaluated(c.clone())),
207207
ArrayThunk::Errored(e) => return Some(Thunk::errored(e.clone())),
208-
ArrayThunk::Waiting(_) | ArrayThunk::Pending => {}
208+
ArrayThunk::Waiting(()) | ArrayThunk::Pending => {}
209209
};
210210

211211
Some(Thunk::new(ArrayElement {
@@ -372,7 +372,7 @@ impl RangeArray {
372372
pub fn new_inclusive(start: i32, end: i32) -> Self {
373373
Self { start, end }
374374
}
375-
fn range(&self) -> impl Iterator<Item = i32> + ExactSizeIterator + DoubleEndedIterator {
375+
fn range(&self) -> impl ExactSizeIterator<Item = i32> + DoubleEndedIterator {
376376
WithExactSize(
377377
self.start..=self.end,
378378
(self.end as usize)
@@ -461,7 +461,7 @@ impl ArrayLike for MappedArray {
461461
ArrayThunk::Waiting(..) => {}
462462
};
463463

464-
let ArrayThunk::Waiting(_) =
464+
let ArrayThunk::Waiting(()) =
465465
replace(&mut self.cached.borrow_mut()[index], ArrayThunk::Pending)
466466
else {
467467
unreachable!()
@@ -508,7 +508,7 @@ impl ArrayLike for MappedArray {
508508
match &self.cached.borrow()[index] {
509509
ArrayThunk::Computed(c) => return Some(Thunk::evaluated(c.clone())),
510510
ArrayThunk::Errored(e) => return Some(Thunk::errored(e.clone())),
511-
ArrayThunk::Waiting(_) | ArrayThunk::Pending => {}
511+
ArrayThunk::Waiting(()) | ArrayThunk::Pending => {}
512512
};
513513

514514
Some(Thunk::new(ArrayElement {

crates/jrsonnet-evaluator/src/evaluate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn evaluate_comp(
8989
specs: &[CompSpec],
9090
callback: &mut impl FnMut(Context) -> Result<()>,
9191
) -> Result<()> {
92-
match specs.get(0) {
92+
match specs.first() {
9393
None => callback(ctx)?,
9494
Some(CompSpec::IfSpec(IfSpecData(cond))) => {
9595
if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {

crates/jrsonnet-evaluator/src/function/builtin.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use jrsonnet_interner::IStr;
66
use super::{arglike::ArgsLike, parse::parse_builtin_call, CallLocation};
77
use crate::{gc::TraceBox, tb, Context, Result, Val};
88

9-
/// Can't have str | IStr, because constant BuiltinParam causes
9+
/// Can't have [`str`] | [`IStr`], because constant [`BuiltinParam`] causes
1010
/// E0492: constant functions cannot refer to interior mutable data
1111
#[derive(Clone, Trace)]
1212
pub struct ParamName(Option<Cow<'static, str>>);
@@ -27,10 +27,9 @@ impl ParamName {
2727
}
2828
impl PartialEq<IStr> for ParamName {
2929
fn eq(&self, other: &IStr) -> bool {
30-
match &self.0 {
31-
Some(s) => s.as_bytes() == other.as_bytes(),
32-
None => false,
33-
}
30+
self.0
31+
.as_ref()
32+
.map_or(false, |s| s.as_bytes() == other.as_bytes())
3433
}
3534
}
3635

@@ -87,7 +86,7 @@ impl NativeCallback {
8786
params: params
8887
.into_iter()
8988
.map(|n| BuiltinParam {
90-
name: ParamName::new_dynamic(n.to_string()),
89+
name: ParamName::new_dynamic(n),
9190
has_default: false,
9291
})
9392
.collect(),

crates/jrsonnet-evaluator/src/integrations/serde.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,18 @@ impl<'de> Deserialize<'de> for Val {
152152
impl Serialize for Val {
153153
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
154154
where
155-
S: serde::Serializer,
155+
S: Serializer,
156156
{
157157
match self {
158158
Val::Bool(v) => serializer.serialize_bool(*v),
159159
Val::Null => serializer.serialize_none(),
160160
Val::Str(s) => serializer.serialize_str(&s.clone().into_flat()),
161161
Val::Num(n) => {
162-
if n.fract() != 0.0 {
163-
serializer.serialize_f64(*n)
164-
} else {
162+
if n.fract() == 0.0 {
165163
let n = *n as i64;
166164
serializer.serialize_i64(n)
165+
} else {
166+
serializer.serialize_f64(*n)
167167
}
168168
}
169169
#[cfg(feature = "exp-bigint")]

crates/jrsonnet-evaluator/src/manifest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ pub fn manifest_json_ex(val: &Val, options: &JsonFormat<'_>) -> Result<String> {
175175
manifest_json_ex_buf(val, &mut out, &mut String::new(), options)?;
176176
Ok(out)
177177
}
178+
#[allow(clippy::too_many_lines)]
178179
fn manifest_json_ex_buf(
179180
val: &Val,
180181
buf: &mut String,

crates/jrsonnet-evaluator/src/obj.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub struct OopObject {
163163
this_entries: Cc<GcHashMap<IStr, ObjMember>>,
164164
value_cache: RefCell<GcHashMap<(IStr, Option<WeakObjValue>), CacheValue>>,
165165
}
166+
#[allow(clippy::missing_fields_in_debug)]
166167
impl Debug for OopObject {
167168
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168169
f.debug_struct("OopObject")
@@ -347,7 +348,7 @@ impl ObjValue {
347348
out.with_super(self);
348349
let mut member = out.field(key);
349350
if value.flags.add() {
350-
member = member.add()
351+
member = member.add();
351352
}
352353
if let Some(loc) = value.location {
353354
member = member.with_location(loc);
@@ -395,7 +396,7 @@ impl ObjValue {
395396

396397
pub fn get(&self, key: IStr) -> Result<Option<Val>> {
397398
self.run_assertions()?;
398-
self.get_for(key, self.0.this().unwrap_or(self.clone()))
399+
self.get_for(key, self.0.this().unwrap_or_else(|| self.clone()))
399400
}
400401

401402
pub fn get_for(&self, key: IStr, this: ObjValue) -> Result<Option<Val>> {
@@ -474,7 +475,7 @@ impl ObjValue {
474475
type Output = Val;
475476

476477
fn get(self: Box<Self>) -> Result<Self::Output> {
477-
Ok(self.obj.get_or_bail(self.key)?)
478+
self.obj.get_or_bail(self.key)
478479
}
479480
}
480481

@@ -495,7 +496,7 @@ impl ObjValue {
495496
SuperDepth::default(),
496497
&mut |depth, index, name, visibility| {
497498
let new_sort_key = FieldSortKey::new(depth, index);
498-
let entry = out.entry(name.clone());
499+
let entry = out.entry(name);
499500
let (visible, _) = entry.or_insert((true, new_sort_key));
500501
match visibility {
501502
Visibility::Normal => {}
@@ -634,7 +635,7 @@ impl OopObject {
634635
SuperDepth::default(),
635636
&mut |depth, index, name, visibility| {
636637
let new_sort_key = FieldSortKey::new(depth, index);
637-
let entry = out.entry(name.clone());
638+
let entry = out.entry(name);
638639
let (visible, _) = entry.or_insert((true, new_sort_key));
639640
match visibility {
640641
Visibility::Normal => {}

crates/jrsonnet-evaluator/src/stdlib/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub fn parse_code(str: &str) -> ParseResult<'_, Code<'_>> {
248248
let (cflags, str) = try_parse_cflags(str)?;
249249
let (width, str) = try_parse_field_width(str)?;
250250
let (precision, str) = try_parse_precision(str)?;
251-
let (_, str) = try_parse_length_modifier(str)?;
251+
let ((), str) = try_parse_length_modifier(str)?;
252252
let (convtype, str) = parse_conversion_type(str)?;
253253

254254
Ok((

crates/jrsonnet-evaluator/src/typed/conversions.rs

+14-18
Original file line numberDiff line numberDiff line change
@@ -433,25 +433,21 @@ impl Typed for IBytes {
433433
}
434434

435435
fn from_untyped(value: Val) -> Result<Self> {
436-
match &value {
437-
Val::Arr(a) => {
438-
if let Some(bytes) = a.as_any().downcast_ref::<BytesArray>() {
439-
return Ok(bytes.0.as_slice().into());
440-
};
441-
<Self as Typed>::TYPE.check(&value)?;
442-
// Any::downcast_ref::<ByteArray>(&a);
443-
let mut out = Vec::with_capacity(a.len());
444-
for e in a.iter() {
445-
let r = e?;
446-
out.push(u8::from_untyped(r)?);
447-
}
448-
Ok(out.as_slice().into())
449-
}
450-
_ => {
451-
<Self as Typed>::TYPE.check(&value)?;
452-
unreachable!()
453-
}
436+
let Val::Arr(a) = &value else {
437+
<Self as Typed>::TYPE.check(&value)?;
438+
unreachable!()
439+
};
440+
if let Some(bytes) = a.as_any().downcast_ref::<BytesArray>() {
441+
return Ok(bytes.0.as_slice().into());
442+
};
443+
<Self as Typed>::TYPE.check(&value)?;
444+
// Any::downcast_ref::<ByteArray>(&a);
445+
let mut out = Vec::with_capacity(a.len());
446+
for e in a.iter() {
447+
let r = e?;
448+
out.push(u8::from_untyped(r)?);
454449
}
450+
Ok(out.as_slice().into())
455451
}
456452
}
457453

crates/jrsonnet-evaluator/src/typed/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn push_type_description(
9090
item: impl Fn() -> Result<()>,
9191
) -> Result<()> {
9292
State::push_description(error_reason, || match item() {
93-
Ok(_) => Ok(()),
93+
Ok(()) => Ok(()),
9494
Err(mut e) => {
9595
if let ErrorKind::TypeError(e) = &mut e.error_mut() {
9696
(e.1).0.push(path());

0 commit comments

Comments
 (0)