From 62557731c37b8ac4625dc1a2c76f7412110152b2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 7 May 2018 11:02:12 -0700 Subject: [PATCH] Enable pedantic clippy lints in serde_derive --- serde_derive/src/de.rs | 10 +++++----- serde_derive/src/internals/attr.rs | 4 +--- serde_derive/src/lib.rs | 15 ++++++++++++++- serde_derive/src/ser.rs | 6 ++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 4cb89502..42dbe386 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -553,7 +553,7 @@ fn deserialize_seq( .count(); let expecting = format!("tuple of {} elements", deserialized_count); - let mut index_in_seq = 0usize; + let mut index_in_seq = 0_usize; let let_values = vars.clone().zip(fields).map(|(var, field)| { if field.attrs.skip_deserializing() { let default = Expr(expr_is_missing(field, cattrs)); @@ -1946,9 +1946,7 @@ fn deserialize_identifier( value_as_borrowed_str_content, value_as_bytes_content, value_as_borrowed_bytes_content, - ) = if !collect_other_fields { - (None, None, None, None) - } else { + ) = if collect_other_fields { ( Some(quote! { let __value = _serde::private::de::Content::String(__value.to_string()); @@ -1963,6 +1961,8 @@ fn deserialize_identifier( let __value = _serde::private::de::Content::Bytes(__value); }), ) + } else { + (None, None, None, None) }; let fallthrough_arm = if let Some(fallthrough) = fallthrough { @@ -1977,7 +1977,7 @@ fn deserialize_identifier( } }; - let variant_indices = 0u64..; + let variant_indices = 0_u64..; let fallthrough_msg = format!("{} index 0 <= i < {}", index_expecting, fields.len()); let visit_other = if collect_other_fields { quote! { diff --git a/serde_derive/src/internals/attr.rs b/serde_derive/src/internals/attr.rs index 29476f17..3d73359f 100644 --- a/serde_derive/src/internals/attr.rs +++ b/serde_derive/src/internals/attr.rs @@ -777,9 +777,7 @@ impl Field { }; let variant_borrow = attrs - .map(|variant| &variant.borrow) - .unwrap_or(&None) - .as_ref() + .map_or(None, |variant| variant.borrow.as_ref()) .map(|borrow| vec![Meta(borrow.clone())]); for meta_items in field diff --git a/serde_derive/src/lib.rs b/serde_derive/src/lib.rs index d651f58e..9c15f37c 100644 --- a/serde_derive/src/lib.rs +++ b/serde_derive/src/lib.rs @@ -23,9 +23,22 @@ //! [https://serde.rs/derive.html]: https://serde.rs/derive.html #![doc(html_root_url = "https://docs.rs/serde_derive/1.0.48")] +#![cfg_attr(feature = "cargo-clippy", deny(clippy, clippy_pedantic))] +// Whitelisted clippy lints #![cfg_attr( feature = "cargo-clippy", - allow(enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding) + allow( + enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding, + cyclomatic_complexity + ) +)] +// Whitelisted clippy_pedantic lints +#![cfg_attr( + feature = "cargo-clippy", + allow( + items_after_statements, doc_markdown, stutter, similar_names, use_self, single_match_else, + enum_glob_use, match_same_arms, filter_map, cast_possible_truncation + ) )] // The `quote!` macro requires deep recursion. #![recursion_limit = "512"] diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index 38b03eec..c7c9a6f5 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -18,8 +18,6 @@ use internals::{attr, Ctxt}; use pretend; use try; -use std::u32; - pub fn expand_derive_serialize(input: &syn::DeriveInput) -> Result { let ctxt = Ctxt::new(); let cont = Container::from_ast(&ctxt, input); @@ -250,7 +248,7 @@ fn serialize_tuple_struct( } fn serialize_struct(params: &Parameters, fields: &[Field], cattrs: &attr::Container) -> Fragment { - assert!(fields.len() as u64 <= u64::from(u32::MAX)); + assert!(fields.len() as u64 <= u64::from(u32::max_value())); if cattrs.has_flatten() { serialize_struct_as_map(params, fields, cattrs) @@ -333,7 +331,7 @@ fn serialize_struct_as_map( } fn serialize_enum(params: &Parameters, variants: &[Variant], cattrs: &attr::Container) -> Fragment { - assert!(variants.len() as u64 <= u64::from(u32::MAX)); + assert!(variants.len() as u64 <= u64::from(u32::max_value())); let self_var = params.self_var;