-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Provide suggestions for some moved value errors #73534
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
Merged
Merged
Conversation
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
(rust_highfive has picked a reviewer for you, use r? to override) |
estebank
commented
Jun 20, 2020
r? @matthewjasper (or someone else maintaining borrow checker) |
@bors r+ |
📌 Commit 5faf657 has been approved by |
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
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 pull request
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.
This comment has been minimized.
This comment has been minimized.
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.
5faf657
to
520461f
Compare
@bors r=matthewjasper rebased |
📌 Commit 520461f has been approved by |
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
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 pull request
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.
This was referenced Jun 26, 2020
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jun 26, 2020
…arth Rollup of 14 pull requests Successful merges: - rust-lang#72617 (Add a fast path for `std::thread::panicking`.) - rust-lang#72738 (Self contained linking option) - rust-lang#72770 (Implement mixed script confusable lint.) - rust-lang#73418 (Add unstable `core::mem::variant_count` intrinsic) - rust-lang#73460 (Emit line info for generator variants) - rust-lang#73534 (Provide suggestions for some moved value errors) - rust-lang#73538 (make commented examples use valid syntax, and be more consistent ) - rust-lang#73581 (Create 0766 error code) - rust-lang#73619 (Document the mod keyword) - rust-lang#73621 (Document the mut keyword) - rust-lang#73648 (Document the return keyword) - rust-lang#73673 (Fix ptr doc warnings.) - rust-lang#73674 (Tweak binop errors) - rust-lang#73687 (Clean up E0701 explanation) Failed merges: - rust-lang#73708 (Explain move errors that occur due to method calls involving `self` (take two)) r? @ghost
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Apr 3, 2025
Dedup `&mut *` reborrow suggestion in loops rust-lang#73534 added a reborrow suggestion in loops; rust-lang#127579 generalized this to generic parameters, making the suggestion triggers twice: ```rs use std::io::Read; fn decode_scalar(_reader: impl Read) {} fn decode_array(reader: &mut impl Read) { for _ in 0.. { decode_scalar(reader); } } ``` ``` error[E0382]: use of moved value: `reader` --> src/lib.rs:6:23 | 4 | fn decode_array(reader: &mut impl Read) { | ------ move occurs because `reader` has type `&mut impl Read`, which does not implement the `Copy` trait 5 | for _ in 0.. { | ------------ inside of this loop 6 | decode_scalar(reader); | ^^^^^^ value moved here, in previous iteration of loop | help: consider creating a fresh reborrow of `reader` here | 6 | decode_scalar(&mut *reader); | ++++++ help: consider creating a fresh reborrow of `reader` here | 6 | decode_scalar(&mut *reader); | ++++++ ``` This PR removes the suggestion in loops, as it requires generic parameters anyway (i.e., the reborrow is automatic if there is no generic params). `@rustbot` label +A-borrow-checker +A-diagnostics +A-suggestion-diagnostics +D-papercut
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 4, 2025
Rollup merge of rust-lang#138462 - ShE3py:mut-borrow-in-loop, r=oli-obk Dedup `&mut *` reborrow suggestion in loops rust-lang#73534 added a reborrow suggestion in loops; rust-lang#127579 generalized this to generic parameters, making the suggestion triggers twice: ```rs use std::io::Read; fn decode_scalar(_reader: impl Read) {} fn decode_array(reader: &mut impl Read) { for _ in 0.. { decode_scalar(reader); } } ``` ``` error[E0382]: use of moved value: `reader` --> src/lib.rs:6:23 | 4 | fn decode_array(reader: &mut impl Read) { | ------ move occurs because `reader` has type `&mut impl Read`, which does not implement the `Copy` trait 5 | for _ in 0.. { | ------------ inside of this loop 6 | decode_scalar(reader); | ^^^^^^ value moved here, in previous iteration of loop | help: consider creating a fresh reborrow of `reader` here | 6 | decode_scalar(&mut *reader); | ++++++ help: consider creating a fresh reborrow of `reader` here | 6 | decode_scalar(&mut *reader); | ++++++ ``` This PR removes the suggestion in loops, as it requires generic parameters anyway (i.e., the reborrow is automatic if there is no generic params). `@rustbot` label +A-borrow-checker +A-diagnostics +A-suggestion-diagnostics +D-papercut
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When encountering an used moved value where the previous move happened
in a
match
orif let
pattern, suggest usingref
. Fix #63988.When encountering a
&mut
value that is used in multiple iterations ofa loop, suggest reborrowing it with
&mut *
. Fix #62112.