Skip to content

Commit 2fb6f5e

Browse files
bors[bot]weirane
andauthored
Merge #11218
11218: fix: Correct has_ref detection, avoiding duplicate &mut insertion on parameter completion r=Veykril a=weirane The original code fails to detect there's a ref in scenarios such as `&mut s` and `& s` because `WHITESPACE` and `IDENT` got reversed. Closes #11199. Co-authored-by: Wang Ruochen <[email protected]>
2 parents 31b41da + 3a57f70 commit 2fb6f5e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

crates/ide_completion/src/context.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ fn path_or_use_tree_qualifier(path: &ast::Path) -> Option<(ast::Path, bool)> {
904904

905905
fn has_ref(token: &SyntaxToken) -> bool {
906906
let mut token = token.clone();
907-
for skip in [WHITESPACE, IDENT, T![mut]] {
907+
for skip in [IDENT, WHITESPACE, T![mut]] {
908908
if token.kind() == skip {
909909
token = match token.prev_token() {
910910
Some(it) => it,
@@ -1020,6 +1020,20 @@ fn bar(x: &u32) {}
10201020
r#"
10211021
fn foo() { bar(&mut $0); }
10221022
fn bar(x: &mut u32) {}
1023+
"#,
1024+
expect![[r#"ty: u32, name: x"#]],
1025+
);
1026+
check_expected_type_and_name(
1027+
r#"
1028+
fn foo() { bar(& c$0); }
1029+
fn bar(x: &u32) {}
1030+
"#,
1031+
expect![[r#"ty: u32, name: x"#]],
1032+
);
1033+
check_expected_type_and_name(
1034+
r#"
1035+
fn foo() { bar(&mut c$0); }
1036+
fn bar(x: &mut u32) {}
10231037
"#,
10241038
expect![[r#"ty: u32, name: x"#]],
10251039
);

crates/ide_completion/src/render.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,22 @@ fn main() {
11511151
fn foo(…) []
11521152
"#]],
11531153
);
1154+
check_relevance(
1155+
r#"
1156+
struct S;
1157+
fn foo(s: &mut S) {}
1158+
fn main() {
1159+
let mut ssss = S;
1160+
foo(&mut s$0);
1161+
}
1162+
"#,
1163+
expect![[r#"
1164+
lc ssss [type+local]
1165+
st S []
1166+
fn main() []
1167+
fn foo(…) []
1168+
"#]],
1169+
);
11541170
}
11551171

11561172
#[test]

0 commit comments

Comments
 (0)