From 615dd3332fd4d14d9f41ffa69ee4beb841aece98 Mon Sep 17 00:00:00 2001 From: Dan Robertson Date: Mon, 21 Jan 2019 10:56:01 +0000 Subject: [PATCH] derive(NetworkBehaviour) handles trailing commas (#874) Properly handle trailing commas in derive(NetworkBehaviour) --- misc/core-derive/src/lib.rs | 6 +++++- misc/core-derive/tests/test.rs | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/misc/core-derive/src/lib.rs b/misc/core-derive/src/lib.rs index 0a423b18..79a551a5 100644 --- a/misc/core-derive/src/lib.rs +++ b/misc/core-derive/src/lib.rs @@ -112,7 +112,11 @@ 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),*}) + if where_clause.predicates.trailing_punct() { + Some(quote!{#where_clause #(#additional),*}) + } else { + 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 0f90baf6..98073e94 100644 --- a/misc/core-derive/tests/test.rs +++ b/misc/core-derive/tests/test.rs @@ -205,6 +205,12 @@ fn where_clause() { ping: libp2p::ping::Ping, } + #[allow(dead_code)] + #[derive(NetworkBehaviour)] + struct Baz where TSubstream: std::fmt::Debug + Clone, { + ping: libp2p::ping::Ping, + } + #[allow(dead_code)] #[derive(NetworkBehaviour)] struct Qux where TSubstream: Clone {