From 69abfbb18e3a9db49ad0b1702a3ee4b83c84ba87 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Tue, 15 Jan 2019 16:00:56 +0000 Subject: [PATCH] Fix custom derive when using a where clause (#853) When injecting the users where clause we need to ensure a comma is inserted between the users where clause and ours. --- misc/core-derive/src/lib.rs | 2 +- misc/core-derive/tests/test.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/misc/core-derive/src/lib.rs b/misc/core-derive/src/lib.rs index ad696f7b..0a423b18 100644 --- a/misc/core-derive/src/lib.rs +++ b/misc/core-derive/src/lib.rs @@ -112,7 +112,7 @@ fn build_struct(ast: &DeriveInput, data_struct: &DataStruct) -> TokenStream { additional.push(quote!{#substream_generic: ::libp2p::tokio_io::AsyncWrite}); if let Some(where_clause) = where_clause { - Some(quote!{#where_clause #(#additional),*}) + Some(quote!{#where_clause, #(#additional),*}) } else { Some(quote!{where #(#additional),*}) } diff --git a/misc/core-derive/tests/test.rs b/misc/core-derive/tests/test.rs index a041147d..0f90baf6 100644 --- a/misc/core-derive/tests/test.rs +++ b/misc/core-derive/tests/test.rs @@ -190,3 +190,24 @@ fn custom_event_and_polling() { require_net_behaviour::>(); } } + +#[test] +fn where_clause() { + #[allow(dead_code)] + #[derive(NetworkBehaviour)] + struct Foo where TSubstream: std::fmt::Debug { + ping: libp2p::ping::Ping, + } + + #[allow(dead_code)] + #[derive(NetworkBehaviour)] + struct Bar { + ping: libp2p::ping::Ping, + } + + #[allow(dead_code)] + #[derive(NetworkBehaviour)] + struct Qux where TSubstream: Clone { + ping: libp2p::ping::Ping, + } +}