From 2d0d919b58c49b86cfabe653a53d39b9a516cd24 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 26 May 2022 20:47:02 +0200 Subject: [PATCH] style: fix warnings with nightly clippy Signed-off-by: Yaroslav Bolyukin --- crates/jrsonnet-cli/src/trace.rs | 2 +- .../jrsonnet-evaluator/src/integrations/serde.rs | 12 ++++++------ crates/jrsonnet-evaluator/src/lib.rs | 5 +++++ crates/jrsonnet-evaluator/src/stdlib/format.rs | 4 ++-- crates/jrsonnet-evaluator/src/stdlib/manifest.rs | 2 +- crates/jrsonnet-evaluator/src/trace/location.rs | 2 +- crates/jrsonnet-evaluator/src/val.rs | 14 +++++++------- crates/jrsonnet-interner/src/inner.rs | 2 +- crates/jrsonnet-parser/src/expr.rs | 14 +++++++------- 9 files changed, 31 insertions(+), 26 deletions(-) diff --git a/crates/jrsonnet-cli/src/trace.rs b/crates/jrsonnet-cli/src/trace.rs index 4aae994e..b4ddf1c8 100644 --- a/crates/jrsonnet-cli/src/trace.rs +++ b/crates/jrsonnet-cli/src/trace.rs @@ -9,7 +9,7 @@ use jrsonnet_evaluator::{ use crate::ConfigureState; -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] pub enum TraceFormatName { Compact, Explaining, diff --git a/crates/jrsonnet-evaluator/src/integrations/serde.rs b/crates/jrsonnet-evaluator/src/integrations/serde.rs index 655c8499..e30d0cc6 100644 --- a/crates/jrsonnet-evaluator/src/integrations/serde.rs +++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs @@ -13,20 +13,20 @@ impl Typed for Value { fn into_untyped(value: Self, s: State) -> Result { Ok(match value { - Value::Null => Val::Null, - Value::Bool(v) => Val::Bool(v), - Value::Number(n) => Val::Num(n.as_f64().ok_or_else(|| { + Self::Null => Val::Null, + Self::Bool(v) => Val::Bool(v), + Self::Number(n) => Val::Num(n.as_f64().ok_or_else(|| { RuntimeError(format!("json number can't be represented as jsonnet: {}", n).into()) })?), - Value::String(s) => Val::Str((&s as &str).into()), - Value::Array(a) => { + Self::String(s) => Val::Str((&s as &str).into()), + Self::Array(a) => { let mut out: Vec = Vec::with_capacity(a.len()); for v in a { out.push(Self::into_untyped(v, s.clone())?); } Val::Arr(out.into()) } - Value::Object(o) => { + Self::Object(o) => { let mut builder = ObjValueBuilder::with_capacity(o.len()); for (k, v) in o { builder diff --git a/crates/jrsonnet-evaluator/src/lib.rs b/crates/jrsonnet-evaluator/src/lib.rs index a0c52ad2..ccb4929c 100644 --- a/crates/jrsonnet-evaluator/src/lib.rs +++ b/crates/jrsonnet-evaluator/src/lib.rs @@ -17,6 +17,11 @@ clippy::cast_possible_wrap, clippy::cast_possible_truncation, clippy::cast_sign_loss, + // False positives + // https://github.com/rust-lang/rust-clippy/issues/6902 + clippy::use_self, + // https://github.com/rust-lang/rust-clippy/issues/8539 + clippy::iter_with_drain, )] // For jrsonnet-macros diff --git a/crates/jrsonnet-evaluator/src/stdlib/format.rs b/crates/jrsonnet-evaluator/src/stdlib/format.rs index 604cb5f8..9b56ab47 100644 --- a/crates/jrsonnet-evaluator/src/stdlib/format.rs +++ b/crates/jrsonnet-evaluator/src/stdlib/format.rs @@ -120,7 +120,7 @@ pub fn try_parse_cflags(str: &str) -> ParseResult { Ok((out, &str[i..])) } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum Width { Star, Fixed(usize), @@ -174,7 +174,7 @@ pub fn try_parse_length_modifier(str: &str) -> ParseResult<()> { Ok(((), &str[idx..])) } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum ConvTypeV { Decimal, Octal, diff --git a/crates/jrsonnet-evaluator/src/stdlib/manifest.rs b/crates/jrsonnet-evaluator/src/stdlib/manifest.rs index d5a2b52f..4e70716f 100644 --- a/crates/jrsonnet-evaluator/src/stdlib/manifest.rs +++ b/crates/jrsonnet-evaluator/src/stdlib/manifest.rs @@ -3,7 +3,7 @@ use crate::{ throw, State, Val, }; -#[derive(PartialEq, Clone, Copy)] +#[derive(PartialEq, Eq, Clone, Copy)] pub enum ManifestType { // Applied in manifestification Manifest, diff --git a/crates/jrsonnet-evaluator/src/trace/location.rs b/crates/jrsonnet-evaluator/src/trace/location.rs index a9a4be06..3cc602d6 100644 --- a/crates/jrsonnet-evaluator/src/trace/location.rs +++ b/crates/jrsonnet-evaluator/src/trace/location.rs @@ -1,5 +1,5 @@ #[allow(clippy::module_name_repetitions)] -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] pub struct CodeLocation { pub offset: usize, diff --git a/crates/jrsonnet-evaluator/src/val.rs b/crates/jrsonnet-evaluator/src/val.rs index a9b1bf45..ccfb910f 100644 --- a/crates/jrsonnet-evaluator/src/val.rs +++ b/crates/jrsonnet-evaluator/src/val.rs @@ -476,43 +476,43 @@ static_assertions::assert_eq_size!(Val, [u8; 32]); impl Val { pub const fn as_bool(&self) -> Option { match self { - Val::Bool(v) => Some(*v), + Self::Bool(v) => Some(*v), _ => None, } } pub const fn as_null(&self) -> Option<()> { match self { - Val::Null => Some(()), + Self::Null => Some(()), _ => None, } } pub fn as_str(&self) -> Option { match self { - Val::Str(s) => Some(s.clone()), + Self::Str(s) => Some(s.clone()), _ => None, } } pub const fn as_num(&self) -> Option { match self { - Val::Num(n) => Some(*n), + Self::Num(n) => Some(*n), _ => None, } } pub fn as_arr(&self) -> Option { match self { - Val::Arr(a) => Some(a.clone()), + Self::Arr(a) => Some(a.clone()), _ => None, } } pub fn as_obj(&self) -> Option { match self { - Val::Obj(o) => Some(o.clone()), + Self::Obj(o) => Some(o.clone()), _ => None, } } pub fn as_func(&self) -> Option { match self { - Val::Func(f) => Some(f.clone()), + Self::Func(f) => Some(f.clone()), _ => None, } } diff --git a/crates/jrsonnet-interner/src/inner.rs b/crates/jrsonnet-interner/src/inner.rs index 1346e0fd..0a555919 100644 --- a/crates/jrsonnet-interner/src/inner.rs +++ b/crates/jrsonnet-interner/src/inner.rs @@ -157,7 +157,7 @@ impl Inner { pub fn ptr_eq(a: &Self, b: &Self) -> bool { a.0 == b.0 } - pub fn as_ptr(this: &Self) -> *const u8 { + pub const fn as_ptr(this: &Self) -> *const u8 { // SAFETY: data is initialized unsafe { this.0.as_ptr().add(mem::size_of::()) } } diff --git a/crates/jrsonnet-parser/src/expr.rs b/crates/jrsonnet-parser/src/expr.rs index 3a499c09..ea594450 100644 --- a/crates/jrsonnet-parser/src/expr.rs +++ b/crates/jrsonnet-parser/src/expr.rs @@ -21,7 +21,7 @@ pub enum FieldName { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, Copy, PartialEq, Trace)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)] pub enum Visibility { /// : Normal, @@ -60,7 +60,7 @@ pub enum Member { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, Copy, PartialEq, Trace)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)] pub enum UnaryOpType { Plus, Minus, @@ -85,7 +85,7 @@ impl Display for UnaryOpType { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, Copy, PartialEq, Trace)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)] pub enum BinaryOpType { Mul, Div, @@ -179,7 +179,7 @@ impl ArgsDesc { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Trace)] +#[derive(Debug, Clone, PartialEq, Eq, Trace)] pub enum DestructRest { /// ...rest Keep(IStr), @@ -188,7 +188,7 @@ pub enum DestructRest { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, Clone, PartialEq, Trace)] +#[derive(Debug, Clone, PartialEq, Eq, Trace)] pub enum Destruct { Full(IStr), #[cfg(feature = "exp-destruct")] @@ -263,7 +263,7 @@ pub enum ObjBody { } #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Debug, PartialEq, Clone, Copy, Trace)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Trace)] pub enum LiteralType { This, Super, @@ -357,7 +357,7 @@ pub enum Expr { /// file, begin offset, end offset #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[derive(Clone, PartialEq, Trace)] +#[derive(Clone, PartialEq, Eq, Trace)] #[skip_trace] #[repr(C)] pub struct ExprLocation(pub Source, pub u32, pub u32);