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