Skip to content

Commit

Permalink
Fix handling of arguments of #[pin_project] attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Aug 22, 2019
1 parent 403d0da commit 62b4921
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pin-project-internal/src/pin_project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down
18 changes: 17 additions & 1 deletion tests/pin_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -164,3 +164,19 @@ fn overlapping_lifetime_names() {
field: &'_pin mut T,
}
}

#[test]
fn combine() {
#[pin_project(PinnedDrop, UnsafeUnpin)]
pub struct Foo<T> {
field_1: u8,
#[pin]
field_2: T,
}

#[pinned_drop]
fn do_drop<T>(_: Pin<&mut Foo<T>>) {}

#[allow(unsafe_code)]
unsafe impl<T: Unpin> UnsafeUnpin for Foo<T> {}
}
6 changes: 6 additions & 0 deletions tests/ui/pin_project/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ enum D<T> {
},
}

#[pin_project(UnsafeUnpin,,)] //~ ERROR unexpected token
struct E<T> {
#[pin]
future: T,
}

fn main() {}
8 changes: 7 additions & 1 deletion tests/ui/pin_project/invalid.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 62b4921

Please sign in to comment.