@@ -2,14 +2,14 @@ use std::iter::ExactSizeIterator;
2
2
use std:: ops:: Deref ;
3
3
4
4
use rustc_ast:: ast:: { self , FnRetTy , Mutability } ;
5
- use rustc_span:: { symbol:: kw, BytePos , Pos , Span } ;
5
+ use rustc_span:: { symbol:: kw, symbol :: Ident , BytePos , Pos , Span } ;
6
6
7
- use crate :: comment:: { combine_strs_with_missing_comments, contains_comment} ;
8
7
use crate :: config:: lists:: * ;
9
8
use crate :: config:: { IndentStyle , TypeDensity , Version } ;
10
9
use crate :: expr:: {
11
10
format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType ,
12
11
} ;
12
+ use crate :: items:: StructParts ;
13
13
use crate :: lists:: {
14
14
definitive_tactic, itemize_list, write_list, ListFormatting , ListItem , Separator ,
15
15
} ;
@@ -24,6 +24,11 @@ use crate::utils::{
24
24
colon_spaces, extra_offset, first_line_width, format_extern, format_mutability,
25
25
last_line_extendable, last_line_width, mk_sp, rewrite_ident,
26
26
} ;
27
+ use crate :: DEFAULT_VISIBILITY ;
28
+ use crate :: {
29
+ comment:: { combine_strs_with_missing_comments, contains_comment} ,
30
+ items:: format_struct_struct,
31
+ } ;
27
32
28
33
#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
29
34
pub ( crate ) enum PathContext {
@@ -764,6 +769,54 @@ impl Rewrite for ast::Ty {
764
769
ast:: TyKind :: Tup ( ref items) => {
765
770
rewrite_tuple ( context, items. iter ( ) , self . span , shape, items. len ( ) == 1 )
766
771
}
772
+ ast:: TyKind :: AnonymousStruct ( ref fields, recovered) => {
773
+ let ident = Ident :: new (
774
+ kw:: Struct ,
775
+ mk_sp ( self . span . lo ( ) , self . span . lo ( ) + BytePos ( 6 ) ) ,
776
+ ) ;
777
+ let data = ast:: VariantData :: Struct ( fields. clone ( ) , recovered) ;
778
+ let variant = ast:: Variant {
779
+ attrs : vec ! [ ] ,
780
+ id : self . id ,
781
+ span : self . span ,
782
+ vis : DEFAULT_VISIBILITY ,
783
+ ident,
784
+ data,
785
+ disr_expr : None ,
786
+ is_placeholder : false ,
787
+ } ;
788
+ format_struct_struct (
789
+ & context,
790
+ & StructParts :: from_variant ( & variant) ,
791
+ fields,
792
+ shape. indent ,
793
+ None ,
794
+ )
795
+ }
796
+ ast:: TyKind :: AnonymousUnion ( ref fields, recovered) => {
797
+ let ident = Ident :: new (
798
+ kw:: Union ,
799
+ mk_sp ( self . span . lo ( ) , self . span . lo ( ) + BytePos ( 5 ) ) ,
800
+ ) ;
801
+ let data = ast:: VariantData :: Struct ( fields. clone ( ) , recovered) ;
802
+ let variant = ast:: Variant {
803
+ attrs : vec ! [ ] ,
804
+ id : self . id ,
805
+ span : self . span ,
806
+ vis : DEFAULT_VISIBILITY ,
807
+ ident,
808
+ data,
809
+ disr_expr : None ,
810
+ is_placeholder : false ,
811
+ } ;
812
+ format_struct_struct (
813
+ & context,
814
+ & StructParts :: from_variant ( & variant) ,
815
+ fields,
816
+ shape. indent ,
817
+ None ,
818
+ )
819
+ }
767
820
ast:: TyKind :: Path ( ref q_self, ref path) => {
768
821
rewrite_path ( context, PathContext :: Type , q_self. as_ref ( ) , path, shape)
769
822
}
0 commit comments