Skip to content

Commit 3a57f70

Browse files
committed
Correct has_ref detection
1 parent 638cc3e commit 3a57f70

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
@@ -876,7 +876,7 @@ fn path_or_use_tree_qualifier(path: &ast::Path) -> Option<(ast::Path, bool)> {
876876

877877
fn has_ref(token: &SyntaxToken) -> bool {
878878
let mut token = token.clone();
879-
for skip in [WHITESPACE, IDENT, T![mut]] {
879+
for skip in [IDENT, WHITESPACE, T![mut]] {
880880
if token.kind() == skip {
881881
token = match token.prev_token() {
882882
Some(it) => it,
@@ -992,6 +992,20 @@ fn bar(x: &u32) {}
992992
r#"
993993
fn foo() { bar(&mut $0); }
994994
fn bar(x: &mut u32) {}
995+
"#,
996+
expect![[r#"ty: u32, name: x"#]],
997+
);
998+
check_expected_type_and_name(
999+
r#"
1000+
fn foo() { bar(& c$0); }
1001+
fn bar(x: &u32) {}
1002+
"#,
1003+
expect![[r#"ty: u32, name: x"#]],
1004+
);
1005+
check_expected_type_and_name(
1006+
r#"
1007+
fn foo() { bar(&mut c$0); }
1008+
fn bar(x: &mut u32) {}
9951009
"#,
9961010
expect![[r#"ty: u32, name: x"#]],
9971011
);

crates/ide_completion/src/render.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,22 @@ fn main() {
11561156
fn foo(…) []
11571157
"#]],
11581158
);
1159+
check_relevance(
1160+
r#"
1161+
struct S;
1162+
fn foo(s: &mut S) {}
1163+
fn main() {
1164+
let mut ssss = S;
1165+
foo(&mut s$0);
1166+
}
1167+
"#,
1168+
expect![[r#"
1169+
lc ssss [type+local]
1170+
st S []
1171+
fn main() []
1172+
fn foo(…) []
1173+
"#]],
1174+
);
11591175
}
11601176

11611177
#[test]

0 commit comments

Comments
 (0)