-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change #[pinned_drop] to trait implementation #86
Conversation
We also need to decide the method name: #[pinned_drop]
impl<T, U> PinnedDrop for Foo<T, U> {
fn pinned_drop(self: Pin<&mut Self>) {}
}
// vs
#[pinned_drop]
impl<T, U> PinnedDrop for Foo<T, U> {
fn drop(self: Pin<&mut Self>) {}
} |
a4837ec
to
c579bb5
Compare
c579bb5
to
ad9e8a6
Compare
bors r+ |
86: Change #[pinned_drop] to trait implementation r=taiki-e a=taiki-e proc-macro just rewrites the trait path and adds `unsafe`. It needs to write the documentation more. ### Examples Before: ```rust use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; use std::pin::Pin; #[pin_project(UnsafeUnpin, PinnedDrop)] pub struct Foo<T, U> { #[pin] pinned_field: T, unpin_field: U } #[pinned_drop] fn do_drop<T, U>(this: Pin<&mut Foo<T, U>>) { // .. } unsafe impl<T: Unpin, U> UnsafeUnpin for Foo<T, U> {} ``` After: ```rust use pin_project::{pin_project, pinned_drop}; use std::pin::Pin; #[pin_project(UnsafeUnpin, PinnedDrop)] pub struct Foo<T, U> { #[pin] pinned_field: T, unpin_field: U } #[pinned_drop] impl<T, U> PinnedDrop for Foo<T, U> { fn drop(self: Pin<&mut Self>) { // .. } } unsafe impl<T: Unpin, U> UnsafeUnpin for Foo<T, U> {} ``` Closes #26 Co-authored-by: Taiki Endo <[email protected]>
Build succeeded
|
Why does it have to add unsafe? And why is it safe to do so? |
It is safe to implement Ideally, it would be desirable to be able to prohibit manual calls in the same way as |
Thanks, that explanation should be in the code somewhere. One thing though: if it is safe to implement, why is the trait unsafe? It should not be. Only its method should be unsafe, reflecting that it is unsafe to call. |
Although it is in a place that was not changed by this PR, I think this should be explained in the document, so I filed #88.
Indeed. I forgot to update it. |
91: Make PinnedDrop safe trait r=taiki-e a=taiki-e #86 (comment) Co-authored-by: Taiki Endo <[email protected]>
109: Release 0.4.0 r=taiki-e a=taiki-e cc #21 ### Changes since the latest 0.3 release: * **Pin projection has become a safe operation.** In the absence of other unsafe code that you write, it is impossible to cause undefined behavior. (#18) * `#[unsafe_project]` attribute has been replaced with `#[pin_project]` attribute. (#18, #33) * The `Unpin` argument has been removed - an `Unpin` impl is now generated by default. (#18) * Drop impls must be specified with `#[pinned_drop]` instead of via a normal `Drop` impl. (#18, #33, #86) * `Unpin` impls must be specified with an impl of `UnsafeUnpin`, instead of implementing the normal `Unpin` trait. (#18) * `#[pin_project]` attribute now determines the visibility of the projection type/method is based on the original type. (#96) * `#[pin_project]` can now be used for public type with private field types. (#53) * `#[pin_project]` can now interoperate with `#[cfg()]`. (#77) * Added `project_ref` method to `#[pin_project]` types. (#93) * Added `#[project_ref]` attribute. (#93) * Removed "project_attr" feature and always enable `#[project]` attribute. (#94) * `#[project]` attribute can now be used for `impl` blocks. (#46) * `#[project]` attribute can now be used for `use` statements. (#85) * `#[project]` attribute now supports `match` expressions at the position of the initializer expression of `let` expressions. (#51) ### Changes since the 0.4.0-beta.1 release: * Fixed an issue that caused an error when using `#[pin_project(UnsafeUnpin)]` and not providing a manual `UnsafeUnpin` implementation on a type with no generics or lifetime. (#107) Co-authored-by: Taiki Endo <[email protected]>
proc-macro just rewrites the trait path and adds
unsafe
.It needs to write the documentation more.
Examples
Before:
After:
Closes #26