-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Begin experimental support for pin reborrowing #130526
Conversation
This commit adds basic support for reborrowing `Pin` types in argument position. At the moment it only supports reborrowing `Pin<&mut T>` as `Pin<&mut T>` by inserting a call to `Pin::as_mut()`, and only in argument position (not as the receiver in a method call).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some thoughts. Specifically, aside from the nits, there's a problem with the desugaring that makes it not as general as when the feature gate is disabled due to the specific lowering to a call of Pin::as_mut
. I think that should be changed.
This comment has been minimized.
This comment has been minimized.
Thanks for making this pretty bite-sized though. I was somewhat afraid you were going to put up a huge pin ergonomics PR; I'm happy to review this work, but if possible, I'd like to have more PRs that are smaller than fewer PRs that are larger (I know I am a huge hypocrite for doing that exact thing, so if it's not possible, then I understand lol). |
Thanks for the comments! I'm a fan of going for the smallest atomic change I can do, but sometimes the smallest atomic change is quite large. The nice thing about the pin ergonomics experiment is that it's around 4-6 independent features and half of them should be pretty small. |
Generating a call to `as_mut()` let to more restrictive borrows than what reborrowing usually gives us. Instead, we change the desugaring to reborrow the pin internals directly which makes things more expressive.
It went ahead and added support for reborrowing |
@bors r+ rollup |
…llaumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#128209 (Remove macOS 10.10 dynamic linker bug workaround) - rust-lang#130526 (Begin experimental support for pin reborrowing) - rust-lang#130611 (Address diagnostics regression for `const_char_encode_utf8`.) - rust-lang#130614 (Add arm64e-apple-tvos target) - rust-lang#130617 (bail if there are too many non-region infer vars in the query response) - rust-lang#130619 (Fix scraped examples height) - rust-lang#130624 (Add `Vec::as_non_null`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130526 - eholk:pin-reborrow, r=compiler-errors Begin experimental support for pin reborrowing This commit adds basic support for reborrowing `Pin` types in argument position. At the moment it only supports reborrowing `Pin<&mut T>` as `Pin<&mut T>` by inserting a call to `Pin::as_mut()`, and only in argument position (not as the receiver in a method call). This PR makes the following example compile: ```rust #![feature(pin_ergonomics)] fn foo(_: Pin<&mut Foo>) { } fn bar(mut x: Pin<&mut Foo>) { foo(x); foo(x); } ``` Previously, you would have had to write `bar` as: ```rust fn bar(mut x: Pin<&mut Foo>) { foo(x.as_mut()); foo(x); } ``` Tracking: - rust-lang#130494 r? `@compiler-errors`
…errors Add support for reborrowing pinned method receivers This builds on rust-lang#130526 to add pinned reborrowing for method receivers. This enables the folllowing examples to work: ```rust #![feature(pin_ergonomics)] #![allow(incomplete_features)] use std::pin::Pin; pub struct Foo; impl Foo { fn foo(self: Pin<&mut Self>) { } fn baz(self: Pin<&Self>) { } } pub fn bar(x: Pin<&mut Foo>) { x.foo(); x.foo(); x.baz(); // Pin<&mut Foo> is downgraded to Pin<&Foo> } pub fn baaz(x: Pin<&Foo>) { x.baz(); x.baz(); } ``` This PR includes the original one, which is currently in the commit queue, but the only code changes are in the latest commit (d3c53aa). rust-lang#130494 r? `@compiler-errors`
…r-errors Add support for reborrowing pinned method receivers This builds on rust-lang#130526 to add pinned reborrowing for method receivers. This enables the folllowing examples to work: ```rust #![feature(pin_ergonomics)] #![allow(incomplete_features)] use std::pin::Pin; pub struct Foo; impl Foo { fn foo(self: Pin<&mut Self>) { } fn baz(self: Pin<&Self>) { } } pub fn bar(x: Pin<&mut Foo>) { x.foo(); x.foo(); x.baz(); // Pin<&mut Foo> is downgraded to Pin<&Foo> } pub fn baaz(x: Pin<&Foo>) { x.baz(); x.baz(); } ``` This PR includes the original one, which is currently in the commit queue, but the only code changes are in the latest commit (d3c53aa). rust-lang#130494 r? `@compiler-errors`
Rollup merge of rust-lang#130633 - eholk:pin-reborrow-self, r=compiler-errors Add support for reborrowing pinned method receivers This builds on rust-lang#130526 to add pinned reborrowing for method receivers. This enables the folllowing examples to work: ```rust #![feature(pin_ergonomics)] #![allow(incomplete_features)] use std::pin::Pin; pub struct Foo; impl Foo { fn foo(self: Pin<&mut Self>) { } fn baz(self: Pin<&Self>) { } } pub fn bar(x: Pin<&mut Foo>) { x.foo(); x.foo(); x.baz(); // Pin<&mut Foo> is downgraded to Pin<&Foo> } pub fn baaz(x: Pin<&Foo>) { x.baz(); x.baz(); } ``` This PR includes the original one, which is currently in the commit queue, but the only code changes are in the latest commit (d3c53aa). rust-lang#130494 r? `@compiler-errors`
…er-errors Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes rust-lang#130526 since that one is in the commit queue. Only the most recent commits (bd45002 and following) are new. Tracking: - rust-lang#130494 r? `@compiler-errors`
Rollup merge of rust-lang#130635 - eholk:pin-reborrow-sugar, r=compiler-errors Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes rust-lang#130526 since that one is in the commit queue. Only the most recent commits (bd45002 and following) are new. Tracking: - rust-lang#130494 r? `@compiler-errors`
…er-errors Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes rust-lang#130526 since that one is in the commit queue. Only the most recent commits (bd45002 and following) are new. Tracking: - rust-lang#130494 r? `@compiler-errors`
This commit adds basic support for reborrowing
Pin
types in argument position. At the moment it only supports reborrowingPin<&mut T>
asPin<&mut T>
by inserting a call toPin::as_mut()
, and only in argument position (not as the receiver in a method call).This PR makes the following example compile:
Previously, you would have had to write
bar
as:Tracking:
r? @compiler-errors