-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest Pin::as_mut
when encountering borrow error
#106095
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 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c79db9c
Suggest `Pin::as_mut` when encountering borrow error
estebank a929316
Suggest `.clone()` on method call move errors
estebank 12fd901
Verify receiver is of `self: Pin<&mut Self>`
estebank ea7de0d
Do not use `hir_ty_to_ty`
estebank 2d6a2ff
Create new inference context
estebank bd890f9
Remove redundant clone suggestion
estebank 8a13a7c
review comments
estebank 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// run-rustfix | ||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
fn foo(self: Pin<&mut Self>) {} | ||
} | ||
|
||
fn main() { | ||
let mut foo = Foo; | ||
let mut foo = Pin::new(&mut foo); | ||
foo.as_mut().foo(); | ||
foo.foo(); //~ ERROR use of moved value | ||
} |
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 @@ | ||
// run-rustfix | ||
use std::pin::Pin; | ||
|
||
struct Foo; | ||
|
||
impl Foo { | ||
fn foo(self: Pin<&mut Self>) {} | ||
} | ||
|
||
fn main() { | ||
let mut foo = Foo; | ||
let mut foo = Pin::new(&mut foo); | ||
foo.foo(); | ||
foo.foo(); //~ ERROR use of moved value | ||
} |
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,23 @@ | ||
error[E0382]: use of moved value: `foo` | ||
--> $DIR/pin-mut-reborrow.rs:14:5 | ||
| | ||
LL | let mut foo = Pin::new(&mut foo); | ||
| ------- move occurs because `foo` has type `Pin<&mut Foo>`, which does not implement the `Copy` trait | ||
LL | foo.foo(); | ||
| ----- `foo` moved due to this method call | ||
LL | foo.foo(); | ||
| ^^^ value used here after move | ||
| | ||
note: `Foo::foo` takes ownership of the receiver `self`, which moves `foo` | ||
--> $DIR/pin-mut-reborrow.rs:7:12 | ||
| | ||
LL | fn foo(self: Pin<&mut Self>) {} | ||
| ^^^^ | ||
help: consider reborrowing the `Pin` instead of moving it | ||
| | ||
LL | foo.as_mut().foo(); | ||
| +++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
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,11 @@ | ||
// run-rustfix | ||
|
||
#[derive(Clone)] | ||
struct Foo; | ||
impl Foo { | ||
fn foo(self) {} | ||
} | ||
fn main() { | ||
let foo = &Foo; | ||
foo.clone().foo(); //~ ERROR cannot move out | ||
} |
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,11 @@ | ||
// run-rustfix | ||
|
||
#[derive(Clone)] | ||
struct Foo; | ||
impl Foo { | ||
fn foo(self) {} | ||
} | ||
fn main() { | ||
let foo = &Foo; | ||
foo.foo(); //~ ERROR cannot move out | ||
} |
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,22 @@ | ||
error[E0507]: cannot move out of `*foo` which is behind a shared reference | ||
--> $DIR/suggest-clone.rs:10:5 | ||
| | ||
LL | foo.foo(); | ||
| ^^^^----- | ||
| | | | ||
| | `*foo` moved due to this method call | ||
| move occurs because `*foo` has type `Foo`, which does not implement the `Copy` trait | ||
| | ||
note: `Foo::foo` takes ownership of the receiver `self`, which moves `*foo` | ||
--> $DIR/suggest-clone.rs:6:12 | ||
| | ||
LL | fn foo(self) {} | ||
| ^^^^ | ||
help: you can `clone` the value and consume it, but this might not be your desired behavior | ||
| | ||
LL | foo.clone().foo(); | ||
| ++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0507`. |
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.