mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Auto merge of #16378 - roife:fix/issue-15470, r=Veykril
fix: better handling of SelfParam in assist 'inline_call' fix #15470. The current `inline_call` directly translates `&self` into `let ref this = ...;` and `&mut self` into `let ref mut this = ...;`. However, it does not handle some complex scenarios. This PR addresses the following transformations (assuming the receiving object is `obj`): - `self`: `let this = obj` - `mut self`: `let mut this = obj` - `&self`: `let this = &obj` - `&mut self` + If `obj` is `let mut obj = ...`, use a mutable reference: `let this = &mut obj` + If `obj` is `let obj = &mut ...;`, perform a reborrow: `let this = &mut *obj`
This commit is contained in:
commit
f4fec4ff65
2 changed files with 134 additions and 17 deletions
|
@ -595,6 +595,9 @@ pub fn expr_macro_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
|
|||
pub fn expr_ref(expr: ast::Expr, exclusive: bool) -> ast::Expr {
|
||||
expr_from_text(&if exclusive { format!("&mut {expr}") } else { format!("&{expr}") })
|
||||
}
|
||||
pub fn expr_reborrow(expr: ast::Expr) -> ast::Expr {
|
||||
expr_from_text(&format!("&mut *{expr}"))
|
||||
}
|
||||
pub fn expr_closure(pats: impl IntoIterator<Item = ast::Param>, expr: ast::Expr) -> ast::Expr {
|
||||
let params = pats.into_iter().join(", ");
|
||||
expr_from_text(&format!("|{params}| {expr}"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue