File tree Expand file tree Collapse file tree 2 files changed +74
-5
lines changed Expand file tree Collapse file tree 2 files changed +74
-5
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,8 @@ impl HirDisplay for Adt {
158158
159159impl HirDisplay for Struct {
160160 fn hir_fmt ( & self , f : & mut HirFormatter < ' _ > ) -> Result < ( ) , HirDisplayError > {
161- write_visibility ( self . module ( f. db ) . id , self . visibility ( f. db ) , f) ?;
161+ let module_id = self . module ( f. db ) . id ;
162+ write_visibility ( module_id, self . visibility ( f. db ) , f) ?;
162163 f. write_str ( "struct " ) ?;
163164 write ! ( f, "{}" , self . name( f. db) . display( f. db. upcast( ) ) ) ?;
164165 let def_id = GenericDefId :: AdtId ( AdtId :: StructId ( self . id ) ) ;
@@ -171,6 +172,7 @@ impl HirDisplay for Struct {
171172
172173 while let Some ( ( id, _) ) = it. next ( ) {
173174 let field = Field { parent : ( * self ) . into ( ) , id } ;
175+ write_visibility ( module_id, field. visibility ( f. db ) , f) ?;
174176 field. ty ( f. db ) . hir_fmt ( f) ?;
175177 if it. peek ( ) . is_some ( ) {
176178 f. write_str ( ", " ) ?;
Original file line number Diff line number Diff line change @@ -702,7 +702,7 @@ fn hover_shows_struct_field_info() {
702702 // Hovering over the field when instantiating
703703 check (
704704 r#"
705- struct Foo { field_a: u32 }
705+ struct Foo { pub field_a: u32 }
706706
707707fn main() {
708708 let foo = Foo { field_a$0: 0, };
@@ -717,15 +717,15 @@ fn main() {
717717
718718 ```rust
719719 // size = 4, align = 4, offset = 0
720- field_a: u32
720+ pub field_a: u32
721721 ```
722722 "# ] ] ,
723723 ) ;
724724
725725 // Hovering over the field in the definition
726726 check (
727727 r#"
728- struct Foo { field_a$0: u32 }
728+ struct Foo { pub field_a$0: u32 }
729729
730730fn main() {
731731 let foo = Foo { field_a: 0 };
@@ -740,7 +740,74 @@ fn main() {
740740
741741 ```rust
742742 // size = 4, align = 4, offset = 0
743- field_a: u32
743+ pub field_a: u32
744+ ```
745+ "# ] ] ,
746+ ) ;
747+ }
748+
749+ #[ test]
750+ fn hover_shows_tuple_struct_field_info ( ) {
751+ check (
752+ r#"
753+ struct Foo(pub u32)
754+
755+ fn main() {
756+ let foo = Foo { 0$0: 0, };
757+ }
758+ "# ,
759+ expect ! [ [ r#"
760+ *0*
761+
762+ ```rust
763+ test::Foo
764+ ```
765+
766+ ```rust
767+ // size = 4, align = 4, offset = 0
768+ pub 0: u32
769+ ```
770+ "# ] ] ,
771+ ) ;
772+ check (
773+ r#"
774+ struct Foo(pub u32)
775+
776+ fn foo(foo: Foo) {
777+ foo.0$0;
778+ }
779+ "# ,
780+ expect ! [ [ r#"
781+ *0*
782+
783+ ```rust
784+ test::Foo
785+ ```
786+
787+ ```rust
788+ // size = 4, align = 4, offset = 0
789+ pub 0: u32
790+ ```
791+ "# ] ] ,
792+ ) ;
793+ }
794+
795+ #[ test]
796+ fn hover_tuple_struct ( ) {
797+ check (
798+ r#"
799+ struct Foo$0(pub u32)
800+ "# ,
801+ expect ! [ [ r#"
802+ *Foo*
803+
804+ ```rust
805+ test
806+ ```
807+
808+ ```rust
809+ // size = 4, align = 4
810+ struct Foo(pub u32);
744811 ```
745812 "# ] ] ,
746813 ) ;
You can’t perform that action at this time.
0 commit comments