Skip to content

Commit

Permalink
Merge pull request #36 from alecmocatta/bump
Browse files Browse the repository at this point in the history
Bump rust
  • Loading branch information
alecmocatta authored Nov 24, 2022
2 parents 01a4d44 + b72f4ac commit 11f653f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 35 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
categories = ["development-tools","encoding","rust-patterns","network-programming"]
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
2 changes: 1 addition & 1 deletion serde_closure_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
categories = ["development-tools","encoding","rust-patterns","network-programming"]
Expand Down
49 changes: 30 additions & 19 deletions serde_closure_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
//! 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,
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
};
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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_ {
Expand All @@ -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);
}
}

Expand All @@ -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<TokenStream, Error> {
let span = Span::call_site(); // TODO: def_site() https://github.com/rust-lang/rust/issues/54724
let name_string = kind.name();
Expand Down Expand Up @@ -214,7 +225,7 @@ fn impl_closure(mut closure: ExprClosure, kind: Kind) -> Result<TokenStream, Err
let env_variables = &env_variables;
let env_variable_names = &env_variables
.iter()
.map(|ident| ident.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>();
let closure = if let Expr::Closure(closure) = closure {
closure
Expand Down Expand Up @@ -261,8 +272,7 @@ fn impl_closure(mut closure: ExprClosure, kind: Kind) -> Result<TokenStream, Err
})
.unwrap();
let env_deref: Expr = parse2(match kind {
Kind::Fn => quote! { *#env_name },
Kind::FnMut => quote! { *#env_name },
Kind::Fn | Kind::FnMut => quote! { *#env_name },
Kind::FnOnce => quote! { #env_name },
})
.unwrap();
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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, .. })
Expand All @@ -661,7 +671,7 @@ impl<'a> State<'a> {
..
}) => {
for elem in elems {
self.pat(elem)
self.pat(elem);
}
}
Pat::Range(pat_range) => {
Expand All @@ -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);
}
}
_ => (),
Expand Down Expand Up @@ -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, .. }) => {
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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;

Expand Down
26 changes: 15 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@
//! automatically serializable and deserializable with
//! [`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))]
#![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,
missing_debug_implementations,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<T, Args> FnOnce<Args> for T
impl<T, Args: Tuple> FnOnce<Args> for T
where
T: ops::FnOnce<Args>,
{
Expand Down Expand Up @@ -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<T, Args> FnMut<Args> for T
impl<T, Args: Tuple> FnMut<Args> for T
where
T: ops::FnMut<Args>,
{
Expand Down Expand Up @@ -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<T, Args> Fn<Args> for T
impl<T, Args: Tuple> Fn<Args> for T
where
T: ops::Fn<Args>,
{
Expand All @@ -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;

Expand Down Expand Up @@ -697,7 +701,7 @@ pub mod structs {
}
}
#[cfg(nightly)]
impl<F, I> std::ops::FnOnce<I> for FnOnce<F>
impl<F, I: Tuple> std::ops::FnOnce<I> for FnOnce<F>
where
F: internal::FnOnce<I>,
{
Expand Down Expand Up @@ -755,7 +759,7 @@ pub mod structs {
}
}
#[cfg(nightly)]
impl<F, I> std::ops::FnOnce<I> for FnMut<F>
impl<F, I: Tuple> std::ops::FnOnce<I> for FnMut<F>
where
F: internal::FnOnce<I>,
{
Expand All @@ -778,7 +782,7 @@ pub mod structs {
}
}
#[cfg(nightly)]
impl<F, I> std::ops::FnMut<I> for FnMut<F>
impl<F, I: Tuple> std::ops::FnMut<I> for FnMut<F>
where
F: internal::FnMut<I>,
{
Expand Down Expand Up @@ -833,7 +837,7 @@ pub mod structs {
}
}
#[cfg(nightly)]
impl<F, I> std::ops::FnOnce<I> for Fn<F>
impl<F, I: Tuple> std::ops::FnOnce<I> for Fn<F>
where
F: internal::FnOnce<I>,
{
Expand All @@ -856,7 +860,7 @@ pub mod structs {
}
}
#[cfg(nightly)]
impl<F, I> std::ops::FnMut<I> for Fn<F>
impl<F, I: Tuple> std::ops::FnMut<I> for Fn<F>
where
F: internal::FnMut<I>,
{
Expand All @@ -877,7 +881,7 @@ pub mod structs {
}
}
#[cfg(nightly)]
impl<F, I> std::ops::Fn<I> for Fn<F>
impl<F, I: Tuple> std::ops::Fn<I> for Fn<F>
where
F: internal::Fn<I>,
{
Expand Down
8 changes: 7 additions & 1 deletion tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
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};
Expand Down
1 change: 1 addition & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 11f653f

Please sign in to comment.