forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#106095 - estebank:pin-mut-reborrow, r=compile…
…r-errors Suggest `Pin::as_mut` when encountering borrow error Fix rust-lang#65409 for `Pin<&mut T>`.
- Loading branch information
Showing
17 changed files
with
205 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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
15 changes: 15 additions & 0 deletions
15
src/test/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.fixed
This file contains 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 | ||
// Test that a by-ref `FnMut` closure gets an error when it tries to | ||
// consume a value. | ||
|
||
fn call<F>(f: F) where F : Fn() { | ||
f(); | ||
} | ||
|
||
fn main() { | ||
let y = vec![format!("World")]; | ||
call(|| { | ||
y.clone().into_iter(); | ||
//~^ ERROR cannot move out of `y`, a captured variable in an `Fn` closure | ||
}); | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.rs
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// run-rustfix | ||
// Test that a by-ref `FnMut` closure gets an error when it tries to | ||
// consume a value. | ||
|
||
|
This file contains 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 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 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 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 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 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 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 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 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 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 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`. |
This file contains 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