git.delta.rocks / jrsonnet / refs/commits / 4f4be44d138e

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2022-04-20parent: #ed4ee4d.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
15#[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}
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
20 Val::Arr(a) => {20 Val::Arr(a) => {
21 let mut out = Vec::with_capacity(a.len());21 let mut out = Vec::with_capacity(a.len());
22 for item in a.iter() {22 for item in a.iter() {
23 out.push((&item?).try_into()?);23 out.push(item?.try_into()?);
24 }24 }
25 Self::Array(out)25 Self::Array(out)
26 }26 }
29 for key in o.fields() {29 for key in o.fields() {
30 out.insert(30 out.insert(
31 (&key as &str).into(),31 (&key as &str).into(),
32 (&o.get(key)?32 o.get(key)?
33 .expect("key is present in fields, so value should exist"))33 .expect("key is present in fields, so value should exist")
34 .try_into()?,34 .try_into()?,
35 );35 );
36 }36 }
40 })40 })
41 }41 }
42}42}
43impl TryFrom<Val> for Value {
44 type Error = LocError;
45
46 fn try_from(value: Val) -> Result<Self, Self::Error> {
47 <Self as TryFrom<&Val>>::try_from(&value)
48 }
49}
4350
44impl TryFrom<&Value> for Val {51impl TryFrom<&Value> for Val {
45 type Error = LocError;52 type Error = LocError;
68 })75 })
69 }76 }
70}77}
78impl TryFrom<Value> for Val {
79 type Error = LocError;
80
81 fn try_from(value: Value) -> Result<Self, Self::Error> {
82 <Self as TryFrom<&Value>>::try_from(&value)
83 }
84}
7185
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
442 fn try_from(value: Val) -> Result<Self, Self::Error> {442 fn try_from(value: Val) -> Result<Self, Self::Error> {
443 <Self as Typed>::TYPE.check(&value)?;443 <Self as Typed>::TYPE.check(&value)?;
444 match value {444 match value {
445 Val::Func(FuncVal::Normal(desc)) => Ok(desc.clone()),445 Val::Func(FuncVal::Normal(desc)) => Ok(desc),
446 Val::Func(_) => throw!(RuntimeError("expected normal function, not builtin".into())),446 Val::Func(_) => throw!(RuntimeError("expected normal function, not builtin".into())),
447 _ => unreachable!(),447 _ => unreachable!(),
448 }448 }
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
126 }126 }
127}127}
128128
129impl 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}
354345
355impl 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,
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
3535
36fn path_is(path: &Path, needed: &str) -> bool {36fn path_is(path: &Path, needed: &str) -> bool {
37 path.leading_colon.is_none()37 path.leading_colon.is_none()
38 && path.segments.len() >= 138 && !path.segments.is_empty()
39 && path.segments.iter().last().unwrap().ident == needed39 && path.segments.iter().last().unwrap().ident == needed
40}40}
4141
119119
120enum ArgInfo {120enum ArgInfo {
121 Normal {121 Normal {
122 ty: Type,122 ty: Box<Type>,
123 is_option: bool,123 is_option: bool,
124 name: String,124 name: String,
125 // ident: Ident,125 // ident: Ident,
147 ))147 ))
148 }148 }
149 };149 };
150 let ty = &typed.ty as &Type;150 let ty = &typed.ty;
151 if type_is_path(&ty, "CallLocation").is_some() {151 if type_is_path(ty, "CallLocation").is_some() {
152 return Ok(Self::Location);152 return Ok(Self::Location);
153 } else if type_is_path(&ty, "Self").is_some() {153 } else if type_is_path(ty, "Self").is_some() {
154 return Ok(Self::This);154 return Ok(Self::This);
155 } else if type_is_path(&ty, "LazyVal").is_some() {155 } else if type_is_path(ty, "LazyVal").is_some() {
156 return Ok(Self::Lazy {156 return Ok(Self::Lazy {
157 is_option: false,157 is_option: false,
158 name: ident.to_string(),158 name: ident.to_string(),
159 });159 });
160 }160 }
161161
162 let (is_option, ty) = if let Some(ty) = extract_type_from_option(&ty)? {162 let (is_option, ty) = if let Some(ty) = extract_type_from_option(ty)? {
163 if type_is_path(&ty, "LazyVal").is_some() {163 if type_is_path(ty, "LazyVal").is_some() {
164 return Ok(Self::Lazy {164 return Ok(Self::Lazy {
165 is_option: true,165 is_option: true,
166 name: ident.to_string(),166 name: ident.to_string(),
167 });167 });
168 }168 }
169169
170 (true, ty.clone())170 (true, Box::new(ty.clone()))
171 } else {171 } else {
172 (false, ty.clone())172 (false, ty.clone())
173 };173 };
210 .sig210 .sig
211 .inputs211 .inputs
212 .iter()212 .iter()
213 .map(|a| ArgInfo::parse(a))213 .map(ArgInfo::parse)
214 .collect::<Result<Vec<_>>>()?;214 .collect::<Result<Vec<_>>>()?;
215215
216 let params_desc = args.iter().flat_map(|a| match a {216 let params_desc = args.iter().flat_map(|a| match a {
380struct TypedField<'f>(&'f syn::Field, TypedAttr);380struct TypedField<'f>(&'f syn::Field, TypedAttr);
381impl<'f> TypedField<'f> {381impl<'f> TypedField<'f> {
382 fn try_new(field: &'f syn::Field) -> Result<Self> {382 fn try_new(field: &'f syn::Field) -> Result<Self> {
383 let attr =383 let attr = parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_default();
384 parse_attr::<TypedAttr, _>(&field.attrs, "typed")?.unwrap_or_else(Default::default);
385 if field.ident.is_none() {384 if field.ident.is_none() {
386 return Err(Error::new(385 return Err(Error::new(
387 field.span(),386 field.span(),
468 out.member(#name.into()).value(self.#ident.try_into()?);467 out.member(#name.into()).value(self.#ident.try_into()?);
469 }468 }
470 }469 }
471 } else {470 } else if self.is_option() {
472 if self.is_option() {
473 quote! {471 quote! {
474 if let Some(value) = self.#ident {472 if let Some(value) = self.#ident {
480 self.#ident.serialize(out)?;478 self.#ident.serialize(out)?;
481 }479 }
482 }480 }
483 }
484 }481 }
485482
486 fn as_option(&self) -> Option<&Type> {483 fn as_option(&self) -> Option<&Type> {