From 62b49217d4088b3c5ee155c97015bad449ccfaca Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 22 Aug 2019 17:14:27 +0900 Subject: [PATCH] Fix handling of arguments of #[pin_project] attribute --- pin-project-internal/src/pin_project/mod.rs | 4 ++++ tests/pin_project.rs | 18 +++++++++++++++++- tests/ui/pin_project/invalid.rs | 6 ++++++ tests/ui/pin_project/invalid.stderr | 8 +++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pin-project-internal/src/pin_project/mod.rs b/pin-project-internal/src/pin_project/mod.rs index aad9d589..64f75944 100644 --- a/pin-project-internal/src/pin_project/mod.rs +++ b/pin-project-internal/src/pin_project/mod.rs @@ -37,6 +37,10 @@ impl Parse for Args { "UnsafeUnpin" => unsafe_unpin = Some(i.span()), _ => return Err(error!(i, "an invalid argument was passed")), } + + if !input.is_empty() { + let _: Comma = input.parse()?; + } } Ok(Self { pinned_drop, unsafe_unpin }) } diff --git a/tests/pin_project.rs b/tests/pin_project.rs index c24ed08f..2d5d7243 100644 --- a/tests/pin_project.rs +++ b/tests/pin_project.rs @@ -4,7 +4,7 @@ #![allow(dead_code)] use core::pin::Pin; -use pin_project::pin_project; +use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; #[test] fn test_pin_project() { @@ -164,3 +164,19 @@ fn overlapping_lifetime_names() { field: &'_pin mut T, } } + +#[test] +fn combine() { + #[pin_project(PinnedDrop, UnsafeUnpin)] + pub struct Foo { + field_1: u8, + #[pin] + field_2: T, + } + + #[pinned_drop] + fn do_drop(_: Pin<&mut Foo>) {} + + #[allow(unsafe_code)] + unsafe impl UnsafeUnpin for Foo {} +} diff --git a/tests/ui/pin_project/invalid.rs b/tests/ui/pin_project/invalid.rs index ac7c0a56..2223d34f 100644 --- a/tests/ui/pin_project/invalid.rs +++ b/tests/ui/pin_project/invalid.rs @@ -26,4 +26,10 @@ enum D { }, } +#[pin_project(UnsafeUnpin,,)] //~ ERROR unexpected token +struct E { + #[pin] + future: T, +} + fn main() {} diff --git a/tests/ui/pin_project/invalid.stderr b/tests/ui/pin_project/invalid.stderr index 1d1ea2e5..25c1a708 100644 --- a/tests/ui/pin_project/invalid.stderr +++ b/tests/ui/pin_project/invalid.stderr @@ -22,5 +22,11 @@ error: unexpected token 24 | #[pin(foo)] //~ ERROR unexpected token | ^ -error: aborting due to 4 previous errors +error: expected identifier + --> $DIR/invalid.rs:29:27 + | +29 | #[pin_project(UnsafeUnpin,,)] //~ ERROR unexpected token + | ^ + +error: aborting due to 5 previous errors