difftreelog
style fix clippy warnings
in: master
5 files changed
crates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth15#[derive(Clone, Copy)]15#[derive(Clone, Copy)]16pub struct CallLocation<'l>(pub Option<&'l ExprLocation>);16pub struct CallLocation<'l>(pub Option<&'l ExprLocation>);17impl<'l> CallLocation<'l> {17impl<'l> CallLocation<'l> {18 pub fn new(loc: &'l ExprLocation) -> Self {18 pub const fn new(loc: &'l ExprLocation) -> Self {19 Self(Some(loc))19 Self(Some(loc))20 }20 }21}21}22impl CallLocation<'static> {22impl CallLocation<'static> {23 pub fn native() -> Self {23 pub const fn native() -> Self {24 Self(None)24 Self(None)25 }25 }26}26}crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -20,7 +20,7 @@
Val::Arr(a) => {
let mut out = Vec::with_capacity(a.len());
for item in a.iter() {
- out.push((&item?).try_into()?);
+ out.push(item?.try_into()?);
}
Self::Array(out)
}
@@ -29,8 +29,8 @@
for key in o.fields() {
out.insert(
(&key as &str).into(),
- (&o.get(key)?
- .expect("key is present in fields, so value should exist"))
+ o.get(key)?
+ .expect("key is present in fields, so value should exist")
.try_into()?,
);
}
@@ -40,6 +40,13 @@
})
}
}
+impl TryFrom<Val> for Value {
+ type Error = LocError;
+
+ fn try_from(value: Val) -> Result<Self, Self::Error> {
+ <Self as TryFrom<&Val>>::try_from(&value)
+ }
+}
impl TryFrom<&Value> for Val {
type Error = LocError;
@@ -68,3 +75,10 @@
})
}
}
+impl TryFrom<Value> for Val {
+ type Error = LocError;
+
+ fn try_from(value: Value) -> Result<Self, Self::Error> {
+ <Self as TryFrom<&Value>>::try_from(&value)
+ }
+}
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -442,7 +442,7 @@
fn try_from(value: Val) -> Result<Self, Self::Error> {
<Self as Typed>::TYPE.check(&value)?;
match value {
- Val::Func(FuncVal::Normal(desc)) => Ok(desc.clone()),
+ Val::Func(FuncVal::Normal(desc)) => Ok(desc),
Val::Func(_) => throw!(RuntimeError("expected normal function, not builtin".into())),
_ => unreachable!(),
}
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -126,15 +126,6 @@
}
}
-impl PartialEq for FuncVal {
- fn eq(&self, other: &Self) -> bool {
- match (self, other) {
- (Self::Normal(a), Self::Normal(b)) => a == b,
- (Self::StaticBuiltin(an), Self::StaticBuiltin(bn)) => std::ptr::eq(*an, *bn),
- (..) => false,
- }
- }
-}
impl FuncVal {
pub fn args_len(&self) -> usize {
match self {
@@ -353,13 +344,13 @@
}
impl Val {
- pub fn as_bool(&self) -> Option<bool> {
+ pub const fn as_bool(&self) -> Option<bool> {
match self {
Val::Bool(v) => Some(*v),
_ => None,
}
}
- pub fn as_null(&self) -> Option<()> {
+ pub const fn as_null(&self) -> Option<()> {
match self {
Val::Null => Some(()),
_ => None,
@@ -371,7 +362,7 @@
_ => None,
}
}
- pub fn as_num(&self) -> Option<f64> {
+ pub const fn as_num(&self) -> Option<f64> {
match self {
Val::Num(n) => Some(*n),
_ => None,
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -35,7 +35,7 @@
fn path_is(path: &Path, needed: &str) -> bool {
path.leading_colon.is_none()
- && path.segments.len() >= 1
+ && !path.segments.is_empty()
&& path.segments.iter().last().unwrap().ident == needed
}
@@ -119,7 +119,7 @@
enum ArgInfo {
Normal {
- ty: Type,
+ ty: Box<Type>,
is_option: bool,
name: String,
// ident: Ident,
@@ -147,27 +147,27 @@
))
}
};
- let ty = &typed.ty as &Type;
- if type_is_path(&ty, "CallLocation").is_some() {
+ let ty = &typed.ty;
+ if type_is_path(ty, "CallLocation").is_some() {
return Ok(Self::Location);
- } else if type_is_path(&ty, "Self").is_some() {
+ } else if type_is_path(ty, "Self").is_some() {
return Ok(Self::This);
- } else if type_is_path(&ty, "LazyVal").is_some() {
+ } else if type_is_path(ty, "LazyVal").is_some() {
return Ok(Self::Lazy {
is_option: false,
name: ident.to_string(),
});
}
- let (is_option, ty) = if let Some(ty) = extract_type_from_option(&ty)? {
- if type_is_path(&ty, "LazyVal").is_some() {
+ let (is_option, ty) = if let Some(ty) = extract_type_from_option(ty)? {
+ if type_is_path(ty, "LazyVal").is_some() {
return Ok(Self::Lazy {
is_option: true,
name: ident.to_string(),
});
}
- (true, ty.clone())
+ (true, Box::new(ty.clone()))
} else {
(false, ty.clone())
};
@@ -210,7 +210,7 @@
.sig
.inputs
.iter()
- .map(|a| ArgInfo::parse(a))
+ .map(ArgInfo::parse)
.collect::<Result<Vec<_>>>()?;
let params_desc = args.iter().flat_map(|a| match a {
@@ -380,8 +380,7 @@
struct TypedField<'f>(&'f syn::Field, TypedAttr);
impl<'f> TypedField<'f> {
fn try_new(field: &'f syn::Field) -> Result<Self> {
- let attr =
- parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_else(Default::default);
+ let attr = parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_default();
if field.ident.is_none() {
return Err(Error::new(
field.span(),
@@ -468,17 +467,15 @@
out.member(#name.into()).value(self.#ident.try_into()?);
}
}
+ } else if self.is_option() {
+ quote! {
+ if let Some(value) = self.#ident {
+ value.serialize(out)?;
+ }
+ }
} else {
- if self.is_option() {
- quote! {
- if let Some(value) = self.#ident {
- value.serialize(out)?;
- }
- }
- } else {
- quote! {
- self.#ident.serialize(out)?;
- }
+ quote! {
+ self.#ident.serialize(out)?;
}
}
}