From dd3def2506dafa526fe1e1103edf387a0f6d70a0 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Thu, 14 Nov 2019 14:46:13 +0000 Subject: [PATCH 1/3] fix an issue whereby multiple closures/async blocks/generators couldn't reference the same variable --- serde_closure_derive/src/lib.rs | 2 +- tests/test.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/serde_closure_derive/src/lib.rs b/serde_closure_derive/src/lib.rs index 3ec2a50..eb36bc3 100644 --- a/serde_closure_derive/src/lib.rs +++ b/serde_closure_derive/src/lib.rs @@ -410,7 +410,7 @@ fn impl_fn_once(closure: Closure, kind: Kind) -> Result { #[allow(unreachable_code)] { if false { - #(#env_variables = loop {};)* + #(*&#env_variables = loop {};)* } } diff --git a/tests/test.rs b/tests/test.rs index 0016eed..b25f34a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -442,6 +442,23 @@ fn capturing() { fn serialize(_t: &T) {} } +#[test] +fn multiple_async() { + let x = 10usize; + + let _left = async { + FnOnce!(move || { + let _ = x; + }) + }; + + let _right = async { + FnOnce!(move || { + let _ = x; + }) + }; +} + mod no_prelude { #![no_implicit_prelude] From 08cd8c70bfd5a23aab11945ffb23133e6550fb92 Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Thu, 14 Nov 2019 14:46:54 +0000 Subject: [PATCH 2/3] v0.2.8 --- Cargo.toml | 6 +++--- README.md | 8 ++++---- serde_closure_derive/Cargo.toml | 4 ++-- serde_closure_derive/src/lib.rs | 2 +- src/lib.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b371411..c09f099 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "serde_closure" -version = "0.2.7" +version = "0.2.8" license = "MIT OR Apache-2.0" authors = ["Alec Mocatta "] categories = ["development-tools","encoding","rust-patterns","network-programming"] @@ -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.7" +documentation = "https://docs.rs/serde_closure/0.2.8" readme = "README.md" edition = "2018" @@ -23,7 +23,7 @@ azure-devops = { project = "alecmocatta/serde_closure", pipeline = "tests" } maintenance = { status = "actively-developed" } [dependencies] -serde_closure_derive = { version = "=0.2.7", path = "serde_closure_derive" } +serde_closure_derive = { version = "=0.2.8", path = "serde_closure_derive" } serde = { version = "1.0", features = ["derive"] } proc-macro-hack = "0.5" diff --git a/README.md b/README.md index 2d87a7c..25f2c4d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![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) -[Docs](https://docs.rs/serde_closure/0.2.7) +[Docs](https://docs.rs/serde_closure/0.2.8) Serializable and debuggable closures. @@ -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.7/serde_closure/macro.FnOnce.html), - [`FnMut`](https://docs.rs/serde_closure/0.2.7/serde_closure/macro.FnMut.html) - and [`Fn`](https://docs.rs/serde_closure/0.2.7/serde_closure/macro.Fn.html), + [`FnOnce`](https://docs.rs/serde_closure/0.2.8/serde_closure/macro.FnOnce.html), + [`FnMut`](https://docs.rs/serde_closure/0.2.8/serde_closure/macro.FnMut.html) + and [`Fn`](https://docs.rs/serde_closure/0.2.8/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`, diff --git a/serde_closure_derive/Cargo.toml b/serde_closure_derive/Cargo.toml index d7ed7a5..ace7675 100644 --- a/serde_closure_derive/Cargo.toml +++ b/serde_closure_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_closure_derive" -version = "0.2.7" +version = "0.2.8" license = "MIT OR Apache-2.0" authors = ["Alec Mocatta "] categories = ["development-tools","encoding","rust-patterns","network-programming"] @@ -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.7" +documentation = "https://docs.rs/serde_closure/0.2.8" edition = "2018" [badges] diff --git a/serde_closure_derive/src/lib.rs b/serde_closure_derive/src/lib.rs index eb36bc3..6861020 100644 --- a/serde_closure_derive/src/lib.rs +++ b/serde_closure_derive/src/lib.rs @@ -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.7")] +#![doc(html_root_url = "https://docs.rs/serde_closure_derive/0.2.8")] #![feature(proc_macro_diagnostic)] #![allow(non_snake_case)] // due to proc-macro-hack can't apply this directly diff --git a/src/lib.rs b/src/lib.rs index 0a6f16c..1ea4775 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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.7")] +#![doc(html_root_url = "https://docs.rs/serde_closure/0.2.8")] #![feature(unboxed_closures, fn_traits)] #![warn( missing_copy_implementations, From 18d049b17062d5a6be147ec6024f7dbadf9f8acd Mon Sep 17 00:00:00 2001 From: alecmocatta Date: Fri, 15 Nov 2019 13:55:23 +0000 Subject: [PATCH 3/3] add another assertion, document assertions --- serde_closure_derive/src/lib.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/serde_closure_derive/src/lib.rs b/serde_closure_derive/src/lib.rs index 6861020..c071d30 100644 --- a/serde_closure_derive/src/lib.rs +++ b/serde_closure_derive/src/lib.rs @@ -404,15 +404,23 @@ fn impl_fn_once(closure: Closure, kind: Kind) -> Result { #fn_impl } + // This asserts that inferred env variables aren't nameable types. { #(let #env_variables = ::serde_closure::internal::a_variable;)* } - #[allow(unreachable_code)] - { - if false { - #(*&#env_variables = loop {};)* - } - } + // This asserts that inferred env variables aren't types with >=1 type parameters. + 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: + // https://users.rust-lang.org/t/statically-asserting-an-ident-is-a-variable-not-a-type/34619 + // #[allow(unreachable_code)] + // { + // if false { + // #(#env_variables = loop {};)* + // } + // } let mut #ret_name = #impls_name::#name::new(#env_capture); let #env_types_name = ::serde_closure::internal::to_phantom(&#ret_name);