difftreelog
style fix clippy warnings
in: master
5 files changed
crates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -15,12 +15,12 @@
#[derive(Clone, Copy)]
pub struct CallLocation<'l>(pub Option<&'l ExprLocation>);
impl<'l> CallLocation<'l> {
- pub fn new(loc: &'l ExprLocation) -> Self {
+ pub const fn new(loc: &'l ExprLocation) -> Self {
Self(Some(loc))
}
}
impl CallLocation<'static> {
- pub fn native() -> Self {
+ pub const fn native() -> Self {
Self(None)
}
}
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.rsdiffbeforeafterboth126 }126 }127}127}128128129impl PartialEq for FuncVal {130 fn eq(&self, other: &Self) -> bool {131 match (self, other) {132 (Self::Normal(a), Self::Normal(b)) => a == b,133 (Self::StaticBuiltin(an), Self::StaticBuiltin(bn)) => std::ptr::eq(*an, *bn),134 (..) => false,135 }136 }137}138impl FuncVal {129impl FuncVal {139 pub fn args_len(&self) -> usize {130 pub fn args_len(&self) -> usize {140 match self {131 match self {353}344}354345355impl Val {346impl Val {356 pub fn as_bool(&self) -> Option<bool> {347 pub const fn as_bool(&self) -> Option<bool> {357 match self {348 match self {358 Val::Bool(v) => Some(*v),349 Val::Bool(v) => Some(*v),359 _ => None,350 _ => None,360 }351 }361 }352 }362 pub fn as_null(&self) -> Option<()> {353 pub const fn as_null(&self) -> Option<()> {363 match self {354 match self {364 Val::Null => Some(()),355 Val::Null => Some(()),365 _ => None,356 _ => None,371 _ => None,362 _ => None,372 }363 }373 }364 }374 pub fn as_num(&self) -> Option<f64> {365 pub const fn as_num(&self) -> Option<f64> {375 match self {366 match self {376 Val::Num(n) => Some(*n),367 Val::Num(n) => Some(*n),377 _ => None,368 _ => 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)?;
}
}
}