-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #127579 - surechen:fix_127285, r=lcnr
Solve a error `.clone()` suggestion when moving a mutable reference If the moved value is a mut reference, it is used in a generic function and it's type is a generic param, suggest 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
7 changed files
with
128 additions
and
41 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
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() {} |
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
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 | ||
| | ||
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`. |
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