Skip to content

Commit

Permalink
chore: resolve Clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvisCraft committed Oct 29, 2023
1 parent 14be01a commit 0c783b1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 41 deletions.
3 changes: 1 addition & 2 deletions crates/jrsonnet-evaluator/src/arr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use jrsonnet_parser::LocExpr;
use crate::{function::FuncVal, gc::TraceBox, tb, Context, Result, Thunk, Val};

mod spec;
pub use spec::ArrayLike;
pub(crate) use spec::*;
pub use spec::{ArrayLike, *};

/// Represents a Jsonnet array value.
#[derive(Debug, Clone, Trace)]
Expand Down
6 changes: 3 additions & 3 deletions crates/jrsonnet-evaluator/src/arr/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl RangeArray {
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)
Expand Down Expand Up @@ -461,7 +461,7 @@ impl ArrayLike for MappedArray {
ArrayThunk::Waiting(..) => {}
};

let ArrayThunk::Waiting(_) =
let ArrayThunk::Waiting(()) =
replace(&mut self.cached.borrow_mut()[index], ArrayThunk::Pending)
else {
unreachable!()
Expand Down Expand Up @@ -508,7 +508,7 @@ impl ArrayLike for MappedArray {
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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/evaluate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn evaluate_comp(
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)?)? {
Expand Down
11 changes: 5 additions & 6 deletions crates/jrsonnet-evaluator/src/function/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use jrsonnet_interner::IStr;
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
/// 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>>);
Expand All @@ -27,10 +27,9 @@ impl ParamName {
}
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())
}
}

Expand Down Expand Up @@ -87,7 +86,7 @@ impl NativeCallback {
params: params
.into_iter()
.map(|n| BuiltinParam {
name: ParamName::new_dynamic(n.to_string()),
name: ParamName::new_dynamic(n),
has_default: false,
})
.collect(),
Expand Down
8 changes: 4 additions & 4 deletions crates/jrsonnet-evaluator/src/integrations/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ impl<'de> Deserialize<'de> for Val {
impl Serialize for Val {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
S: Serializer,
{
match self {
Val::Bool(v) => serializer.serialize_bool(*v),
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")]
Expand Down
1 change: 1 addition & 0 deletions crates/jrsonnet-evaluator/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ pub fn manifest_json_ex(val: &Val, options: &JsonFormat<'_>) -> Result<String> {
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,
Expand Down
11 changes: 6 additions & 5 deletions crates/jrsonnet-evaluator/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub struct OopObject {
this_entries: Cc<GcHashMap<IStr, ObjMember>>,
value_cache: RefCell<GcHashMap<(IStr, Option<WeakObjValue>), CacheValue>>,
}
#[allow(clippy::missing_fields_in_debug)]
impl Debug for OopObject {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("OopObject")
Expand Down Expand Up @@ -347,7 +348,7 @@ impl ObjValue {
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);
Expand Down Expand Up @@ -395,7 +396,7 @@ impl ObjValue {

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>> {
Expand Down Expand Up @@ -474,7 +475,7 @@ impl ObjValue {
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)
}
}

Expand All @@ -495,7 +496,7 @@ impl ObjValue {
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 => {}
Expand Down Expand Up @@ -634,7 +635,7 @@ impl OopObject {
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 => {}
Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/stdlib/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ pub fn parse_code(str: &str) -> ParseResult<'_, Code<'_>> {
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((
Expand Down
32 changes: 14 additions & 18 deletions crates/jrsonnet-evaluator/src/typed/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,25 +433,21 @@ impl Typed for IBytes {
}

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())
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/jrsonnet-evaluator/src/typed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn push_type_description(
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());
Expand Down

0 comments on commit 0c783b1

Please sign in to comment.