Skip to content

Commit

Permalink
Properly account for mutable references when postfix-completing consu…
Browse files Browse the repository at this point in the history
…ming completions (e.g. `call`)
  • Loading branch information
ChayimFriedman2 committed Sep 22, 2024
1 parent 814da15 commit 2818d1e
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,10 @@ fn include_references(initial_element: &ast::Expr) -> (ast::Expr, ast::Expr) {
while let Some(parent_ref_element) =
resulting_element.syntax().parent().and_then(ast::RefExpr::cast)
{
let exclusive = parent_ref_element.mut_token().is_some();
resulting_element = ast::Expr::from(parent_ref_element);

new_element_opt = make::expr_ref(new_element_opt, false);
new_element_opt = make::expr_ref(new_element_opt, exclusive);
}
} else {
// If we do not find any ref expressions, restore
Expand Down Expand Up @@ -855,4 +856,23 @@ fn test() {
expect![[r#""#]],
);
}

#[test]
fn mut_ref_consuming() {
check_edit(
"call",
r#"
fn main() {
let mut x = &mut 2;
&mut x.$0;
}
"#,
r#"
fn main() {
let mut x = &mut 2;
${1}(&mut x);
}
"#,
);
}
}

0 comments on commit 2818d1e

Please sign in to comment.