rust/compiler/rustc_borrowck/src/diagnostics
Matthias Krüger 21e7463bf8
Rollup merge of #112019 - jieyouxu:issue-111554, r=compiler-errors
Don't suggest changing `&self` and `&mut self` in function signature to be mutable when taking `&mut self` in closure

Current suggestion for when taking a mutable reference to `self` in a closure (as an upvar) will produce a machine-applicable suggestion to change the `self` in the function signature to `mut self`, but does not account for the specialness of implicit self in that it can already have `&` and `&mut` (see #111554). This causes the function signature to become `test(&mut mut self)` which does not seem desirable.

```
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
   --> src/sound_player.rs:870:11
    |
869 |     pub fn test(&mut self) {
    |                      ---- help: consider changing this to be mutable: `mut self`
870 |     || test2(&mut self);
    |              ^^^^^^^^^ cannot borrow as mutable
```

This PR suppresses the "changing this to be mutable" suggestion if the implicit self is either `ImplicitSelfKind::ImmRef` or `ImplicitSelfKind::MutRef`.

Fixes #111554.
2023-06-06 12:00:33 +02:00
..
bound_region_errors.rs Rename tcx.mk_re_* => Region::new_* 2023-05-29 17:54:53 +00:00
conflict_errors.rs Remove DesugaringKind::Replace. 2023-05-25 17:40:46 +00:00
explain_borrow.rs Use is_some_and/is_ok_and in less obvious spots 2023-05-24 14:33:43 +00:00
find_all_local_uses.rs rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
find_use.rs Remove ToRegionVid. 2023-04-13 12:20:41 +10:00
mod.rs Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
move_errors.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
mutability_errors.rs Don't suggest changing {ImmRef,MutRef} implicit self to be mutable 2023-05-29 13:11:03 +08:00
outlives_suggestion.rs Use is_some_and/is_ok_and in less obvious spots 2023-05-24 14:33:43 +00:00
region_errors.rs Rollup merge of #110827 - compiler-errors:issue-110761-followup, r=cjgillot 2023-05-08 11:39:20 +05:30
region_name.rs Restrict From<S> for {D,Subd}iagnosticMessage. 2023-05-03 08:44:39 +10:00
var_name.rs Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00