Skip to content

Conversation

ShE3py
Copy link
Contributor

@ShE3py ShE3py commented Mar 13, 2025

#73534 added a reborrow suggestion in loops; #127579 generalized this to generic parameters, making the suggestion triggers twice:

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

@rustbot
Copy link
Collaborator

rustbot commented Mar 13, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. A-borrow-checker Area: The borrow checker labels Mar 13, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Apr 2, 2025

Sorry I kept meaning to get to this but its seeming like I probably wont.
r? compiler

@rustbot rustbot assigned oli-obk and unassigned BoxyUwU Apr 2, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Apr 3, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 3, 2025

📌 Commit 2d2307e has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 3, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 3, 2025
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#138017 (Tighten up assignment operator representations.) - rust-lang#138462 (Dedup `&mut *` reborrow suggestion in loops) - rust-lang#138610 (impl !PartialOrd for HirId) - rust-lang#138767 (Allow boolean literals in `check-cfg`) - rust-lang#139068 (io: Avoid marking some bytes as uninit) - rust-lang#139255 (Remove unused variables generated in merged doctests) - rust-lang#139270 (Add a mailmap entry for myself) - rust-lang#139303 (Put Noratrieb on vacation) - rust-lang#139312 (add Marco Ieni to mailmap) r? `@ghost` `@rustbot` modify labels: rollup
@bors bors merged commit 731ce84 into rust-lang:master Apr 4, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 4, 2025
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
@ShE3py ShE3py deleted the mut-borrow-in-loop branch May 3, 2025 12:17
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` D-papercut Diagnostics: An error or lint that needs small tweaks. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

5 participants