-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Unhelpful .clone()
suggestion when moving a mutable reference
#127285
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
cyrgani
added
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Jul 3, 2024
@rustbot claim |
surechen
added a commit
to surechen/rust
that referenced
this issue
Jul 10, 2024
…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 rust-lang#127285
surechen
added a commit
to surechen/rust
that referenced
this issue
Jul 11, 2024
…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 rust-lang#127285
surechen
added a commit
to surechen/rust
that referenced
this issue
Jul 11, 2024
…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 rust-lang#127285
surechen
added a commit
to surechen/rust
that referenced
this issue
Jul 11, 2024
…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 rust-lang#127285
surechen
added a commit
to surechen/rust
that referenced
this issue
Jul 12, 2024
…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 rust-lang#127285
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jul 17, 2024
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 rust-lang#127285
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Jul 18, 2024
Rollup merge of rust-lang#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 rust-lang#127285
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Rationale and extra context
Cloning the returned value (which is
()
) obviously doesn't help. But&mut T
does not implementClone
, so changing the suggestion to cloneself
wouldn't help either. In fact, adding.clone()
as suggested right now will error and suggest next:And so on.
Instead, reborrowing
self
withgeneric(&mut *self)
makes the code compile and should be suggested.Thanks to bruh791 on the rust community discord server for explaining the problem and solution to me.
Other cases
No response
Rust Version
Anything else?
Replacing the use of
with
compiles even without reborrowing.
The text was updated successfully, but these errors were encountered: