@@ -450,6 +450,24 @@ impl<'a> State<'a> {
450450 self . s . word ( ";" )
451451 }
452452
453+ fn print_item_type (
454+ & mut self ,
455+ item : & hir:: Item ,
456+ generics : & hir:: Generics ,
457+ inner : impl Fn ( & mut Self ) ,
458+ ) {
459+ self . head ( visibility_qualified ( & item. vis , "type" ) ) ;
460+ self . print_ident ( item. ident ) ;
461+ self . print_generic_params ( & generics. params ) ;
462+ self . end ( ) ; // end the inner ibox
463+
464+ self . print_where_clause ( & generics. where_clause ) ;
465+ self . s . space ( ) ;
466+ inner ( self ) ;
467+ self . s . word ( ";" ) ;
468+ self . end ( ) ; // end the outer ibox
469+ }
470+
453471 /// Pretty-print an item
454472 pub fn print_item ( & mut self , item : & hir:: Item ) {
455473 self . hardbreak_if_not_bol ( ) ;
@@ -553,43 +571,28 @@ impl<'a> State<'a> {
553571 self . end ( )
554572 }
555573 hir:: ItemKind :: Ty ( ref ty, ref generics) => {
556- self . head ( visibility_qualified ( & item. vis , "type" ) ) ;
557- self . print_ident ( item. ident ) ;
558- self . print_generic_params ( & generics. params ) ;
559- self . end ( ) ; // end the inner ibox
560-
561- self . print_where_clause ( & generics. where_clause ) ;
562- self . s . space ( ) ;
563- self . word_space ( "=" ) ;
564- self . print_type ( & ty) ;
565- self . s . word ( ";" ) ;
566- self . end ( ) ; // end the outer ibox
574+ self . print_item_type ( item, & generics, |state| {
575+ state. word_space ( "=" ) ;
576+ state. print_type ( & ty) ;
577+ } ) ;
567578 }
568579 hir:: ItemKind :: OpaqueTy ( ref opaque_ty) => {
569- self . head ( visibility_qualified ( & item. vis , "type" ) ) ;
570- self . print_ident ( item. ident ) ;
571- self . print_generic_params ( & opaque_ty. generics . params ) ;
572- let mut real_bounds = Vec :: with_capacity ( opaque_ty. bounds . len ( ) ) ;
573- for b in opaque_ty. bounds . iter ( ) {
574- if let GenericBound :: Trait ( ref ptr, hir:: TraitBoundModifier :: Maybe ) = * b {
575- self . s . space ( ) ;
576- self . word_space ( "for ?" ) ;
577- self . print_trait_ref ( & ptr. trait_ref ) ;
578- } else {
579- real_bounds. push ( b) ;
580+ self . print_item_type ( item, & opaque_ty. generics , |state| {
581+ let mut real_bounds = Vec :: with_capacity ( opaque_ty. bounds . len ( ) ) ;
582+ for b in opaque_ty. bounds . iter ( ) {
583+ if let GenericBound :: Trait ( ref ptr, hir:: TraitBoundModifier :: Maybe ) = * b {
584+ state. s . space ( ) ;
585+ state. word_space ( "for ?" ) ;
586+ state. print_trait_ref ( & ptr. trait_ref ) ;
587+ } else {
588+ real_bounds. push ( b) ;
589+ }
580590 }
581- }
582- self . print_bounds ( " = impl" , real_bounds) ;
583-
584- self . end ( ) ; // end the inner ibox
585-
586- self . print_where_clause ( & opaque_ty. generics . where_clause ) ;
587- self . s . word ( ";" ) ;
588- self . end ( ) ; // end the outer ibox
591+ state. print_bounds ( "= impl" , real_bounds) ;
592+ } ) ;
589593 }
590594 hir:: ItemKind :: Enum ( ref enum_definition, ref params) => {
591- self . print_enum_def ( enum_definition, params, item. ident . name , item. span ,
592- & item. vis ) ;
595+ self . print_enum_def ( enum_definition, params, item. ident . name , item. span , & item. vis ) ;
593596 }
594597 hir:: ItemKind :: Struct ( ref struct_def, ref generics) => {
595598 self . head ( visibility_qualified ( & item. vis , "struct" ) ) ;
0 commit comments