@@ -10,6 +10,8 @@ use rustc_index::vec::IndexVec;
10
10
use rustc_span:: { Span , Symbol } ;
11
11
use rustc_target:: abi:: VariantIdx ;
12
12
use smallvec:: SmallVec ;
13
+ use std:: cell:: Cell ;
14
+ use std:: fmt:: { self , Debug } ;
13
15
14
16
use super :: { Field , SourceInfo } ;
15
17
@@ -58,7 +60,7 @@ rustc_index::newtype_index! {
58
60
}
59
61
60
62
/// The layout of generator state.
61
- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , HashStable , TypeFoldable ) ]
63
+ #[ derive( Clone , RustcEncodable , RustcDecodable , HashStable , TypeFoldable ) ]
62
64
pub struct GeneratorLayout < ' tcx > {
63
65
/// The type of every local stored inside the generator.
64
66
pub field_tys : IndexVec < GeneratorSavedLocal , Ty < ' tcx > > ,
@@ -77,6 +79,62 @@ pub struct GeneratorLayout<'tcx> {
77
79
pub storage_conflicts : BitMatrix < GeneratorSavedLocal , GeneratorSavedLocal > ,
78
80
}
79
81
82
+ impl Debug for GeneratorLayout < ' _ > {
83
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
84
+ /// Prints an iterator of (key, value) tuples as a map.
85
+ struct MapPrinter < ' a , K , V > ( Cell < Option < Box < dyn Iterator < Item = ( K , V ) > + ' a > > > ) ;
86
+ impl < ' a , K , V > MapPrinter < ' a , K , V > {
87
+ fn new ( iter : impl Iterator < Item = ( K , V ) > + ' a ) -> Self {
88
+ Self ( Cell :: new ( Some ( Box :: new ( iter) ) ) )
89
+ }
90
+ }
91
+ impl < ' a , K : Debug , V : Debug > Debug for MapPrinter < ' a , K , V > {
92
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
93
+ fmt. debug_map ( ) . entries ( self . 0 . take ( ) . unwrap ( ) ) . finish ( )
94
+ }
95
+ }
96
+
97
+ /// Prints the generator variant name.
98
+ struct GenVariantPrinter ( VariantIdx ) ;
99
+ impl From < VariantIdx > for GenVariantPrinter {
100
+ fn from ( idx : VariantIdx ) -> Self {
101
+ GenVariantPrinter ( idx)
102
+ }
103
+ }
104
+ impl Debug for GenVariantPrinter {
105
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
106
+ let variant_name = ty:: GeneratorSubsts :: variant_name ( self . 0 ) ;
107
+ if fmt. alternate ( ) {
108
+ write ! ( fmt, "{:9}({:?})" , variant_name, self . 0 )
109
+ } else {
110
+ write ! ( fmt, "{}" , variant_name)
111
+ }
112
+ }
113
+ }
114
+
115
+ /// Forces its contents to print in regular mode instead of alternate mode.
116
+ struct OneLinePrinter < T > ( T ) ;
117
+ impl < T : Debug > Debug for OneLinePrinter < T > {
118
+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
119
+ write ! ( fmt, "{:?}" , self . 0 )
120
+ }
121
+ }
122
+
123
+ fmt. debug_struct ( "GeneratorLayout" )
124
+ . field ( "field_tys" , & MapPrinter :: new ( self . field_tys . iter_enumerated ( ) ) )
125
+ . field (
126
+ "variant_fields" ,
127
+ & MapPrinter :: new (
128
+ self . variant_fields
129
+ . iter_enumerated ( )
130
+ . map ( |( k, v) | ( GenVariantPrinter ( k) , OneLinePrinter ( v) ) ) ,
131
+ ) ,
132
+ )
133
+ . field ( "storage_conflicts" , & self . storage_conflicts )
134
+ . finish ( )
135
+ }
136
+ }
137
+
80
138
#[ derive( Debug , RustcEncodable , RustcDecodable , HashStable ) ]
81
139
pub struct BorrowCheckResult < ' tcx > {
82
140
/// All the opaque types that are restricted to concrete types
0 commit comments