]> git.lizzy.rs Git - rust.git/commitdiff
Correct has_ref detection
authorWang Ruochen <wrc@ruo-chen.wang>
Thu, 6 Jan 2022 19:45:09 +0000 (11:45 -0800)
committerWang Ruochen <wrc@ruo-chen.wang>
Thu, 6 Jan 2022 19:46:28 +0000 (11:46 -0800)
crates/ide_completion/src/context.rs
crates/ide_completion/src/render.rs

index c6af285e86c3f3ce3604ef8100d024e030db1269..a21de23d1d7ba9a8b338891677dc8b3168491d41 100644 (file)
@@ -876,7 +876,7 @@ fn path_or_use_tree_qualifier(path: &ast::Path) -> Option<(ast::Path, bool)> {
 
 fn has_ref(token: &SyntaxToken) -> bool {
     let mut token = token.clone();
-    for skip in [WHITESPACE, IDENT, T![mut]] {
+    for skip in [IDENT, WHITESPACE, T![mut]] {
         if token.kind() == skip {
             token = match token.prev_token() {
                 Some(it) => it,
@@ -992,6 +992,20 @@ fn bar(x: &u32) {}
             r#"
 fn foo() { bar(&mut $0); }
 fn bar(x: &mut u32) {}
+"#,
+            expect![[r#"ty: u32, name: x"#]],
+        );
+        check_expected_type_and_name(
+            r#"
+fn foo() { bar(& c$0); }
+fn bar(x: &u32) {}
+        "#,
+            expect![[r#"ty: u32, name: x"#]],
+        );
+        check_expected_type_and_name(
+            r#"
+fn foo() { bar(&mut c$0); }
+fn bar(x: &mut u32) {}
 "#,
             expect![[r#"ty: u32, name: x"#]],
         );
index 4b4fbb3ed9e2c1edd0be296b84a8c4c1ff7ec120..d7184e406eb01c33808f879a6874b8a894dcd734 100644 (file)
@@ -1156,6 +1156,22 @@ fn main() []
                 fn foo(…) []
             "#]],
         );
+        check_relevance(
+            r#"
+struct S;
+fn foo(s: &mut S) {}
+fn main() {
+    let mut ssss = S;
+    foo(&mut s$0);
+}
+            "#,
+            expect![[r#"
+                lc ssss [type+local]
+                st S []
+                fn main() []
+                fn foo(…) []
+            "#]],
+        );
     }
 
     #[test]