Skip to content

Commit

Permalink
Merge pull request #22 from alecmocatta/borrowck-fix
Browse files Browse the repository at this point in the history
Borrowck fix
  • Loading branch information
mergify[bot] authored Nov 15, 2019
2 parents 3b27a9e + 18d049b commit fdd6057
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 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.7"
version = "0.2.8"
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.7"
documentation = "https://docs.rs/serde_closure/0.2.8"
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.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"

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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.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`,
Expand Down
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.7"
version = "0.2.8"
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.7"
documentation = "https://docs.rs/serde_closure/0.2.8"
edition = "2018"

[badges]
Expand Down
22 changes: 15 additions & 7 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.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

Expand Down Expand Up @@ -404,15 +404,23 @@ fn impl_fn_once(closure: Closure, kind: Kind) -> Result<TokenStream, Error> {
#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);
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.7")]
#![doc(html_root_url = "https://docs.rs/serde_closure/0.2.8")]
#![feature(unboxed_closures, fn_traits)]
#![warn(
missing_copy_implementations,
Expand Down
17 changes: 17 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,23 @@ fn capturing() {
fn serialize<T: 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]

Expand Down

0 comments on commit fdd6057

Please sign in to comment.