Skip to content

Commit

Permalink
Merge #322
Browse files Browse the repository at this point in the history
322: v0.4: Fix unused_must_use warning on unused borrows r=taiki-e a=taiki-e

This fixes `unused_must_use` warning on unused borrows, which will be added to rustc in the future.

See rust-lang/rust#76894 fore more.

(Note: pin-project 1.0 does not have this problem.)


Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e authored Mar 28, 2021
2 parents 9e67d8b + 88ff0cb commit c6905a4
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 71 deletions.
6 changes: 3 additions & 3 deletions examples/not_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ const _: () = {
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
// for details.
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};

Expand Down
6 changes: 3 additions & 3 deletions examples/pinned_drop-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ const _: () = {
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
// for details.
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<'a, T>(val: &Struct<'a, T>) {
&val.was_dropped;
&val.field;
fn __assert_not_repr_packed<'a, T>(this: &Struct<'a, T>) {
let _ = &this.was_dropped;
let _ = &this.field;
}
};

Expand Down
6 changes: 3 additions & 3 deletions examples/project_replace-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ const _: () = {
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
// for details.
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};

Expand Down
6 changes: 3 additions & 3 deletions examples/struct-default-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ const _: () = {
//
// See https://github.com/taiki-e/pin-project/pull/34 for more details.
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};

Expand Down
6 changes: 3 additions & 3 deletions examples/unsafe_unpin-expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ const _: () = {
// See ./struct-default-expanded.rs and https://github.com/taiki-e/pin-project/pull/34
// for details.
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};

Expand Down
8 changes: 4 additions & 4 deletions pin-project-internal/src/pin_project/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,13 +1208,13 @@ impl<'a> Context<'a> {
match fields {
Fields::Named(FieldsNamed { named, .. }) => {
for Field { ident, .. } in named {
field_refs.push(quote!(&val.#ident;));
field_refs.push(quote!(&this.#ident));
}
}
Fields::Unnamed(FieldsUnnamed { unnamed, .. }) => {
for (index, _) in unnamed.iter().enumerate() {
let index = Index::from(index);
field_refs.push(quote!(&val.#index;));
field_refs.push(quote!(&this.#index));
}
}
Fields::Unit => {}
Expand All @@ -1224,8 +1224,8 @@ impl<'a> Context<'a> {
let ident = self.orig.ident;
Ok(quote! {
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed #impl_generics (val: &#ident #ty_generics) #where_clause {
#(#field_refs)*
fn __assert_not_repr_packed #impl_generics (this: &#ident #ty_generics) #where_clause {
#(let _ = #field_refs;)*
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/default-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/default-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
}
};
fn main() {}
10 changes: 5 additions & 5 deletions tests/expand/tests/expand/multifields-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned1;
&val.pinned2;
&val.unpinned1;
&val.unpinned2;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned1;
let _ = &this.pinned2;
let _ = &this.unpinned1;
let _ = &this.unpinned2;
}
};
fn main() {}
10 changes: 5 additions & 5 deletions tests/expand/tests/expand/multifields-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
&val.2;
&val.3;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
let _ = &this.2;
let _ = &this.3;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/naming-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/naming-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/not_unpin-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/not_unpin-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/pinned_drop-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ const _: () = {
}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};
impl<T, U> ::pin_project::__private::PinnedDrop for Struct<T, U> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ const _: () = {
}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
}
};
impl<T, U> ::pin_project::__private::PinnedDrop for TupleStruct<T, U> {
Expand Down
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/project_replace-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};
fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/pub-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/pub-tuple_struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
}
};
fn main() {}
6 changes: 3 additions & 3 deletions tests/expand/tests/expand/unsafe_unpin-struct.expanded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &Struct<T, U>) {
&val.pinned;
&val.unpinned;
fn __assert_not_repr_packed<T, U>(this: &Struct<T, U>) {
let _ = &this.pinned;
let _ = &this.unpinned;
}
};
unsafe impl<T: Unpin, U> UnsafeUnpin for Struct<T, U> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ const _: () = {
unsafe fn drop(self: ::pin_project::__private::Pin<&mut Self>) {}
}
#[forbid(safe_packed_borrows)]
fn __assert_not_repr_packed<T, U>(val: &TupleStruct<T, U>) {
&val.0;
&val.1;
fn __assert_not_repr_packed<T, U>(this: &TupleStruct<T, U>) {
let _ = &this.0;
let _ = &this.1;
}
};
unsafe impl<T: Unpin, U> UnsafeUnpin for Struct<T, U> {}
Expand Down

0 comments on commit c6905a4

Please sign in to comment.