about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-02-08 10:05:28 +0100
committerLukas Wirth <lukastw97@gmail.com>2024-02-08 10:05:28 +0100
commit81ea48a573ea1dfd729a31c35e74c46af2598769 (patch)
tree4546d5ddeae7a2ffc9721c33dfc2717272309175
parentc48f145535db82a166f516847cb1f67d2ade6745 (diff)
downloadrust-81ea48a573ea1dfd729a31c35e74c46af2598769.tar.gz
rust-81ea48a573ea1dfd729a31c35e74c46af2598769.zip
fix: Fix tuple structs not rendering visibility in their fields
-rw-r--r--crates/hir/src/display.rs4
-rw-r--r--crates/ide/src/hover/tests.rs75
2 files changed, 74 insertions, 5 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index 9b99b141fc5..30f402a79f3 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -158,7 +158,8 @@ impl HirDisplay for Adt {
 
 impl HirDisplay for Struct {
     fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
-        write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
+        let module_id = self.module(f.db).id;
+        write_visibility(module_id, self.visibility(f.db), f)?;
         f.write_str("struct ")?;
         write!(f, "{}", self.name(f.db).display(f.db.upcast()))?;
         let def_id = GenericDefId::AdtId(AdtId::StructId(self.id));
@@ -171,6 +172,7 @@ impl HirDisplay for Struct {
 
             while let Some((id, _)) = it.next() {
                 let field = Field { parent: (*self).into(), id };
+                write_visibility(module_id, field.visibility(f.db), f)?;
                 field.ty(f.db).hir_fmt(f)?;
                 if it.peek().is_some() {
                     f.write_str(", ")?;
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 9f4427090e9..78efa9cac86 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -702,7 +702,7 @@ fn hover_shows_struct_field_info() {
     // Hovering over the field when instantiating
     check(
         r#"
-struct Foo { field_a: u32 }
+struct Foo { pub field_a: u32 }
 
 fn main() {
     let foo = Foo { field_a$0: 0, };
@@ -717,7 +717,7 @@ fn main() {
 
             ```rust
              // size = 4, align = 4, offset = 0
-            field_a: u32
+            pub field_a: u32
             ```
         "#]],
     );
@@ -725,7 +725,7 @@ fn main() {
     // Hovering over the field in the definition
     check(
         r#"
-struct Foo { field_a$0: u32 }
+struct Foo { pub field_a$0: u32 }
 
 fn main() {
     let foo = Foo { field_a: 0 };
@@ -740,7 +740,74 @@ fn main() {
 
             ```rust
              // size = 4, align = 4, offset = 0
-            field_a: u32
+            pub field_a: u32
+            ```
+        "#]],
+    );
+}
+
+#[test]
+fn hover_shows_tuple_struct_field_info() {
+    check(
+        r#"
+struct Foo(pub u32)
+
+fn main() {
+    let foo = Foo { 0$0: 0, };
+}
+"#,
+        expect![[r#"
+            *0*
+
+            ```rust
+            test::Foo
+            ```
+
+            ```rust
+             // size = 4, align = 4, offset = 0
+            pub 0: u32
+            ```
+        "#]],
+    );
+    check(
+        r#"
+struct Foo(pub u32)
+
+fn foo(foo: Foo) {
+    foo.0$0;
+}
+"#,
+        expect![[r#"
+            *0*
+
+            ```rust
+            test::Foo
+            ```
+
+            ```rust
+             // size = 4, align = 4, offset = 0
+            pub 0: u32
+            ```
+        "#]],
+    );
+}
+
+#[test]
+fn hover_tuple_struct() {
+    check(
+        r#"
+struct Foo$0(pub u32)
+"#,
+        expect![[r#"
+            *Foo*
+
+            ```rust
+            test
+            ```
+
+            ```rust
+             // size = 4, align = 4
+            struct Foo(pub u32);
             ```
         "#]],
     );