File tree 2 files changed +74
-5
lines changed
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 {
158
158
159
159
impl HirDisplay for Struct {
160
160
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) ?;
162
163
f. write_str ( "struct " ) ?;
163
164
write ! ( f, "{}" , self . name( f. db) . display( f. db. upcast( ) ) ) ?;
164
165
let def_id = GenericDefId :: AdtId ( AdtId :: StructId ( self . id ) ) ;
@@ -171,6 +172,7 @@ impl HirDisplay for Struct {
171
172
172
173
while let Some ( ( id, _) ) = it. next ( ) {
173
174
let field = Field { parent : ( * self ) . into ( ) , id } ;
175
+ write_visibility ( module_id, field. visibility ( f. db ) , f) ?;
174
176
field. ty ( f. db ) . hir_fmt ( f) ?;
175
177
if it. peek ( ) . is_some ( ) {
176
178
f. write_str ( ", " ) ?;
Original file line number Diff line number Diff line change @@ -702,7 +702,7 @@ fn hover_shows_struct_field_info() {
702
702
// Hovering over the field when instantiating
703
703
check (
704
704
r#"
705
- struct Foo { field_a: u32 }
705
+ struct Foo { pub field_a: u32 }
706
706
707
707
fn main() {
708
708
let foo = Foo { field_a$0: 0, };
@@ -717,15 +717,15 @@ fn main() {
717
717
718
718
```rust
719
719
// size = 4, align = 4, offset = 0
720
- field_a: u32
720
+ pub field_a: u32
721
721
```
722
722
"# ] ] ,
723
723
) ;
724
724
725
725
// Hovering over the field in the definition
726
726
check (
727
727
r#"
728
- struct Foo { field_a$0: u32 }
728
+ struct Foo { pub field_a$0: u32 }
729
729
730
730
fn main() {
731
731
let foo = Foo { field_a: 0 };
@@ -740,7 +740,74 @@ fn main() {
740
740
741
741
```rust
742
742
// 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);
744
811
```
745
812
"# ] ] ,
746
813
) ;
You can’t perform that action at this time.
0 commit comments