Fixed more &x ->&mut x suggestions#157032
Conversation
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
Can you merge the three commits? There is no need for them to be separate, they logically belong together. r=me once that is done.
(For next time: a nice way to do error message PRs is to add/change tests in a first commit, and then make the code changes in a second commit. That way the improvements in the diagnostics are easy to see in the second commit.)
a0f000a to
a5b0416
Compare
a5b0416 to
9bef677
Compare
|
r? @nnethercote regrouped into two commits as you suggested |
|
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
|
@bors r+ rollup |
…suggestion-fix, r=nnethercote Fixed more &x ->&mut x suggestions This PR fixes additional issues related to rust-lang#148467, i.e. compiler still suggests incorrect fixes for adding mut to deref patterns (needing additional parens) in other bindings besides for loop ```rust 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 { | +++ ```
…suggestion-fix, r=nnethercote Fixed more &x ->&mut x suggestions This PR fixes additional issues related to rust-lang#148467, i.e. compiler still suggests incorrect fixes for adding mut to deref patterns (needing additional parens) in other bindings besides for loop ```rust 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 { | +++ ```
…uwer Rollup of 12 pull requests Successful merges: - #154591 (Remove `will_cache_on_disk_for_key_fn`) - #156672 (Misc improvements to coroutine transform code) - #157027 (HIR ty lowering: Move some things into submodules) - #157051 (Allow two object files for a single CGU in CompiledModule) - #157100 (Some more per owner things) - #153497 (Use `trait_object_dummy_self` more & heavily fix+update related docs) - #155638 (Fix tupled closure signature in `AsyncFn` arg mismatch diagnostic) - #156826 (style: Clarify nullary call and `()` no-break rule applies past max width) - #157004 (Remove unused functions in `value_analysis.rs`) - #157032 (Fixed more &x ->&mut x suggestions) - #157033 (Note irrefutable while let in loop type errors) - #157139 (compiler: `ops::RangeInclusive` → `range::RangeInclusive`) Failed merges: - #156875 (Correct and document semantics of `yield` terminator)
Rollup merge of #157032 - nullie:borrowck-deref-pattern-mut-suggestion-fix, r=nnethercote Fixed more &x ->&mut x suggestions 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 ```rust 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 { | +++ ```
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