-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the moved value is a mut reference, it is used in a generic functi…
…on and it's type is a generic param, it can be reborrowed to avoid moving. for example: ```rust struct Y(u32); // x's type is '& mut Y' and it is used in `fn generic<T>(x: T) {}`. fn generic<T>(x: T) {} ``` fixes #127285
- Loading branch information
Showing
4 changed files
with
110 additions
and
12 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
17 changes: 17 additions & 0 deletions
17
tests/ui/borrowck/moved-value-suggest-reborrow-issue-127285.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,17 @@ | ||
//@ run-rustfix | ||
|
||
#![allow(dead_code)] | ||
|
||
struct X(u32); | ||
|
||
impl X { | ||
fn f(&mut self) { | ||
generic(&mut *self); | ||
self.0 += 1; | ||
//~^ ERROR: use of moved value: `self` [E0382] | ||
} | ||
} | ||
|
||
fn generic<T>(_x: T) {} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/borrowck/moved-value-suggest-reborrow-issue-127285.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//@ run-rustfix | ||
|
||
#![allow(dead_code)] | ||
|
||
struct X(u32); | ||
|
||
impl X { | ||
fn f(&mut self) { | ||
generic(self); | ||
self.0 += 1; | ||
//~^ ERROR: use of moved value: `self` [E0382] | ||
} | ||
} | ||
|
||
fn generic<T>(_x: T) {} | ||
|
||
fn main() {} |
25 changes: 25 additions & 0 deletions
25
tests/ui/borrowck/moved-value-suggest-reborrow-issue-127285.stderr
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,25 @@ | ||
error[E0382]: use of moved value: `self` | ||
--> $DIR/moved-value-suggest-reborrow-issue-127285.rs:10:9 | ||
| | ||
LL | fn f(&mut self) { | ||
| --------- move occurs because `self` has type `&mut X`, which does not implement the `Copy` trait | ||
LL | generic(self); | ||
| ---- value moved here | ||
LL | self.0 += 1; | ||
| ^^^^^^^^^^^ value used here after move | ||
| | ||
note: consider changing this parameter type in function `generic` to borrow instead if owning the value isn't necessary | ||
--> $DIR/moved-value-suggest-reborrow-issue-127285.rs:15:19 | ||
| | ||
LL | fn generic<T>(_x: T) {} | ||
| ------- ^ this parameter takes ownership of the value | ||
| | | ||
| in this function | ||
help: consider creating a fresh reborrow of `self` here | ||
| | ||
LL | generic(&mut *self); | ||
| ++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0382`. |