Made clippy also check _derive, fixed clippy warnings
This commit is contained in:
parent
cffc9fcffa
commit
6361ad7d69
|
|
@ -1,3 +1,8 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"derive"
|
||||
]
|
||||
|
||||
[package]
|
||||
name = "bincode"
|
||||
version = "2.0.0-dev" # remember to update html_root_url and bincode_derive
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use proc_macro::TokenStream;
|
|||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
use quote::ToTokens;
|
||||
use syn::{spanned::Spanned, Field, Fields, Generics, Ident, Index, Variant};
|
||||
use syn::{spanned::Spanned, Fields, Generics, Ident, Index, Variant};
|
||||
pub struct DeriveEnum {
|
||||
name: Ident,
|
||||
generics: Generics,
|
||||
|
|
@ -21,7 +21,7 @@ impl DeriveEnum {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn to_encodable(self) -> Result<TokenStream> {
|
||||
pub fn generate_encodable(self) -> Result<TokenStream> {
|
||||
let DeriveEnum {
|
||||
name,
|
||||
generics,
|
||||
|
|
@ -56,7 +56,7 @@ impl DeriveEnum {
|
|||
Ok(result.into())
|
||||
}
|
||||
|
||||
pub fn to_decodable(self) -> Result<TokenStream> {
|
||||
pub fn generate_decodable(self) -> Result<TokenStream> {
|
||||
let DeriveEnum {
|
||||
name,
|
||||
generics,
|
||||
|
|
@ -145,7 +145,7 @@ fn fields_to_names(fields: &Fields) -> Vec<TokenStream2> {
|
|||
|
||||
fn field_names_to_encodable(names: &[TokenStream2]) -> Vec<TokenStream2> {
|
||||
names
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|field| {
|
||||
quote! {
|
||||
bincode::enc::Encodeable::encode(#field, &mut encoder)?;
|
||||
|
|
@ -165,7 +165,7 @@ fn fields_to_constructable_names(fields: &Fields) -> Vec<TokenStream2> {
|
|||
.unnamed
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, f)| Index::from(i).to_token_stream())
|
||||
.map(|(i, _)| Index::from(i).to_token_stream())
|
||||
.collect(),
|
||||
syn::Fields::Unit => Vec::new(),
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ fn fields_to_constructable_names(fields: &Fields) -> Vec<TokenStream2> {
|
|||
|
||||
fn field_names_to_decodable(names: &[TokenStream2]) -> Vec<TokenStream2> {
|
||||
names
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|field| {
|
||||
quote! {
|
||||
#field: bincode::de::Decodable::decode(&mut decoder)?,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::Result;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{quote, quote_spanned, ToTokens};
|
||||
use syn::{spanned::Spanned, Generics, Ident, Index};
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{Generics, Ident, Index};
|
||||
|
||||
pub struct DeriveStruct {
|
||||
name: Ident,
|
||||
|
|
@ -33,7 +33,7 @@ impl DeriveStruct {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn to_encodable(self) -> Result<TokenStream> {
|
||||
pub fn generate_encodable(self) -> Result<TokenStream> {
|
||||
let DeriveStruct {
|
||||
name,
|
||||
generics,
|
||||
|
|
@ -63,7 +63,7 @@ impl DeriveStruct {
|
|||
Ok(result.into())
|
||||
}
|
||||
|
||||
pub fn to_decodable(self) -> Result<TokenStream> {
|
||||
pub fn generate_decodable(self) -> Result<TokenStream> {
|
||||
let DeriveStruct {
|
||||
name,
|
||||
generics,
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ fn derive_encodable_inner(input: DeriveInput) -> Result<TokenStream> {
|
|||
match input.data {
|
||||
syn::Data::Struct(struct_definition) => {
|
||||
DeriveStruct::parse(input.ident, input.generics, struct_definition)
|
||||
.and_then(|str| str.to_encodable())
|
||||
.and_then(|str| str.generate_encodable())
|
||||
}
|
||||
syn::Data::Enum(enum_definition) => {
|
||||
DeriveEnum::parse(input.ident, input.generics, enum_definition)
|
||||
.and_then(|str| str.to_encodable())
|
||||
.and_then(|str| str.generate_encodable())
|
||||
}
|
||||
syn::Data::Union(_) => Err(Error::UnionNotSupported),
|
||||
}
|
||||
|
|
@ -42,11 +42,11 @@ fn derive_decodable_inner(input: DeriveInput) -> Result<TokenStream> {
|
|||
match input.data {
|
||||
syn::Data::Struct(struct_definition) => {
|
||||
DeriveStruct::parse(input.ident, input.generics, struct_definition)
|
||||
.and_then(|str| str.to_decodable())
|
||||
.and_then(|str| str.generate_decodable())
|
||||
}
|
||||
syn::Data::Enum(enum_definition) => {
|
||||
DeriveEnum::parse(input.ident, input.generics, enum_definition)
|
||||
.and_then(|str| str.to_decodable())
|
||||
.and_then(|str| str.generate_decodable())
|
||||
}
|
||||
syn::Data::Union(_) => Err(Error::UnionNotSupported),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue