@@ -138,81 +138,11 @@ impl<Cx: PatCx> DeconstructedPat<Cx> {
138138/// This is best effort and not good enough for a `Display` impl.
139139impl < Cx : PatCx > fmt:: Debug for DeconstructedPat < Cx > {
140140 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
141- let pat = self ;
142- let mut first = true ;
143- let mut start_or_continue = |s| {
144- if first {
145- first = false ;
146- ""
147- } else {
148- s
149- }
150- } ;
151- let mut start_or_comma = || start_or_continue ( ", " ) ;
152-
153141 let mut fields: Vec < _ > = ( 0 ..self . arity ) . map ( |_| PatOrWild :: Wild ) . collect ( ) ;
154142 for ipat in self . iter_fields ( ) {
155143 fields[ ipat. idx ] = PatOrWild :: Pat ( & ipat. pat ) ;
156144 }
157-
158- match pat. ctor ( ) {
159- Struct | Variant ( _) | UnionField => {
160- Cx :: write_variant_name ( f, pat) ?;
161- // Without `cx`, we can't know which field corresponds to which, so we can't
162- // get the names of the fields. Instead we just display everything as a tuple
163- // struct, which should be good enough.
164- write ! ( f, "(" ) ?;
165- for p in fields {
166- write ! ( f, "{}" , start_or_comma( ) ) ?;
167- write ! ( f, "{p:?}" ) ?;
168- }
169- write ! ( f, ")" )
170- }
171- // Note: given the expansion of `&str` patterns done in `expand_pattern`, we should
172- // be careful to detect strings here. However a string literal pattern will never
173- // be reported as a non-exhaustiveness witness, so we can ignore this issue.
174- Ref => {
175- write ! ( f, "&{:?}" , & fields[ 0 ] )
176- }
177- Slice ( slice) => {
178- write ! ( f, "[" ) ?;
179- match slice. kind {
180- SliceKind :: FixedLen ( _) => {
181- for p in fields {
182- write ! ( f, "{}{:?}" , start_or_comma( ) , p) ?;
183- }
184- }
185- SliceKind :: VarLen ( prefix_len, _) => {
186- for p in & fields[ ..prefix_len] {
187- write ! ( f, "{}{:?}" , start_or_comma( ) , p) ?;
188- }
189- write ! ( f, "{}" , start_or_comma( ) ) ?;
190- write ! ( f, ".." ) ?;
191- for p in & fields[ prefix_len..] {
192- write ! ( f, "{}{:?}" , start_or_comma( ) , p) ?;
193- }
194- }
195- }
196- write ! ( f, "]" )
197- }
198- Bool ( b) => write ! ( f, "{b}" ) ,
199- // Best-effort, will render signed ranges incorrectly
200- IntRange ( range) => write ! ( f, "{range:?}" ) ,
201- F32Range ( lo, hi, end) => write ! ( f, "{lo}{end}{hi}" ) ,
202- F64Range ( lo, hi, end) => write ! ( f, "{lo}{end}{hi}" ) ,
203- Str ( value) => write ! ( f, "{value:?}" ) ,
204- Opaque ( ..) => write ! ( f, "<constant pattern>" ) ,
205- Or => {
206- for pat in fields {
207- write ! ( f, "{}{:?}" , start_or_continue( " | " ) , pat) ?;
208- }
209- Ok ( ( ) )
210- }
211- Never => write ! ( f, "!" ) ,
212- Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => {
213- write ! ( f, "_ : {:?}" , pat. ty( ) )
214- }
215- }
145+ self . ctor ( ) . fmt_fields ( f, self . ty ( ) , fields. into_iter ( ) )
216146 }
217147}
218148
@@ -295,7 +225,6 @@ impl<'p, Cx: PatCx> fmt::Debug for PatOrWild<'p, Cx> {
295225
296226/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
297227/// purposes. As such they don't use interning and can be cloned.
298- #[ derive( Debug ) ]
299228pub struct WitnessPat < Cx : PatCx > {
300229 ctor : Constructor < Cx > ,
301230 pub ( crate ) fields : Vec < WitnessPat < Cx > > ,
@@ -353,3 +282,10 @@ impl<Cx: PatCx> WitnessPat<Cx> {
353282 self . fields . iter ( )
354283 }
355284}
285+
286+ /// This is best effort and not good enough for a `Display` impl.
287+ impl < Cx : PatCx > fmt:: Debug for WitnessPat < Cx > {
288+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
289+ self . ctor ( ) . fmt_fields ( f, self . ty ( ) , self . fields . iter ( ) )
290+ }
291+ }
0 commit comments