Skip to content
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

Assert lack of Drop impl without implementing Drop #48

Merged
merged 2 commits into from
Aug 23, 2019

Conversation

Aaron1011
Copy link
Collaborator

Previously, we would provide an empty Drop impl for types that did not
provide a pinned_drop method, in order to assert that the user was not
providing their own Drop impl.

However, the compiler places certain restrictions on types that
implement Drop. For example, you cannot move out of the fields of such
types, as that would cause the Drop impl to observe the fields in an
uninitialized state.

This commit changes to a purely trait-based approach, as used in
the assert-impl crate by @upsuper . This prevents the creation of
unnecessary Drop impls, while still ensuring that the user cannot
provide their own Drop impl without going through pinned_drop

Previously, we would provide an empty Drop impl for types that did not
provide a pinned_drop method, in order to assert that the user was not
providing their own Drop impl.

However, the compiler places certain restrictions on types that
implement Drop. For example, you cannot move out of the fields of such
types, as that would cause the Drop impl to observe the fields in an
uninitialized state.

This commit changes to a purely trait-based approach, as used in
the assert-impl crate by @upsuper . This prevents the creation of
unnecessary Drop impls, while still ensuring that the user cannot
provide their own Drop impl without going through pinned_drop
@taiki-e
Copy link
Owner

taiki-e commented Aug 23, 2019

Looks great to me. Could you update the documents as well?

/// To enforce this, this attribute will automatically generate a `Drop` impl.

/// To ensure that this requirement is upheld, the `pin_project` attribute will
/// provide a `Drop` impl for you. This `Drop` impl will delegate to a function

@taiki-e
Copy link
Owner

taiki-e commented Aug 23, 2019

r=me with documents updated

bors delegate+

@bors
Copy link
Contributor

bors bot commented Aug 23, 2019

✌️ Aaron1011 can now approve this pull request

@Aaron1011
Copy link
Collaborator Author

@taiki-e: I updated the first doc comment. I believe the second one is still accurate, as we still generate a Drop impl when you use #[pinned_drop]

@taiki-e
Copy link
Owner

taiki-e commented Aug 23, 2019

Ah, indeed.

@taiki-e
Copy link
Owner

taiki-e commented Aug 23, 2019

bors r+

bors bot added a commit that referenced this pull request Aug 23, 2019
46: Add impl block support to #[project] attribute r=taiki-e a=taiki-e

This adds a feature to convert an annotated impl to a projected type's impl.

Example:

```rust
#[project]
impl<T, U> Foo<T, U> {
    fn baz(self) {
        let Self { future, field } = self;
    }
}

// convert to:
impl<'_pin, T, U> __FooProjection<'_pin, T, U> {
    fn baz(self) {
        let Self { future, field } = self;
    }
}
```

Closes #43

cc @Nemo157



48: Assert lack of Drop impl without implementing Drop r=taiki-e a=Aaron1011

Previously, we would provide an empty Drop impl for types that did not
provide a pinned_drop method, in order to assert that the user was not
providing their own Drop impl.

However, the compiler places certain restrictions on types that
implement Drop. For example, you cannot move out of the fields of such
types, as that would cause the Drop impl to observe the fields in an
uninitialized state.

This commit changes to a purely trait-based approach, as used in
the assert-impl crate by @upsuper . This prevents the creation of
unnecessary Drop impls, while still ensuring that the user cannot
provide their own Drop impl without going through pinned_drop

Co-authored-by: Taiki Endo <[email protected]>
Co-authored-by: Aaron Hill <[email protected]>
@bors
Copy link
Contributor

bors bot commented Aug 23, 2019

Build succeeded

  • taiki-e.pin-project

@bors bors bot merged commit deea6e8 into taiki-e:master Aug 23, 2019
@taiki-e taiki-e added the A-drop Area: #[pinned_drop] and Drop label Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-drop Area: #[pinned_drop] and Drop
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants