Skip to content

Commit

Permalink
Merge #113
Browse files Browse the repository at this point in the history
113: Fix support for DSTs r=taiki-e a=taiki-e

Fixes #112

Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e authored Sep 29, 2019
2 parents 6e3c119 + fe39201 commit d6c097d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/pinned_drop-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn __unpin_scope_Foo() {
#[allow(single_use_lifetimes)]
#[allow(non_snake_case)]
#[deny(safe_packed_borrows)]
fn __pin_project_assert_not_repr_packed_Foo<'a, T>(val: Foo<'a, T>) {
fn __pin_project_assert_not_repr_packed_Foo<'a, T>(val: &Foo<'a, T>) {
{
&val.was_dropped;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl<T, U> StructMustNotImplDrop for Struct<T, U> {}
#[allow(single_use_lifetimes)]
#[allow(non_snake_case)]
#[deny(safe_packed_borrows)]
fn __pin_project_assert_not_repr_packed_Struct<T, U>(val: Struct<T, U>) {
fn __pin_project_assert_not_repr_packed_Struct<T, U>(val: &Struct<T, U>) {
{
&val.pinned;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/unsafe_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<T, U> FooMustNotImplDrop for Foo<T, U> {}
#[allow(single_use_lifetimes)]
#[allow(non_snake_case)]
#[deny(safe_packed_borrows)]
fn __pin_project_assert_not_repr_packed_Foo<T, U>(val: Foo<T, U>) {
fn __pin_project_assert_not_repr_packed_Foo<T, U>(val: &Foo<T, U>) {
{
&val.pinned;
}
Expand Down
4 changes: 2 additions & 2 deletions pin-project-internal/src/pin_project/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fn ensure_not_packed(item: &ItemStruct) -> Result<TokenStream> {
// struct, we generate code like this:
//
// #[deny(safe_packed_borrows)]
// fn enforce_not_packed_for_MyStruct(val: MyStruct) {
// fn enforce_not_packed_for_MyStruct(val: &MyStruct) {
// let _field1 = &val.field1;
// let _field2 = &val.field2;
// ...
Expand Down Expand Up @@ -381,7 +381,7 @@ fn ensure_not_packed(item: &ItemStruct) -> Result<TokenStream> {
#[allow(single_use_lifetimes)]
#[allow(non_snake_case)]
#[deny(safe_packed_borrows)]
fn #method_name #impl_generics (val: #struct_name #ty_generics) #where_clause {
fn #method_name #impl_generics (val: &#struct_name #ty_generics) #where_clause {
#(#field_refs)*
}
};
Expand Down
20 changes: 20 additions & 0 deletions tests/pin_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,23 @@ fn trivial_bounds() {
field: PhantomPinned,
}
}

#[test]
fn dst() {
#[pin_project]
pub struct A<T: ?Sized> {
x: T,
}

#[pin_project]
pub struct B<T: ?Sized> {
#[pin]
x: T,
}

#[pin_project]
pub struct C<T: ?Sized>(T);

#[pin_project]
pub struct D<T: ?Sized>(#[pin] T);
}
2 changes: 1 addition & 1 deletion tests/ui/pin_project/packed_sneaky-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate sneaky_macro;

use pin_project::pin_project;

hidden_repr_macro! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
hidden_repr_macro! { //~ ERROR may not be used on #[repr(packed)] types
#[pin_project]
struct B {
#[pin]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/pin_project/packed_sneaky-2.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: #[pin_project] attribute may not be used on #[repr(packed)] types
--> $DIR/packed_sneaky-2.rs:9:1
|
9 | / hidden_repr_macro! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
9 | / hidden_repr_macro! { //~ ERROR may not be used on #[repr(packed)] types
10 | | #[pin_project]
11 | | struct B {
12 | | #[pin]
Expand Down

0 comments on commit d6c097d

Please sign in to comment.