about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-07-23 18:22:09 +0000
committerGitHub <noreply@github.com>2021-07-23 18:22:09 +0000
commit2e45e47c83e31e1aae0a37acb94ea89f367ffa74 (patch)
treecd68b5296ce39a7e351f26b6d7872eeedccbb4f0
parent661961ca7580f536c14c35950b5fa9fa006e8167 (diff)
parentc495a7374f93a357bd2299d9f1910e9f678dadce (diff)
downloadrust-2e45e47c83e31e1aae0a37acb94ea89f367ffa74.tar.gz
rust-2e45e47c83e31e1aae0a37acb94ea89f367ffa74.zip
Merge #9685
9685: internal: add tests for tuple struct field completion and resolve a FIXME r=jonas-schievink a=jonas-schievink

This removes the last FIXME related to visibility and thus fixes https://github.com/rust-analyzer/rust-analyzer/issues/824

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
-rw-r--r--crates/ide_completion/src/completions/dot.rs38
1 files changed, 36 insertions, 2 deletions
diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs
index 6208b89728d..fc3f9005e70 100644
--- a/crates/ide_completion/src/completions/dot.rs
+++ b/crates/ide_completion/src/completions/dot.rs
@@ -69,7 +69,7 @@ fn complete_fields(
             f(Either::Left(field), ty);
         }
         for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() {
-            // FIXME: Handle visibility
+            // Tuple fields are always public (tuple struct fields are handled above).
             f(Either::Right(i), ty);
         }
     }
@@ -215,6 +215,23 @@ fn foo(a: lib::m::A) { a.$0 }
 
         check(
             r#"
+//- /lib.rs crate:lib new_source_root:library
+pub mod m {
+    pub struct A(
+        i32,
+        pub f64,
+    );
+}
+//- /main.rs crate:main deps:lib new_source_root:local
+fn foo(a: lib::m::A) { a.$0 }
+"#,
+            expect![[r#"
+                fd 1 f64
+            "#]],
+        );
+
+        check(
+            r#"
 //- /lib.rs crate:lib new_source_root:local
 pub struct A {}
 mod m {
@@ -405,7 +422,24 @@ fn foo() {
                 fd 0 i32
                 fd 1 f64
             "#]],
-        )
+        );
+    }
+
+    #[test]
+    fn test_tuple_struct_field_completion() {
+        check(
+            r#"
+struct S(i32, f64);
+fn foo() {
+   let b = S(0, 3.14);
+   b.$0
+}
+"#,
+            expect![[r#"
+                fd 0 i32
+                fd 1 f64
+            "#]],
+        );
     }
 
     #[test]