-
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
"use of moved value" diagnostic could suggest reborrow when passing &mut
to &mut
#62112
Labels
A-borrow-checker
Area: The borrow checker
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
pnkfelix
added
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
A-borrow-checker
Area: The borrow checker
and removed
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
labels
Jun 25, 2019
estebank
added
the
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
label
Jul 14, 2019
estebank
added
the
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
label
Oct 5, 2019
crlf0710
added
the
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
label
Jun 11, 2020
estebank
added a commit
to estebank/rust
that referenced
this issue
Jun 20, 2020
When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Jun 21, 2020
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Jun 22, 2020
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Jun 26, 2020
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Jun 26, 2020
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Jun 26, 2020
…tthewjasper Provide suggestions for some moved value errors When encountering an used moved value where the previous move happened in a `match` or `if let` pattern, suggest using `ref`. Fix rust-lang#63988. When encountering a `&mut` value that is used in multiple iterations of a loop, suggest reborrowing it with `&mut *`. Fix rust-lang#62112.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-borrow-checker
Area: The borrow checker
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Spawned off of #45142
Consider the following code (play):
Today, this yields the diagnostic:
We could do better. For example, the diagnostic could additionally say:
Background:
The compiler tries hard to auto-inject
&mut
-reborrows when it makes sense; as a way to create a fresh&mut
reference to pass into the method invocation, and avoid moving the pre-existing&mut
reference.But there are times, often involving generic code, when it cannot automatically inject a reborrow. (After all, there are cases where the intent is to move the borrow into some place whose dynamic extent outlives that of the method invocation itself; and the static analysis cannot tell if this was the case at the point where it is deciding whether to insert an
&mut
-reborrow or not.)This can lead to a diagnostic for the user telling them that they have a used of a moved value.
But new-comers to Rust do not always know about the option of putting in a
&mut
-reborrow themselves.Our diagnostics could help them here. Even though we choose to not attempt to auto-inject the auto-reborrow in the compiler itself, our diagnostics have enough information about the method signature and the invocation to suggest to the user that they write out the
&mut *value
themselves.The text was updated successfully, but these errors were encountered: