Skip to content

Commit

Permalink
Merge pull request #26 from alecmocatta/fix-warnings
Browse files Browse the repository at this point in the history
Fix warnings on latest rust
  • Loading branch information
mergify[bot] authored Apr 29, 2020
2 parents a0682a0 + 93f4c6a commit d9934dd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 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.2.10"
version = "0.2.11"
license = "MIT OR Apache-2.0"
authors = ["Alec Mocatta <[email protected]>"]
categories = ["development-tools","encoding","rust-patterns","network-programming"]
Expand All @@ -14,7 +14,7 @@ This library provides macros that wrap closures to make them serializable and de
"""
repository = "https://github.com/alecmocatta/serde_closure"
homepage = "https://github.com/alecmocatta/serde_closure"
documentation = "https://docs.rs/serde_closure/0.2.10"
documentation = "https://docs.rs/serde_closure/0.2.11"
readme = "README.md"
edition = "2018"

Expand All @@ -23,7 +23,7 @@ azure-devops = { project = "alecmocatta/serde_closure", pipeline = "tests" }
maintenance = { status = "actively-developed" }

[dependencies]
serde_closure_derive = { version = "=0.2.10", path = "serde_closure_derive" }
serde_closure_derive = { version = "=0.2.11", path = "serde_closure_derive" }
serde = { version = "1.0", features = ["derive"] }
proc-macro-hack = "0.5"

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[![Crates.io](https://img.shields.io/crates/v/serde_closure.svg?maxAge=86400)](https://crates.io/crates/serde_closure)
[![MIT / Apache 2.0 licensed](https://img.shields.io/crates/l/serde_closure.svg?maxAge=2592000)](#License)
[![Build Status](https://dev.azure.com/alecmocatta/serde_closure/_apis/build/status/tests?branchName=master)](https://dev.azure.com/alecmocatta/serde_closure/_build/latest?branchName=master)
[![Build Status](https://dev.azure.com/alecmocatta/serde_closure/_apis/build/status/tests?branchName=master)](https://dev.azure.com/alecmocatta/serde_closure/_build/latest?definitionId=10&branchName=master)

[Docs](https://docs.rs/serde_closure/0.2.10)
[Docs](https://docs.rs/serde_closure/0.2.11)

Serializable and debuggable closures.

Expand All @@ -30,9 +30,9 @@ requires nightly Rust for the `unboxed_closures` and `fn_traits` features (rust
issue [#29625](https://github.com/rust-lang/rust/issues/29625)).

* There are three macros,
[`FnOnce`](https://docs.rs/serde_closure/0.2.10/serde_closure/macro.FnOnce.html),
[`FnMut`](https://docs.rs/serde_closure/0.2.10/serde_closure/macro.FnMut.html)
and [`Fn`](https://docs.rs/serde_closure/0.2.10/serde_closure/macro.Fn.html),
[`FnOnce`](https://docs.rs/serde_closure/0.2.11/serde_closure/macro.FnOnce.html),
[`FnMut`](https://docs.rs/serde_closure/0.2.11/serde_closure/macro.FnMut.html)
and [`Fn`](https://docs.rs/serde_closure/0.2.11/serde_closure/macro.Fn.html),
corresponding to the three types of Rust closure.
* Wrap your closure with one of the macros and it will now implement `Copy`,
`Clone`, `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`, `Serialize`,
Expand Down
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
endpoint: alecmocatta
default:
rust_toolchain: nightly
rust_lint_toolchain: nightly-2019-10-14
rust_lint_toolchain: nightly-2020-04-23
rust_flags: ''
rust_features: ''
rust_target_check: ''
rust_target_build: ''
rust_target_run: ''
matrix:
windows:
imageName: 'vs2017-win2016'
imageName: 'windows-latest'
rust_target_run: 'x86_64-pc-windows-msvc i686-pc-windows-msvc' # currently broken building crate-type=lib: x86_64-pc-windows-gnu i686-pc-windows-gnu
mac:
imageName: 'macos-10.13'
imageName: 'macos-latest'
rust_target_run: 'x86_64-apple-darwin'
linux:
imageName: 'ubuntu-16.04'
imageName: 'ubuntu-latest'
rust_target_run: 'x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl'
4 changes: 2 additions & 2 deletions 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.2.10"
version = "0.2.11"
license = "MIT OR Apache-2.0"
authors = ["Alec Mocatta <[email protected]>"]
categories = ["development-tools","encoding","rust-patterns","network-programming"]
Expand All @@ -14,7 +14,7 @@ See https://crates.io/crates/serde_closure for documentation.
"""
repository = "https://github.com/alecmocatta/serde_closure"
homepage = "https://github.com/alecmocatta/serde_closure"
documentation = "https://docs.rs/serde_closure/0.2.10"
documentation = "https://docs.rs/serde_closure/0.2.11"
edition = "2018"

[badges]
Expand Down
23 changes: 10 additions & 13 deletions serde_closure_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! See [`serde_closure`](https://docs.rs/serde_closure/) for
//! documentation.
#![doc(html_root_url = "https://docs.rs/serde_closure_derive/0.2.10")]
#![doc(html_root_url = "https://docs.rs/serde_closure_derive/0.2.11")]
#![feature(proc_macro_diagnostic)]
#![allow(non_snake_case)] // due to proc-macro-hack can't apply this directly

Expand Down Expand Up @@ -181,7 +181,7 @@ fn impl_fn_once(closure: Closure, kind: Kind) -> Result<TokenStream, Error> {
let env_deconstruct = if kind == Kind::FnOnce {
Some(
parse2::<Stmt>(
quote! { let #impls_name::#name{#(mut #env_variables ,)*..} = #env_name; },
quote! { #[allow(unused_mut)] let #impls_name::#name{#(mut #env_variables ,)*..} = #env_name; },
)
.unwrap(),
)
Expand Down Expand Up @@ -261,7 +261,7 @@ fn impl_fn_once(closure: Closure, kind: Kind) -> Result<TokenStream, Error> {
Ok(quote! {
{
mod #impls_name {
#![allow(warnings)]
#![allow(warnings, unsafe_code)]
use ::serde_closure::{
internal::{self, is_phantom, to_phantom},
structs,
Expand Down Expand Up @@ -427,10 +427,8 @@ fn impl_fn_once(closure: Closure, kind: Kind) -> Result<TokenStream, Error> {
}
// This asserts that inferred env variables aren't types with >=1 type parameters.
#[allow(warnings)]
{
if false {
#(&#env_variables::<>;)*
}
if false {
#(&#env_variables::<>;)*
}
// TODO: Work out how to assert env variables aren't unnameable types with 0 type parameters.
// This might work in the future, but today it causes borrowck issues:
Expand All @@ -442,22 +440,21 @@ fn impl_fn_once(closure: Closure, kind: Kind) -> Result<TokenStream, Error> {
// }
// }

#[allow(unused_mut)]
let mut #ret_name = #impls_name::#name::new(#env_capture);
let #env_types_name = ::serde_closure::internal::to_phantom(&#ret_name);

let closure =
#(#attrs)* #asyncness move |mut #env_name: #env_type, (#(#input_pats,)*): (#(#input_types,)*)| #output {
#(#attrs)* #asyncness move |#env_name: #env_type, (#(#input_pats,)*): (#(#input_types,)*)| #output {
#[allow(warnings)]
{
if false {
::serde_closure::internal::is_phantom(& #env_deref, #env_types_name);
}
if false {
::serde_closure::internal::is_phantom(& #env_deref, #env_types_name);
}
#env_deconstruct
#body
};

#[allow(warnings)]
#[allow(warnings, unsafe_code)]
{
if false {
let _ = closure(#ret_ref, loop {});
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
//! automatically serializable and deserializable with
//! [`serde`](https://github.com/serde-rs/serde).
#![doc(html_root_url = "https://docs.rs/serde_closure/0.2.10")]
#![doc(html_root_url = "https://docs.rs/serde_closure/0.2.11")]
#![feature(unboxed_closures, fn_traits)]
#![warn(
missing_copy_implementations,
Expand Down
9 changes: 7 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(unsafe_code)] // TODO: make this forbid when unsafe in a macro doesn't trigger it (def_site?)

use serde::{de::DeserializeOwned, Serialize};
use std::{fmt::Debug, mem::size_of};

Expand Down Expand Up @@ -99,6 +101,7 @@ fn fnonce() {
let tasks2 = tasks.clone();
let c = FnOnce!(move || -> String {
for task in tasks {
#[allow(clippy::redundant_closure_call)]
(|| reduce.push(task))();
}
reduce
Expand Down Expand Up @@ -373,7 +376,7 @@ fn source() {

#[test]
fn upcast() {
let closure = FnOnce!(|x: &str| "test");
let closure = FnOnce!(|_x: &str| "test");
let closure: Box<dyn FnOnce(&str) -> &'static str + Send + Sync> = Box::new(closure);
closure("test");
}
Expand All @@ -385,6 +388,7 @@ fn capturing() {
let c = 0u8;
#[rustfmt::skip]
let closure = FnOnce!(move || {
#![allow(path_statements)]
(b)();
// b();
// (b::<>)();
Expand Down Expand Up @@ -415,6 +419,7 @@ fn capturing() {
// let FooVar = Foo;
#[rustfmt::skip]
let closure = FnOnce!(move || {
#![allow(path_statements)]
// (b)();
// b();
// (b::<>)();
Expand Down Expand Up @@ -464,7 +469,7 @@ fn static_var() {
static STATIC: String = String::new();

FnMut!(move || {
let a = &STATIC;
let _a = &STATIC;
});
}

Expand Down

0 comments on commit d9934dd

Please sign in to comment.