@@ -375,7 +375,8 @@ impl<'a> State<'a> {
375
375
pub fn print_foreign_item ( & mut self , item : & hir:: ForeignItem < ' _ > ) {
376
376
self . hardbreak_if_not_bol ( ) ;
377
377
self . maybe_print_comment ( item. span . lo ( ) ) ;
378
- self . print_outer_attributes ( self . attrs ( item. hir_id ( ) ) ) ;
378
+ let attrs = self . attrs ( item. hir_id ( ) ) ;
379
+ self . print_outer_attributes ( attrs) ;
379
380
match item. kind {
380
381
hir:: ForeignItemKind :: Fn ( decl, arg_names, generics) => {
381
382
self . head ( "" ) ;
@@ -415,6 +416,7 @@ impl<'a> State<'a> {
415
416
self . end ( ) ; // end the head-ibox
416
417
self . end ( ) // end the outer cbox
417
418
}
419
+ hir:: ForeignItemKind :: Impl ( impl_) => self . print_impl ( impl_, attrs, item. span ) ,
418
420
}
419
421
}
420
422
@@ -477,6 +479,48 @@ impl<'a> State<'a> {
477
479
self . end ( ) ; // end the outer ibox
478
480
}
479
481
482
+ fn print_impl (
483
+ & mut self ,
484
+ impl_ : & hir:: Impl < ' _ > ,
485
+ attrs : & [ ast:: Attribute ] ,
486
+ span : rustc_span:: Span ,
487
+ ) {
488
+ self . head ( "" ) ;
489
+ self . print_defaultness ( impl_. defaultness ) ;
490
+ self . print_unsafety ( impl_. unsafety ) ;
491
+ self . word_nbsp ( "impl" ) ;
492
+
493
+ if !impl_. generics . params . is_empty ( ) {
494
+ self . print_generic_params ( impl_. generics . params ) ;
495
+ self . space ( ) ;
496
+ }
497
+
498
+ if impl_. constness == hir:: Constness :: Const {
499
+ self . word_nbsp ( "const" ) ;
500
+ }
501
+
502
+ if let hir:: ImplPolarity :: Negative ( _) = impl_. polarity {
503
+ self . word ( "!" ) ;
504
+ }
505
+
506
+ if let Some ( ref t) = impl_. of_trait {
507
+ self . print_trait_ref ( t) ;
508
+ self . space ( ) ;
509
+ self . word_space ( "for" ) ;
510
+ }
511
+
512
+ self . print_type ( impl_. self_ty ) ;
513
+ self . print_where_clause ( impl_. generics ) ;
514
+
515
+ self . space ( ) ;
516
+ self . bopen ( ) ;
517
+ self . print_inner_attributes ( attrs) ;
518
+ for impl_item in impl_. items {
519
+ self . ann . nested ( self , Nested :: ImplItem ( impl_item. id ) ) ;
520
+ }
521
+ self . bclose ( span) ;
522
+ }
523
+
480
524
/// Pretty-print an item
481
525
pub fn print_item ( & mut self , item : & hir:: Item < ' _ > ) {
482
526
self . hardbreak_if_not_bol ( ) ;
@@ -619,52 +663,7 @@ impl<'a> State<'a> {
619
663
self . head ( "union" ) ;
620
664
self . print_struct ( struct_def, generics, item. ident . name , item. span , true ) ;
621
665
}
622
- hir:: ItemKind :: Impl ( & hir:: Impl {
623
- unsafety,
624
- polarity,
625
- defaultness,
626
- constness,
627
- defaultness_span : _,
628
- generics,
629
- ref of_trait,
630
- self_ty,
631
- items,
632
- } ) => {
633
- self . head ( "" ) ;
634
- self . print_defaultness ( defaultness) ;
635
- self . print_unsafety ( unsafety) ;
636
- self . word_nbsp ( "impl" ) ;
637
-
638
- if !generics. params . is_empty ( ) {
639
- self . print_generic_params ( generics. params ) ;
640
- self . space ( ) ;
641
- }
642
-
643
- if constness == hir:: Constness :: Const {
644
- self . word_nbsp ( "const" ) ;
645
- }
646
-
647
- if let hir:: ImplPolarity :: Negative ( _) = polarity {
648
- self . word ( "!" ) ;
649
- }
650
-
651
- if let Some ( t) = of_trait {
652
- self . print_trait_ref ( t) ;
653
- self . space ( ) ;
654
- self . word_space ( "for" ) ;
655
- }
656
-
657
- self . print_type ( self_ty) ;
658
- self . print_where_clause ( generics) ;
659
-
660
- self . space ( ) ;
661
- self . bopen ( ) ;
662
- self . print_inner_attributes ( attrs) ;
663
- for impl_item in items {
664
- self . ann . nested ( self , Nested :: ImplItem ( impl_item. id ) ) ;
665
- }
666
- self . bclose ( item. span ) ;
667
- }
666
+ hir:: ItemKind :: Impl ( impl_) => self . print_impl ( impl_, attrs, item. span ) ,
668
667
hir:: ItemKind :: Trait ( is_auto, unsafety, generics, bounds, trait_items) => {
669
668
self . head ( "" ) ;
670
669
self . print_is_auto ( is_auto) ;
0 commit comments