mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 11:21:01 +00:00
Address clippy lints in serde_derive_internals
This commit is contained in:
@@ -221,8 +221,8 @@ fn borrowed_lifetimes(cont: &Container) -> BorrowedLifetimes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
fn deserialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
||||||
if let Some(from_type) = cont.attrs.from_type() {
|
if let Some(type_from) = cont.attrs.type_from() {
|
||||||
deserialize_from(from_type)
|
deserialize_from(type_from)
|
||||||
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
} else if let attr::Identifier::No = cont.attrs.identifier() {
|
||||||
match cont.data {
|
match cont.data {
|
||||||
Data::Enum(ref variants) => deserialize_enum(params, variants, &cont.attrs),
|
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.
|
// deserialize_in_place for remote derives.
|
||||||
assert!(!params.has_getter);
|
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
|
|| cont.data
|
||||||
.all_fields()
|
.all_fields()
|
||||||
.all(|f| f.attrs.deserialize_with().is_some())
|
.all(|f| f.attrs.deserialize_with().is_some())
|
||||||
@@ -295,10 +295,10 @@ fn deserialize_in_place_body(_cont: &Container, _params: &Parameters) -> Option<
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_from(from_type: &syn::Type) -> Fragment {
|
fn deserialize_from(type_from: &syn::Type) -> Fragment {
|
||||||
quote_block! {
|
quote_block! {
|
||||||
_serde::export::Result::map(
|
_serde::export::Result::map(
|
||||||
<#from_type as _serde::Deserialize>::deserialize(__deserializer),
|
<#type_from as _serde::Deserialize>::deserialize(__deserializer),
|
||||||
_serde::export::From::from)
|
_serde::export::From::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ fn needs_serialize_bound(field: &attr::Field, variant: Option<&attr::Variant>) -
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
fn serialize_body(cont: &Container, params: &Parameters) -> Fragment {
|
||||||
if let Some(into_type) = cont.attrs.into_type() {
|
if let Some(type_into) = cont.attrs.type_into() {
|
||||||
serialize_into(params, into_type)
|
serialize_into(params, type_into)
|
||||||
} else {
|
} else {
|
||||||
match cont.data {
|
match cont.data {
|
||||||
Data::Enum(ref variants) => serialize_enum(params, variants, &cont.attrs),
|
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 = ¶ms.self_var;
|
let self_var = ¶ms.self_var;
|
||||||
quote_block! {
|
quote_block! {
|
||||||
_serde::Serialize::serialize(
|
_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)
|
__serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,10 +51,10 @@ impl<'a> Container<'a> {
|
|||||||
|
|
||||||
let mut data = match item.data {
|
let mut data = match item.data {
|
||||||
syn::Data::Enum(ref 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) => {
|
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)
|
Data::Struct(style, fields)
|
||||||
}
|
}
|
||||||
syn::Data::Union(_) => {
|
syn::Data::Union(_) => {
|
||||||
@@ -63,9 +63,9 @@ impl<'a> Container<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
match data {
|
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());
|
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());
|
field.attrs.rename_by_rule(variant.attrs.rename_all());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -75,7 +75,7 @@ impl<'a> Container<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let item = Container {
|
let item = Container {
|
||||||
ident: item.ident.clone(),
|
ident: item.ident,
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
data: data,
|
data: data,
|
||||||
generics: &item.generics,
|
generics: &item.generics,
|
||||||
@@ -112,7 +112,7 @@ fn enum_from_ast<'a>(
|
|||||||
let (style, fields) =
|
let (style, fields) =
|
||||||
struct_from_ast(cx, &variant.fields, Some(&attrs), container_default);
|
struct_from_ast(cx, &variant.fields, Some(&attrs), container_default);
|
||||||
Variant {
|
Variant {
|
||||||
ident: variant.ident.clone(),
|
ident: variant.ident,
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
style: style,
|
style: style,
|
||||||
fields: fields,
|
fields: fields,
|
||||||
@@ -154,7 +154,7 @@ fn fields_from_ast<'a>(
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, field)| Field {
|
.map(|(i, field)| Field {
|
||||||
ident: field.ident.clone(),
|
ident: field.ident,
|
||||||
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
attrs: attr::Field::from_ast(cx, i, field, attrs, container_default),
|
||||||
ty: &field.ty,
|
ty: &field.ty,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ pub struct Container {
|
|||||||
ser_bound: Option<Vec<syn::WherePredicate>>,
|
ser_bound: Option<Vec<syn::WherePredicate>>,
|
||||||
de_bound: Option<Vec<syn::WherePredicate>>,
|
de_bound: Option<Vec<syn::WherePredicate>>,
|
||||||
tag: EnumTag,
|
tag: EnumTag,
|
||||||
from_type: Option<syn::Type>,
|
type_from: Option<syn::Type>,
|
||||||
into_type: Option<syn::Type>,
|
type_into: Option<syn::Type>,
|
||||||
remote: Option<syn::Path>,
|
remote: Option<syn::Path>,
|
||||||
identifier: Identifier,
|
identifier: Identifier,
|
||||||
}
|
}
|
||||||
@@ -184,8 +184,8 @@ impl Container {
|
|||||||
let mut untagged = BoolAttr::none(cx, "untagged");
|
let mut untagged = BoolAttr::none(cx, "untagged");
|
||||||
let mut internal_tag = Attr::none(cx, "tag");
|
let mut internal_tag = Attr::none(cx, "tag");
|
||||||
let mut content = Attr::none(cx, "content");
|
let mut content = Attr::none(cx, "content");
|
||||||
let mut from_type = Attr::none(cx, "from");
|
let mut type_from = Attr::none(cx, "from");
|
||||||
let mut into_type = Attr::none(cx, "into");
|
let mut type_into = Attr::none(cx, "into");
|
||||||
let mut remote = Attr::none(cx, "remote");
|
let mut remote = Attr::none(cx, "remote");
|
||||||
let mut field_identifier = BoolAttr::none(cx, "field_identifier");
|
let mut field_identifier = BoolAttr::none(cx, "field_identifier");
|
||||||
let mut variant_identifier = BoolAttr::none(cx, "variant_identifier");
|
let mut variant_identifier = BoolAttr::none(cx, "variant_identifier");
|
||||||
@@ -314,14 +314,14 @@ impl Container {
|
|||||||
// Parse `#[serde(from = "Type")]
|
// Parse `#[serde(from = "Type")]
|
||||||
Meta(NameValue(ref m)) if m.ident == "from" => {
|
Meta(NameValue(ref m)) if m.ident == "from" => {
|
||||||
if let Ok(from_ty) = parse_lit_into_ty(cx, m.ident.as_ref(), &m.lit) {
|
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")]
|
// Parse `#[serde(into = "Type")]
|
||||||
Meta(NameValue(ref m)) if m.ident == "into" => {
|
Meta(NameValue(ref m)) if m.ident == "into" => {
|
||||||
if let Ok(into_ty) = parse_lit_into_ty(cx, m.ident.as_ref(), &m.lit) {
|
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),
|
rename_all: rename_all.get().unwrap_or(RenameRule::None),
|
||||||
ser_bound: ser_bound.get(),
|
ser_bound: ser_bound.get(),
|
||||||
de_bound: de_bound.get(),
|
de_bound: de_bound.get(),
|
||||||
tag: decide_tag(cx, item, untagged, internal_tag, content),
|
tag: decide_tag(cx, item, &untagged, internal_tag, content),
|
||||||
from_type: from_type.get(),
|
type_from: type_from.get(),
|
||||||
into_type: into_type.get(),
|
type_into: type_into.get(),
|
||||||
remote: remote.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
|
&self.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_type(&self) -> Option<&syn::Type> {
|
pub fn type_from(&self) -> Option<&syn::Type> {
|
||||||
self.from_type.as_ref()
|
self.type_from.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn into_type(&self) -> Option<&syn::Type> {
|
pub fn type_into(&self) -> Option<&syn::Type> {
|
||||||
self.into_type.as_ref()
|
self.type_into.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remote(&self) -> Option<&syn::Path> {
|
pub fn remote(&self) -> Option<&syn::Path> {
|
||||||
@@ -422,7 +422,7 @@ impl Container {
|
|||||||
fn decide_tag(
|
fn decide_tag(
|
||||||
cx: &Ctxt,
|
cx: &Ctxt,
|
||||||
item: &syn::DeriveInput,
|
item: &syn::DeriveInput,
|
||||||
untagged: BoolAttr,
|
untagged: &BoolAttr,
|
||||||
internal_tag: Attr<String>,
|
internal_tag: Attr<String>,
|
||||||
content: Attr<String>,
|
content: Attr<String>,
|
||||||
) -> EnumTag {
|
) -> EnumTag {
|
||||||
@@ -475,8 +475,8 @@ fn decide_tag(
|
|||||||
fn decide_identifier(
|
fn decide_identifier(
|
||||||
cx: &Ctxt,
|
cx: &Ctxt,
|
||||||
item: &syn::DeriveInput,
|
item: &syn::DeriveInput,
|
||||||
field_identifier: BoolAttr,
|
field_identifier: &BoolAttr,
|
||||||
variant_identifier: BoolAttr,
|
variant_identifier: &BoolAttr,
|
||||||
) -> Identifier {
|
) -> Identifier {
|
||||||
match (&item.data, field_identifier.get(), variant_identifier.get()) {
|
match (&item.data, field_identifier.get(), variant_identifier.get()) {
|
||||||
(_, false, false) => Identifier::No,
|
(_, false, false) => Identifier::No,
|
||||||
@@ -1144,7 +1144,7 @@ fn parse_lit_into_lifetimes(
|
|||||||
if let Ok(BorrowedLifetimes(lifetimes)) = syn::parse_str(&string) {
|
if let Ok(BorrowedLifetimes(lifetimes)) = syn::parse_str(&string) {
|
||||||
let mut set = BTreeSet::new();
|
let mut set = BTreeSet::new();
|
||||||
for lifetime in lifetimes {
|
for lifetime in lifetimes {
|
||||||
if !set.insert(lifetime.clone()) {
|
if !set.insert(lifetime) {
|
||||||
cx.error(format!("duplicate borrowed lifetime `{}`", lifetime));
|
cx.error(format!("duplicate borrowed lifetime `{}`", lifetime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.19.0")]
|
#![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]
|
#[macro_use]
|
||||||
extern crate syn;
|
extern crate syn;
|
||||||
|
|||||||
Reference in New Issue
Block a user