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

Add impl block support to #[project] attribute #46

Merged
merged 1 commit into from
Aug 23, 2019
Merged

Conversation

taiki-e
Copy link
Owner

@taiki-e taiki-e commented Aug 18, 2019

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

Example:

#[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

@taiki-e taiki-e force-pushed the project-impl branch 4 times, most recently from 584473b to bed5af8 Compare August 19, 2019 07:01
@Nemo157
Copy link

Nemo157 commented Aug 19, 2019

I only looked at the docs and tests, but design looks good to me!

@taiki-e taiki-e marked this pull request as ready for review August 23, 2019 04:31
@taiki-e taiki-e force-pushed the project-impl branch 2 times, most recently from 5720f07 to 01a6574 Compare August 23, 2019 04:37
@taiki-e
Copy link
Owner Author

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 <te316e89@gmail.com>
Co-authored-by: Aaron Hill <aa1ronham@gmail.com>
@bors
Copy link
Contributor

bors bot commented Aug 23, 2019

Build succeeded

  • taiki-e.pin-project

@bors bors bot merged commit f8d0a0c into master Aug 23, 2019
@taiki-e taiki-e mentioned this pull request Aug 23, 2019
11 tasks
@taiki-e taiki-e deleted the project-impl branch August 23, 2019 04:51
@taiki-e taiki-e added this to the v0.4 milestone Aug 24, 2019
@taiki-e taiki-e added the A-project-attribute Area: #[project], #[project_ref], and #[project_replace] (note: this was removed in v1.0) label Sep 24, 2019
@taiki-e taiki-e mentioned this pull request Sep 25, 2019
bors bot added a commit that referenced this pull request Sep 25, 2019
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 <te316e89@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-project-attribute Area: #[project], #[project_ref], and #[project_replace] (note: this was removed in v1.0)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide way to refer to projected type
2 participants