@@ -2,7 +2,6 @@ use hir::def::Namespace;
2
2
use hir:: def_id:: DefId ;
3
3
use middle:: region;
4
4
use ty:: subst:: { Kind , Subst , Substs , UnpackedKind } ;
5
- use ty:: { BrAnon , BrEnv , BrFresh , BrNamed } ;
6
5
use ty:: { Bool , Char , Adt } ;
7
6
use ty:: { Error , Str , Array , Slice , Float , FnDef , FnPtr } ;
8
7
use ty:: { Param , Bound , RawPtr , Ref , Never , Tuple } ;
@@ -469,119 +468,34 @@ define_print! {
469
468
}
470
469
}
471
470
472
- define_print ! {
473
- ( ) ty:: BoundRegion , ( self , cx) {
474
- display {
475
- if cx. config. is_verbose {
476
- return self . print_debug( cx) ;
477
- }
478
-
479
- if let BrNamed ( _, name) = * self {
480
- if name != "" && name != "'_" {
481
- p!( write( "{}" , name) ) ;
482
- return Ok ( cx. printer) ;
483
- }
484
- }
485
-
486
- let highlight = cx. printer. region_highlight_mode( ) ;
487
- if let Some ( ( region, counter) ) = highlight. highlight_bound_region {
488
- if * self == region {
489
- p!( write( "'{}" , counter) ) ;
490
- }
491
- }
492
- }
493
- debug {
494
- match * self {
495
- BrAnon ( n) => p!( write( "BrAnon({:?})" , n) ) ,
496
- BrFresh ( n) => p!( write( "BrFresh({:?})" , n) ) ,
497
- BrNamed ( did, name) => {
498
- p!( write( "BrNamed({:?}:{:?}, {})" ,
499
- did. krate, did. index, name) )
500
- }
501
- BrEnv => p!( write( "BrEnv" ) ) ,
502
- }
503
- }
504
- }
505
- }
506
-
507
- // HACK(eddyb) (see `ty::RegionKind::display_outputs_anything`)
508
- //
509
- // NB: this must be kept in sync with the printing logic above.
510
- impl ty:: BoundRegion {
511
- fn display_outputs_anything < P > ( & self , cx : & PrintCx < ' _ , ' _ , ' _ , P > ) -> bool
512
- where P : PrettyPrinter
513
- {
514
- if cx. config . is_verbose {
515
- return true ;
516
- }
517
-
518
- if let BrNamed ( _, name) = * self {
519
- if name != "" && name != "'_" {
520
- return true ;
521
- }
522
- }
523
-
524
- let highlight = cx. printer . region_highlight_mode ( ) ;
525
- if let Some ( ( region, _) ) = highlight. highlight_bound_region {
526
- if * self == region {
527
- return true ;
471
+ impl fmt:: Debug for ty:: BoundRegion {
472
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
473
+ match * self {
474
+ ty:: BrAnon ( n) => write ! ( f, "BrAnon({:?})" , n) ,
475
+ ty:: BrFresh ( n) => write ! ( f, "BrFresh({:?})" , n) ,
476
+ ty:: BrNamed ( did, name) => {
477
+ write ! ( f, "BrNamed({:?}:{:?}, {})" ,
478
+ did. krate, did. index, name)
528
479
}
480
+ ty:: BrEnv => write ! ( f, "BrEnv" ) ,
529
481
}
530
-
531
- false
532
482
}
533
483
}
534
484
535
485
define_print ! {
536
- ( ) ty:: PlaceholderRegion , ( self , cx) {
486
+ ( ) ty:: RegionKind , ( self , cx) {
537
487
display {
538
- if cx. config. is_verbose {
539
- return self . print_debug( cx) ;
540
- }
541
-
488
+ // Watch out for region highlights.
542
489
let highlight = cx. printer. region_highlight_mode( ) ;
543
- if let Some ( counter) = highlight. placeholder_highlight( * self ) {
544
- p!( write( "'{}" , counter) ) ;
545
- } else {
546
- p!( print_display( self . name) ) ;
490
+ if let Some ( n) = highlight. region_highlighted( self ) {
491
+ p!( write( "'{}" , n) ) ;
492
+ return Ok ( cx. printer) ;
547
493
}
548
- }
549
- }
550
- }
551
-
552
- // HACK(eddyb) (see `ty::RegionKind::display_outputs_anything`)
553
- //
554
- // NB: this must be kept in sync with the printing logic above.
555
- impl ty:: PlaceholderRegion {
556
- fn display_outputs_anything < P > ( & self , cx : & PrintCx < ' _ , ' _ , ' _ , P > ) -> bool
557
- where P : PrettyPrinter
558
- {
559
- if cx. config . is_verbose {
560
- return true ;
561
- }
562
-
563
- let highlight = cx. printer . region_highlight_mode ( ) ;
564
- if highlight. placeholder_highlight ( * self ) . is_some ( ) {
565
- return true ;
566
- }
567
494
568
- self . name . display_outputs_anything ( cx)
569
- }
570
- }
571
-
572
- define_print ! {
573
- ( ) ty:: RegionKind , ( self , cx) {
574
- display {
575
495
if cx. config. is_verbose {
576
496
return self . print_debug( cx) ;
577
497
}
578
498
579
- // Watch out for region highlights.
580
- if let Some ( n) = cx. printer. region_highlight_mode( ) . region_highlighted( self ) {
581
- p!( write( "'{}" , n) ) ;
582
- return Ok ( cx. printer) ;
583
- }
584
-
585
499
// These printouts are concise. They do not contain all the information
586
500
// the user might want to diagnose an error, but there is basically no way
587
501
// to fit that into a short string. Hence the recommendation to use
@@ -593,11 +507,20 @@ define_print! {
593
507
}
594
508
}
595
509
ty:: ReLateBound ( _, br) |
596
- ty:: ReFree ( ty:: FreeRegion { bound_region: br, .. } ) => {
597
- p!( print_display( br) )
598
- }
599
- ty:: RePlaceholder ( p) => {
600
- p!( print_display( p) )
510
+ ty:: ReFree ( ty:: FreeRegion { bound_region: br, .. } ) |
511
+ ty:: RePlaceholder ( ty:: Placeholder { name: br, .. } ) => {
512
+ if let ty:: BrNamed ( _, name) = br {
513
+ if name != "" && name != "'_" {
514
+ p!( write( "{}" , name) ) ;
515
+ return Ok ( cx. printer) ;
516
+ }
517
+ }
518
+
519
+ if let Some ( ( region, counter) ) = highlight. highlight_bound_region {
520
+ if br == region {
521
+ p!( write( "'{}" , counter) ) ;
522
+ }
523
+ }
601
524
}
602
525
ty:: ReScope ( scope) if cx. config. identify_regions => {
603
526
match scope. data {
@@ -617,11 +540,9 @@ define_print! {
617
540
}
618
541
}
619
542
ty:: ReVar ( region_vid) if cx. config. identify_regions => {
620
- p!( print_debug( region_vid) )
621
- }
622
- ty:: ReVar ( region_vid) => {
623
- p!( print_display( region_vid) )
543
+ p!( write( "{:?}" , region_vid) ) ;
624
544
}
545
+ ty:: ReVar ( _) => { }
625
546
ty:: ReScope ( _) |
626
547
ty:: ReErased => { }
627
548
ty:: ReStatic => p!( write( "'static" ) ) ,
@@ -640,14 +561,11 @@ define_print! {
640
561
}
641
562
642
563
ty:: ReClosureBound ( ref vid) => {
643
- p!( write( "ReClosureBound({:?})" ,
644
- vid) )
564
+ p!( write( "ReClosureBound({:?})" , vid) )
645
565
}
646
566
647
567
ty:: ReLateBound ( binder_id, ref bound_region) => {
648
- p!( write( "ReLateBound({:?}, " , binder_id) ,
649
- print_debug( bound_region) ,
650
- write( ")" ) )
568
+ p!( write( "ReLateBound({:?}, {:?})" , binder_id, bound_region) )
651
569
}
652
570
653
571
ty:: ReFree ( ref fr) => p!( print_debug( fr) ) ,
@@ -659,11 +577,11 @@ define_print! {
659
577
ty:: ReStatic => p!( write( "ReStatic" ) ) ,
660
578
661
579
ty:: ReVar ( ref vid) => {
662
- p!( print_debug ( vid) )
580
+ p!( write ( "{:?}" , vid) ) ;
663
581
}
664
582
665
583
ty:: RePlaceholder ( placeholder) => {
666
- p!( write( "RePlaceholder(" ) , print_debug ( placeholder) , write ( ")" ) )
584
+ p!( write( "RePlaceholder({:?})" , placeholder) )
667
585
}
668
586
669
587
ty:: ReEmpty => p!( write( "ReEmpty" ) ) ,
@@ -685,11 +603,12 @@ impl ty::RegionKind {
685
603
pub ( crate ) fn display_outputs_anything < P > ( & self , cx : & PrintCx < ' _ , ' _ , ' _ , P > ) -> bool
686
604
where P : PrettyPrinter
687
605
{
688
- if cx. config . is_verbose {
606
+ let highlight = cx. printer . region_highlight_mode ( ) ;
607
+ if highlight. region_highlighted ( self ) . is_some ( ) {
689
608
return true ;
690
609
}
691
610
692
- if cx. printer . region_highlight_mode ( ) . region_highlighted ( self ) . is_some ( ) {
611
+ if cx. config . is_verbose {
693
612
return true ;
694
613
}
695
614
@@ -699,17 +618,27 @@ impl ty::RegionKind {
699
618
}
700
619
701
620
ty:: ReLateBound ( _, br) |
702
- ty:: ReFree ( ty:: FreeRegion { bound_region : br, .. } ) => {
703
- br. display_outputs_anything ( cx)
704
- }
621
+ ty:: ReFree ( ty:: FreeRegion { bound_region : br, .. } ) |
622
+ ty:: RePlaceholder ( ty:: Placeholder { name : br, .. } ) => {
623
+ if let ty:: BrNamed ( _, name) = br {
624
+ if name != "" && name != "'_" {
625
+ return true ;
626
+ }
627
+ }
705
628
706
- ty:: RePlaceholder ( p) => p. display_outputs_anything ( cx) ,
629
+ if let Some ( ( region, _) ) = highlight. highlight_bound_region {
630
+ if br == region {
631
+ return true ;
632
+ }
633
+ }
634
+
635
+ false
636
+ }
707
637
708
638
ty:: ReScope ( _) |
709
639
ty:: ReVar ( _) if cx. config . identify_regions => true ,
710
640
711
- ty:: ReVar ( region_vid) => region_vid. display_outputs_anything ( cx) ,
712
-
641
+ ty:: ReVar ( _) |
713
642
ty:: ReScope ( _) |
714
643
ty:: ReErased => false ,
715
644
@@ -780,48 +709,9 @@ impl fmt::Debug for ty::FloatVid {
780
709
}
781
710
}
782
711
783
- define_print ! {
784
- ( ) ty:: RegionVid , ( self , cx) {
785
- display {
786
- if cx. config. is_verbose {
787
- return self . print_debug( cx) ;
788
- }
789
-
790
- let highlight = cx. printer. region_highlight_mode( ) ;
791
- if let Some ( counter) = highlight. region_highlighted( & ty:: ReVar ( * self ) ) {
792
- p!( write( "'{}" , counter) ) ;
793
- }
794
- }
795
- debug {
796
- // HACK(eddyb) this is duplicated from `display` printing,
797
- // to keep NLL borrowck working even with `-Zverbose`.
798
- let highlight = cx. printer. region_highlight_mode( ) ;
799
- if let Some ( counter) = highlight. region_highlighted( & ty:: ReVar ( * self ) ) {
800
- p!( write( "'{}" , counter) ) ;
801
- } else {
802
- p!( write( "'_#{}r" , self . index( ) ) ) ;
803
- }
804
- }
805
- }
806
- }
807
-
808
- // HACK(eddyb) (see `ty::RegionKind::display_outputs_anything`)
809
- //
810
- // NB: this must be kept in sync with the printing logic above.
811
- impl ty:: RegionVid {
812
- fn display_outputs_anything < P > ( & self , cx : & PrintCx < ' _ , ' _ , ' _ , P > ) -> bool
813
- where P : PrettyPrinter
814
- {
815
- if cx. config . is_verbose {
816
- return true ;
817
- }
818
-
819
- let highlight = cx. printer . region_highlight_mode ( ) ;
820
- if highlight. region_highlighted ( & ty:: ReVar ( * self ) ) . is_some ( ) {
821
- return true ;
822
- }
823
-
824
- false
712
+ impl fmt:: Debug for ty:: RegionVid {
713
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
714
+ write ! ( f, "'_#{}r" , self . index( ) )
825
715
}
826
716
}
827
717
0 commit comments