@@ -2,14 +2,14 @@ use std::iter::ExactSizeIterator;
22use std:: ops:: Deref ;
33
44use 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 } ;
66
7- use crate :: comment:: { combine_strs_with_missing_comments, contains_comment} ;
87use crate :: config:: lists:: * ;
98use crate :: config:: { IndentStyle , TypeDensity , Version } ;
109use crate :: expr:: {
1110 format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType ,
1211} ;
12+ use crate :: items:: StructParts ;
1313use crate :: lists:: {
1414 definitive_tactic, itemize_list, write_list, ListFormatting , ListItem , Separator ,
1515} ;
@@ -24,6 +24,11 @@ use crate::utils::{
2424 colon_spaces, extra_offset, first_line_width, format_extern, format_mutability,
2525 last_line_extendable, last_line_width, mk_sp, rewrite_ident,
2626} ;
27+ use crate :: DEFAULT_VISIBILITY ;
28+ use crate :: {
29+ comment:: { combine_strs_with_missing_comments, contains_comment} ,
30+ items:: format_struct_struct,
31+ } ;
2732
2833#[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
2934pub ( crate ) enum PathContext {
@@ -764,6 +769,54 @@ impl Rewrite for ast::Ty {
764769 ast:: TyKind :: Tup ( ref items) => {
765770 rewrite_tuple ( context, items. iter ( ) , self . span , shape, items. len ( ) == 1 )
766771 }
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+ }
767820 ast:: TyKind :: Path ( ref q_self, ref path) => {
768821 rewrite_path ( context, PathContext :: Type , q_self. as_ref ( ) , path, shape)
769822 }
0 commit comments