Skip to content

Fixed more &x ->&mut x suggestions#157032

Open
nullie wants to merge 3 commits into
rust-lang:mainfrom
nullie:borrowck-deref-pattern-mut-suggestion-fix
Open

Fixed more &x ->&mut x suggestions#157032
nullie wants to merge 3 commits into
rust-lang:mainfrom
nullie:borrowck-deref-pattern-mut-suggestion-fix

Conversation

@nullie
Copy link
Copy Markdown

@nullie nullie commented May 27, 2026

This PR fixes additional issues related to #148467, i.e. compiler still suggests incorrect fixes for adding mut to deref patterns (needing additional parens) in other bindings besides for loop

fn let_deref(num_ref: &u32) -> u32 {
    let &num = num_ref;

    num *= 2; //~ ERROR cannot assign twice to immutable variable `num`

    num
}

fn deref_inside_pattern(option_num_ref: Option<&u32>) {
    if let Some(&num) = option_num_ref {
        num *= 2; //~ ERROR cannot assign twice to immutable variable `num`

        println!("{num}");
    }
}
...
help: consider making this binding mutable
  |
2 |     let &mut num = num_ref;
  |          +++
...
help: consider making this binding mutable
   |
10 |     if let Some(&mut num) = option_num_ref {
   |                  +++

@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. labels May 27, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 27, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 18 candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants