Skip to content

Commit 2818d1e

Browse files
Properly account for mutable references when postfix-completing consuming completions (e.g. call)
1 parent 814da15 commit 2818d1e

File tree

1 file changed

+21
-1
lines changed
  • src/tools/rust-analyzer/crates/ide-completion/src/completions

1 file changed

+21
-1
lines changed

src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ fn include_references(initial_element: &ast::Expr) -> (ast::Expr, ast::Expr) {
302302
while let Some(parent_ref_element) =
303303
resulting_element.syntax().parent().and_then(ast::RefExpr::cast)
304304
{
305+
let exclusive = parent_ref_element.mut_token().is_some();
305306
resulting_element = ast::Expr::from(parent_ref_element);
306307

307-
new_element_opt = make::expr_ref(new_element_opt, false);
308+
new_element_opt = make::expr_ref(new_element_opt, exclusive);
308309
}
309310
} else {
310311
// If we do not find any ref expressions, restore
@@ -855,4 +856,23 @@ fn test() {
855856
expect![[r#""#]],
856857
);
857858
}
859+
860+
#[test]
861+
fn mut_ref_consuming() {
862+
check_edit(
863+
"call",
864+
r#"
865+
fn main() {
866+
let mut x = &mut 2;
867+
&mut x.$0;
868+
}
869+
"#,
870+
r#"
871+
fn main() {
872+
let mut x = &mut 2;
873+
${1}(&mut x);
874+
}
875+
"#,
876+
);
877+
}
858878
}

0 commit comments

Comments
 (0)