-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Begin experimental support for pin reborrowing #130526
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7b7992f
Begin experimental support for pin reborrowing
eholk a73c8b1
Apply code review suggestions
eholk b2b76fb
Allow shortening reborrows
eholk 92a5d21
Add a test case to make sure we don't reborrow twice
eholk a18800f
pin_ergonomics: allow reborrowing as Pin<&T>
eholk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//@ check-pass | ||
|
||
#![feature(pin_ergonomics)] | ||
#![allow(dead_code, incomplete_features)] | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
fn baz(self: Pin<&mut Self>) { | ||
} | ||
} | ||
|
||
fn foo(_: Pin<&mut Foo>) { | ||
} | ||
|
||
fn bar(mut x: Pin<&mut Foo>) { | ||
eholk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
foo(x); | ||
foo(x); // for this to work we need to automatically reborrow, | ||
// as if the user had written `foo(x.as_mut())`. | ||
|
||
Foo::baz(x); | ||
Foo::baz(x); | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//@ check-pass | ||
//@ignore-test | ||
|
||
// Currently ignored due to self reborrowing not being implemented for Pin | ||
|
||
#![feature(pin_ergonomics)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
fn foo(self: Pin<&mut Self>) { | ||
} | ||
} | ||
|
||
fn bar(x: Pin<&mut Foo>) { | ||
x.foo(); | ||
x.foo(); // for this to work we need to automatically reborrow, | ||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// as if the user had written `x.as_mut().foo()`. | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#![allow(dead_code, incomplete_features)] | ||
|
||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
fn foo(_: Pin<&mut Foo>) { | ||
} | ||
|
||
fn bar(mut x: Pin<&mut Foo>) { | ||
foo(x); | ||
foo(x); //~ ERROR use of moved value: `x` | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0382]: use of moved value: `x` | ||
--> $DIR/feature-gate-pin_ergonomics.rs:12:9 | ||
| | ||
LL | fn bar(mut x: Pin<&mut Foo>) { | ||
| ----- move occurs because `x` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait | ||
LL | foo(x); | ||
| - value moved here | ||
LL | foo(x); | ||
| ^ value used here after move | ||
| | ||
note: consider changing this parameter type in function `foo` to borrow instead if owning the value isn't necessary | ||
--> $DIR/feature-gate-pin_ergonomics.rs:7:11 | ||
| | ||
LL | fn foo(_: Pin<&mut Foo>) { | ||
| --- ^^^^^^^^^^^^^ this parameter takes ownership of the value | ||
| | | ||
| in this function | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.