Address clippy lints in serde_derive_internals

This commit is contained in:
David Tolnay 2018-01-09 19:21:01 -08:00
parent 6024e717fb
commit 34eaab00f7
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 35 additions and 34 deletions

View File

@ -221,8 +221,8 @@ fn borrowed_lifetimes(cont: &Container) -> BorrowedLifetimes {
}
fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
if let Some(from_type) = cont.attrs.from_type() {
deserialize_from(from_type)
if let Some(type_from) = cont.attrs.type_from() {
deserialize_from(type_from)
} else if let attr::Identifier::No = cont.attrs.identifier() {
match cont.data {
Data::Enum(ref variants) => deserialize_enum(params, variants, &cont.attrs),
@ -256,7 +256,7 @@ fn deserialize_in_place_body(cont: &Container, params: &Parameters) -> Option<St
// deserialize_in_place for remote derives.
assert!(!params.has_getter);
if cont.attrs.from_type().is_some() || cont.attrs.identifier().is_some()
if cont.attrs.type_from().is_some() || cont.attrs.identifier().is_some()
|| cont.data
.all_fields()
.all(|f| f.attrs.deserialize_with().is_some())
@ -295,10 +295,10 @@ fn deserialize_in_place_body(_cont: &Container, _params: &Parameters) -> Option<
None
}
fn deserialize_from(from_type: &syn::Type) -> Fragment {
fn deserialize_from(type_from: &syn::Type) -> Fragment {
quote_block! {
_serde::export::Result::map(
<#from_type as _serde::Deserialize>::deserialize(__deserializer),
<#type_from as _serde::Deserialize>::deserialize(__deserializer),
_serde::export::From::from)
}
}

View File

@ -153,8 +153,8 @@ fn needs_serialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -
}
fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
if let Some(into_type) = cont.attrs.into_type() {
serialize_into(params, into_type)
if let Some(type_into) = cont.attrs.type_into() {
serialize_into(params, type_into)
} else {
match cont.data {
Data::Enum(ref variants) => serialize_enum(params, variants, &cont.attrs),
@ -178,11 +178,11 @@ fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
}
}
fn serialize_into(params: &Parameters, into_type: &syn::Type) -> Fragment {
fn serialize_into(params: &Parameters, type_into: &syn::Type) -> Fragment {
let self_var = &params.self_var;
quote_block! {
_serde::Serialize::serialize(
&_serde::export::Into::<#into_type>::into(_serde::export::Clone::clone(#self_var)),
&_serde::export::Into::<#type_into>::into(_serde::export::Clone::clone(#self_var)),
__serializer)
}
}

View File

@ -51,10 +51,10 @@ impl<'a> Container<'a> {
let mut data = match item.data {
syn::Data::Enum(ref data) => {
Data::Enum(enum_from_ast(cx, &data.variants, &attrs.default()))
Data::Enum(enum_from_ast(cx, &data.variants, attrs.default()))
}
syn::Data::Struct(ref data) => {
let (style, fields) = struct_from_ast(cx, &data.fields, None, &attrs.default());
let (style, fields) = struct_from_ast(cx, &data.fields, None, attrs.default());
Data::Struct(style, fields)
}
syn::Data::Union(_) => {
@ -63,9 +63,9 @@ impl<'a> Container<'a> {
};
match data {
Data::Enum(ref mut variants) => for ref mut variant in variants {
Data::Enum(ref mut variants) => for variant in variants {
variant.attrs.rename_by_rule(attrs.rename_all());
for ref mut field in &mut variant.fields {
for field in &mut variant.fields {
field.attrs.rename_by_rule(variant.attrs.rename_all());
}
},
@ -75,7 +75,7 @@ impl<'a> Container<'a> {
}
let item = Container {
ident: item.ident.clone(),
ident: item.ident,
attrs: attrs,
data: data,
generics: &item.generics,
@ -112,7 +112,7 @@ fn enum_from_ast<'a>(
let (style, fields) =
struct_from_ast(cx, &variant.fields, Some(&attrs), container_default);
Variant {
ident: variant.ident.clone(),
ident: variant.ident,
attrs: attrs,
style: style,
fields: fields,
@ -154,7 +154,7 @@ fn fields_from_ast<'a>(
.iter()
.enumerate()
.map(|(i, field)| Field {
ident: field.ident.clone(),
ident: field.ident,
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
ty: &field.ty,
})

View File

@ -108,8 +108,8 @@ pub struct Container {
ser_bound: Option<Vec<syn::WherePredicate>>,
de_bound: Option<Vec<syn::WherePredicate>>,
tag: EnumTag,
from_type: Option<syn::Type>,
into_type: Option<syn::Type>,
type_from: Option<syn::Type>,
type_into: Option<syn::Type>,
remote: Option<syn::Path>,
identifier: Identifier,
}
@ -184,8 +184,8 @@ impl Container {
let mut untagged = BoolAttr::none(cx, "untagged");
let mut internal_tag = Attr::none(cx, "tag");
let mut content = Attr::none(cx, "content");
let mut from_type = Attr::none(cx, "from");
let mut into_type = Attr::none(cx, "into");
let mut type_from = Attr::none(cx, "from");
let mut type_into = Attr::none(cx, "into");
let mut remote = Attr::none(cx, "remote");
let mut field_identifier = BoolAttr::none(cx, "field_identifier");
let mut variant_identifier = BoolAttr::none(cx, "variant_identifier");
@ -314,14 +314,14 @@ impl Container {
// Parse `#[serde(from = "Type")]
Meta(NameValue(ref m)) if m.ident == "from" => {
if let Ok(from_ty) = parse_lit_into_ty(cx, m.ident.as_ref(), &m.lit) {
from_type.set_opt(Some(from_ty));
type_from.set_opt(Some(from_ty));
}
}
// Parse `#[serde(into = "Type")]
Meta(NameValue(ref m)) if m.ident == "into" => {
if let Ok(into_ty) = parse_lit_into_ty(cx, m.ident.as_ref(), &m.lit) {
into_type.set_opt(Some(into_ty));
type_into.set_opt(Some(into_ty));
}
}
@ -366,11 +366,11 @@ impl Container {
rename_all: rename_all.get().unwrap_or(RenameRule::None),
ser_bound: ser_bound.get(),
de_bound: de_bound.get(),
tag: decide_tag(cx, item, untagged, internal_tag, content),
from_type: from_type.get(),
into_type: into_type.get(),
tag: decide_tag(cx, item, &untagged, internal_tag, content),
type_from: type_from.get(),
type_into: type_into.get(),
remote: remote.get(),
identifier: decide_identifier(cx, item, field_identifier, variant_identifier),
identifier: decide_identifier(cx, item, &field_identifier, &variant_identifier),
}
}
@ -402,12 +402,12 @@ impl Container {
&self.tag
}
pub fn from_type(&self) -> Option<&syn::Type> {
self.from_type.as_ref()
pub fn type_from(&self) -> Option<&syn::Type> {
self.type_from.as_ref()
}
pub fn into_type(&self) -> Option<&syn::Type> {
self.into_type.as_ref()
pub fn type_into(&self) -> Option<&syn::Type> {
self.type_into.as_ref()
}
pub fn remote(&self) -> Option<&syn::Path> {
@ -422,7 +422,7 @@ impl Container {
fn decide_tag(
cx: &Ctxt,
item: &syn::DeriveInput,
untagged: BoolAttr,
untagged: &BoolAttr,
internal_tag: Attr<String>,
content: Attr<String>,
) -> EnumTag {
@ -475,8 +475,8 @@ fn decide_tag(
fn decide_identifier(
cx: &Ctxt,
item: &syn::DeriveInput,
field_identifier: BoolAttr,
variant_identifier: BoolAttr,
field_identifier: &BoolAttr,
variant_identifier: &BoolAttr,
) -> Identifier {
match (&item.data, field_identifier.get(), variant_identifier.get()) {
(_, false, false) => Identifier::No,
@ -1144,7 +1144,7 @@ fn parse_lit_into_lifetimes(
if let Ok(BorrowedLifetimes(lifetimes)) = syn::parse_str(&string) {
let mut set = BTreeSet::new();
for lifetime in lifetimes {
if !set.insert(lifetime.clone()) {
if !set.insert(lifetime) {
cx.error(format!("duplicate borrowed lifetime `{}`", lifetime));
}
}

View File

@ -7,6 +7,7 @@
// except according to those terms.
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.19.0")]
#![cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity, doc_markdown, match_same_arms, unit_expr))]
#[macro_use]
extern crate syn;