Skip to content

Commit d6c097d

Browse files
bors[bot]taiki-e
andauthored
113: Fix support for DSTs r=taiki-e a=taiki-e Fixes taiki-e#112 Co-authored-by: Taiki Endo <te316e89@gmail.com>
2 parents 6e3c119 + fe39201 commit d6c097d

File tree

7 files changed

+27
-7
lines changed

7 files changed

+27
-7
lines changed

examples/pinned_drop-expanded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn __unpin_scope_Foo() {
130130
#[allow(single_use_lifetimes)]
131131
#[allow(non_snake_case)]
132132
#[deny(safe_packed_borrows)]
133-
fn __pin_project_assert_not_repr_packed_Foo<'a, T>(val: Foo<'a, T>) {
133+
fn __pin_project_assert_not_repr_packed_Foo<'a, T>(val: &Foo<'a, T>) {
134134
{
135135
&val.was_dropped;
136136
}

examples/struct-default-expanded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<T, U> StructMustNotImplDrop for Struct<T, U> {}
130130
#[allow(single_use_lifetimes)]
131131
#[allow(non_snake_case)]
132132
#[deny(safe_packed_borrows)]
133-
fn __pin_project_assert_not_repr_packed_Struct<T, U>(val: Struct<T, U>) {
133+
fn __pin_project_assert_not_repr_packed_Struct<T, U>(val: &Struct<T, U>) {
134134
{
135135
&val.pinned;
136136
}

examples/unsafe_unpin-expanded.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<T, U> FooMustNotImplDrop for Foo<T, U> {}
8585
#[allow(single_use_lifetimes)]
8686
#[allow(non_snake_case)]
8787
#[deny(safe_packed_borrows)]
88-
fn __pin_project_assert_not_repr_packed_Foo<T, U>(val: Foo<T, U>) {
88+
fn __pin_project_assert_not_repr_packed_Foo<T, U>(val: &Foo<T, U>) {
8989
{
9090
&val.pinned;
9191
}

pin-project-internal/src/pin_project/attribute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn ensure_not_packed(item: &ItemStruct) -> Result<TokenStream> {
322322
// struct, we generate code like this:
323323
//
324324
// #[deny(safe_packed_borrows)]
325-
// fn enforce_not_packed_for_MyStruct(val: MyStruct) {
325+
// fn enforce_not_packed_for_MyStruct(val: &MyStruct) {
326326
// let _field1 = &val.field1;
327327
// let _field2 = &val.field2;
328328
// ...
@@ -381,7 +381,7 @@ fn ensure_not_packed(item: &ItemStruct) -> Result<TokenStream> {
381381
#[allow(single_use_lifetimes)]
382382
#[allow(non_snake_case)]
383383
#[deny(safe_packed_borrows)]
384-
fn #method_name #impl_generics (val: #struct_name #ty_generics) #where_clause {
384+
fn #method_name #impl_generics (val: &#struct_name #ty_generics) #where_clause {
385385
#(#field_refs)*
386386
}
387387
};

tests/pin_project.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,23 @@ fn trivial_bounds() {
357357
field: PhantomPinned,
358358
}
359359
}
360+
361+
#[test]
362+
fn dst() {
363+
#[pin_project]
364+
pub struct A<T: ?Sized> {
365+
x: T,
366+
}
367+
368+
#[pin_project]
369+
pub struct B<T: ?Sized> {
370+
#[pin]
371+
x: T,
372+
}
373+
374+
#[pin_project]
375+
pub struct C<T: ?Sized>(T);
376+
377+
#[pin_project]
378+
pub struct D<T: ?Sized>(#[pin] T);
379+
}

tests/ui/pin_project/packed_sneaky-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate sneaky_macro;
66

77
use pin_project::pin_project;
88

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
1010
#[pin_project]
1111
struct B {
1212
#[pin]

tests/ui/pin_project/packed_sneaky-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: #[pin_project] attribute may not be used on #[repr(packed)] types
22
--> $DIR/packed_sneaky-2.rs:9:1
33
|
4-
9 | / hidden_repr_macro! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block
4+
9 | / hidden_repr_macro! { //~ ERROR may not be used on #[repr(packed)] types
55
10 | | #[pin_project]
66
11 | | struct B {
77
12 | | #[pin]

0 commit comments

Comments
 (0)