From 79c6e57d10a05247fccedd9bae1017d0ccb421c4 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Thu, 24 Nov 2022 12:27:59 +0000 Subject: [PATCH 1/3] bump rust --- azure-pipelines.yml | 2 +- serde_closure_derive/src/lib.rs | 47 ++++++++++++++++++++------------- src/lib.rs | 24 ++++++++++------- tests/smoke.rs | 2 +- tests/test.rs | 1 + 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 706b9ba..6b077d4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,7 +14,7 @@ jobs: endpoint: alecmocatta default: rust_toolchain: stable nightly - rust_lint_toolchain: nightly-2020-07-27 + rust_lint_toolchain: nightly-2022-11-23 rust_flags: '' rust_features_clippy: '' rust_features: '' diff --git a/serde_closure_derive/src/lib.rs b/serde_closure_derive/src/lib.rs index cabded0..b571cc0 100644 --- a/serde_closure_derive/src/lib.rs +++ b/serde_closure_derive/src/lib.rs @@ -11,10 +11,17 @@ //! documentation. #![doc(html_root_url = "https://docs.rs/serde_closure_derive/0.3.2")] +#![allow( + unknown_lints, + clippy::default_trait_access, + clippy::unused_self, + clippy::if_not_else, + clippy::manual_let_else +)] use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; -use std::{collections::HashSet, iter, iter::successors, mem::take, str}; +use std::{collections::HashSet, convert::TryInto, iter, iter::successors, mem::take, str}; use syn::{ parse2, parse_macro_input, visit_mut::{self, VisitMut}, Arm, AttributeArgs, Block, Error, Expr, ExprArray, ExprAssign, ExprAssignOp, ExprAsync, ExprAwait, ExprBinary, ExprBlock, ExprBox, ExprBreak, ExprCall, ExprCast, ExprClosure, ExprField, ExprForLoop, ExprGroup, ExprIf, ExprIndex, ExprLet, ExprLoop, ExprMacro, ExprMatch, ExprMethodCall, ExprParen, ExprPath, ExprRange, ExprReference, ExprRepeat, ExprReturn, ExprStruct, ExprTry, ExprTryBlock, ExprTuple, ExprType, ExprUnary, ExprUnsafe, ExprWhile, ExprYield, FieldValue, GenericParam, Ident, ImplItem, Item, ItemImpl, Lifetime, LifetimeDef, Local, Member, Pat, PatBox, PatIdent, PatReference, PatSlice, PatTuple, PatTupleStruct, PatType, Path, PathArguments, PathSegment, ReturnType, Stmt, TraitBound, Type, TypeInfer, TypeReference, TypeTuple, UnOp }; @@ -87,16 +94,16 @@ impl Desugar { inputs.push_punct(Default::default()); } let output = match &args.output { - ReturnType::Type(_, type_) => (&**type_).clone(), + ReturnType::Type(_, type_) => (**type_).clone(), ReturnType::Default => Type::Tuple(TypeTuple { paren_token: Default::default(), elems: Default::default(), }), }; *arg = PathArguments::AngleBracketed(if !return_output { - syn::parse2(quote! { <(#inputs), Output = #output> }).unwrap() + parse2(quote! { <(#inputs), Output = #output> }).unwrap() } else { - syn::parse2(quote! { <(#inputs)> }).unwrap() + parse2(quote! { <(#inputs)> }).unwrap() }); (lifetimes, if return_output { Some(output) } else { None }) } else { @@ -112,7 +119,7 @@ impl VisitMut for Desugar { .0; if lifetimes > 0 { let span = Span::call_site(); - let empty = syn::parse2(quote! {for <>}).unwrap(); + let empty = parse2(quote! {for <>}).unwrap(); i.lifetimes = Some(i.lifetimes.clone().unwrap_or(empty)); i.lifetimes .as_mut() @@ -125,7 +132,7 @@ impl VisitMut for Desugar { )) })); } - visit_mut::visit_trait_bound_mut(self, i) + visit_mut::visit_trait_bound_mut(self, i); } fn visit_item_impl_mut(&mut self, i: &mut ItemImpl) { if let Some((_, path, _)) = &mut i.trait_ { @@ -146,12 +153,12 @@ impl VisitMut for Desugar { if path.segments.last().unwrap().ident == "FnOnce" { if let Some(output) = output { i.items.push(ImplItem::Type( - syn::parse2(quote! { type Output = #output; }).unwrap(), + parse2(quote! { type Output = #output; }).unwrap(), )); } } } - visit_mut::visit_item_impl_mut(self, i) + visit_mut::visit_item_impl_mut(self, i); } } @@ -171,7 +178,11 @@ impl Kind { } } -#[allow(clippy::cognitive_complexity)] +#[allow( + clippy::cognitive_complexity, + clippy::unnecessary_wraps, + clippy::too_many_lines +)] fn impl_closure(mut closure: ExprClosure, kind: Kind) -> Result { let span = Span::call_site(); // TODO: def_site() https://github.com/rust-lang/rust/issues/54724 let name_string = kind.name(); @@ -214,7 +225,7 @@ fn impl_closure(mut closure: ExprClosure, kind: Kind) -> Result>(); let closure = if let Expr::Closure(closure) = closure { closure @@ -261,8 +272,7 @@ fn impl_closure(mut closure: ExprClosure, kind: Kind) -> Result quote! { *#env_name }, - Kind::FnMut => quote! { *#env_name }, + Kind::Fn | Kind::FnMut => quote! { *#env_name }, Kind::FnOnce => quote! { #env_name }, }) .unwrap(); @@ -582,7 +592,7 @@ fn pat_to_type(pat: &Pat) -> Type { match pat { Pat::Type(pat_type) => { if let Type::Infer(_) = *pat_type.ty { - pat_to_type(&*pat_type.pat) + pat_to_type(&pat_type.pat) } else { (*pat_type.ty).clone() } @@ -651,7 +661,7 @@ impl<'a> State<'a> { | Pat::Type(PatType { pat, .. }) => self.pat(&mut *pat), Pat::Or(pat_or) => { for case in &mut pat_or.cases { - self.pat(case) + self.pat(case); } } Pat::Slice(PatSlice { elems, .. }) @@ -661,7 +671,7 @@ impl<'a> State<'a> { .. }) => { for elem in elems { - self.pat(elem) + self.pat(elem); } } Pat::Range(pat_range) => { @@ -670,7 +680,7 @@ impl<'a> State<'a> { } Pat::Struct(pat_struct) => { for field in &mut pat_struct.fields { - self.pat(&mut *field.pat) + self.pat(&mut field.pat); } } _ => (), @@ -707,6 +717,7 @@ impl<'a> State<'a> { .collect(); } + #[allow(clippy::too_many_lines)] fn expr(&mut self, expr: &mut Expr, is_func: bool) { match expr { Expr::Array(ExprArray { elems, .. }) | Expr::Tuple(ExprTuple { elems, .. }) => { @@ -763,7 +774,7 @@ impl<'a> State<'a> { Expr::Path(ExprPath { path, .. }) if path.leading_colon.is_none() && path.segments.len() == 1 => { - self.expr(func, true) + self.expr(func, true); } _ => self.expr(func, false), } @@ -944,7 +955,7 @@ fn bijective_base(n: u64, base: u64, digits: impl Fn(u8) -> u8) -> String { .iter_mut() .rev() .zip(divided) - .map(|(c, n)| *c = digits((n % base) as u8)) + .map(|(c, n)| *c = digits((n % base).try_into().unwrap())) .count(); let index = BUF_SIZE - written; diff --git a/src/lib.rs b/src/lib.rs index ffbc2bb..ccd8a23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -166,7 +166,7 @@ //! [`serde`](https://github.com/serde-rs/serde). #![doc(html_root_url = "https://docs.rs/serde_closure/0.3.2")] -#![cfg_attr(nightly, feature(unboxed_closures, fn_traits))] +#![cfg_attr(nightly, feature(unboxed_closures, fn_traits, tuple_trait))] #![warn( missing_copy_implementations, missing_debug_implementations, @@ -482,6 +482,8 @@ pub mod traits { #![allow(non_snake_case)] + #[cfg(nightly)] + use std::marker::Tuple; use std::ops; /// Supertrait of [`std::ops::FnOnce`] that is usable on stable Rust. It is @@ -567,7 +569,7 @@ pub mod traits { #[cfg(not(nightly))] fn_once!(A B C D E F G H I J K L); #[cfg(nightly)] - impl FnOnce for T + impl FnOnce for T where T: ops::FnOnce, { @@ -601,7 +603,7 @@ pub mod traits { #[cfg(not(nightly))] fn_mut!(A B C D E F G H I J K L); #[cfg(nightly)] - impl FnMut for T + impl FnMut for T where T: ops::FnMut, { @@ -633,7 +635,7 @@ pub mod traits { #[cfg(not(nightly))] fn_ref!(A B C D E F G H I J K L); #[cfg(nightly)] - impl Fn for T + impl Fn for T where T: ops::Fn, { @@ -657,6 +659,8 @@ pub mod structs { use serde::{Deserialize, Serialize}; use std::fmt::{self, Debug}; + #[cfg(nightly)] + use std::marker::Tuple; use super::internal; @@ -697,7 +701,7 @@ pub mod structs { } } #[cfg(nightly)] - impl std::ops::FnOnce for FnOnce + impl std::ops::FnOnce for FnOnce where F: internal::FnOnce, { @@ -755,7 +759,7 @@ pub mod structs { } } #[cfg(nightly)] - impl std::ops::FnOnce for FnMut + impl std::ops::FnOnce for FnMut where F: internal::FnOnce, { @@ -778,7 +782,7 @@ pub mod structs { } } #[cfg(nightly)] - impl std::ops::FnMut for FnMut + impl std::ops::FnMut for FnMut where F: internal::FnMut, { @@ -833,7 +837,7 @@ pub mod structs { } } #[cfg(nightly)] - impl std::ops::FnOnce for Fn + impl std::ops::FnOnce for Fn where F: internal::FnOnce, { @@ -856,7 +860,7 @@ pub mod structs { } } #[cfg(nightly)] - impl std::ops::FnMut for Fn + impl std::ops::FnMut for Fn where F: internal::FnMut, { @@ -877,7 +881,7 @@ pub mod structs { } } #[cfg(nightly)] - impl std::ops::Fn for Fn + impl std::ops::Fn for Fn where F: internal::Fn, { diff --git a/tests/smoke.rs b/tests/smoke.rs index 11dd7f1..687ea68 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -7,7 +7,7 @@ unreachable_pub, clippy::pedantic )] -#![allow(clippy::too_many_lines, clippy::many_single_char_names, unused_imports)] +#![allow(clippy::too_many_lines, clippy::many_single_char_names, clippy::self_assignment, clippy::uninlined_format_args, unused_imports)] use serde::{de::DeserializeOwned, Serialize}; use std::{fmt::Debug, mem::size_of}; diff --git a/tests/test.rs b/tests/test.rs index 8614b6e..153f89c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -7,6 +7,7 @@ unreachable_pub, clippy::pedantic )] +#![allow(clippy::no_effect_underscore_binding, clippy::unnecessary_wraps)] use serde::{de::DeserializeOwned, Serialize}; use std::{fmt::Debug, hash::Hash}; From 17eabe533d406a71e42ff0741d1c2af28f4f8d69 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Thu, 24 Nov 2022 12:43:13 +0000 Subject: [PATCH 2/3] v0.3.3 --- Cargo.toml | 5 +++-- serde_closure_derive/Cargo.toml | 2 +- serde_closure_derive/src/lib.rs | 2 +- src/lib.rs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 11db1a0..6ca1ae3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "serde_closure" -version = "0.3.2" +version = "0.3.3" license = "MIT OR Apache-2.0" authors = ["Alec Mocatta "] categories = ["development-tools","encoding","rust-patterns","network-programming"] @@ -23,7 +23,8 @@ azure-devops = { project = "alecmocatta/serde_closure", pipeline = "tests", buil maintenance = { status = "actively-developed" } [dependencies] -serde_closure_derive = { version = "=0.3.2", path = "serde_closure_derive" } +serde_closure_derive = { version = "=0.3.3", path = "serde_closure_derive" } + serde = { version = "1.0", features = ["derive"] } [build-dependencies] diff --git a/serde_closure_derive/Cargo.toml b/serde_closure_derive/Cargo.toml index aeb19ad..9d9ede2 100644 --- a/serde_closure_derive/Cargo.toml +++ b/serde_closure_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_closure_derive" -version = "0.3.2" +version = "0.3.3" license = "MIT OR Apache-2.0" authors = ["Alec Mocatta "] categories = ["development-tools","encoding","rust-patterns","network-programming"] diff --git a/serde_closure_derive/src/lib.rs b/serde_closure_derive/src/lib.rs index b571cc0..569accf 100644 --- a/serde_closure_derive/src/lib.rs +++ b/serde_closure_derive/src/lib.rs @@ -10,7 +10,7 @@ //! See [`serde_closure`](https://docs.rs/serde_closure) for //! documentation. -#![doc(html_root_url = "https://docs.rs/serde_closure_derive/0.3.2")] +#![doc(html_root_url = "https://docs.rs/serde_closure_derive/0.3.3")] #![allow( unknown_lints, clippy::default_trait_access, diff --git a/src/lib.rs b/src/lib.rs index ccd8a23..1f3ac64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -165,7 +165,7 @@ //! automatically serializable and deserializable with //! [`serde`](https://github.com/serde-rs/serde). -#![doc(html_root_url = "https://docs.rs/serde_closure/0.3.2")] +#![doc(html_root_url = "https://docs.rs/serde_closure/0.3.3")] #![cfg_attr(nightly, feature(unboxed_closures, fn_traits, tuple_trait))] #![warn( missing_copy_implementations, From b72f4accc2465eebcbb84baeb657f8486cec368e Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Thu, 24 Nov 2022 12:45:20 +0000 Subject: [PATCH 3/3] fmt --- tests/smoke.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/smoke.rs b/tests/smoke.rs index 687ea68..cf93410 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -7,7 +7,13 @@ unreachable_pub, clippy::pedantic )] -#![allow(clippy::too_many_lines, clippy::many_single_char_names, clippy::self_assignment, clippy::uninlined_format_args, unused_imports)] +#![allow( + clippy::too_many_lines, + clippy::many_single_char_names, + clippy::self_assignment, + clippy::uninlined_format_args, + unused_imports +)] use serde::{de::DeserializeOwned, Serialize}; use std::{fmt::Debug, mem::size_of};