@@ -850,103 +850,6 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
850850
851851 Pat { ty : pat. ty ( ) . inner ( ) , span : DUMMY_SP , kind }
852852 }
853-
854- /// Best-effort `Debug` implementation.
855- pub ( crate ) fn debug_pat (
856- f : & mut fmt:: Formatter < ' _ > ,
857- pat : & crate :: pat:: DeconstructedPat < ' _ , Self > ,
858- ) -> fmt:: Result {
859- let mut first = true ;
860- let mut start_or_continue = |s| {
861- if first {
862- first = false ;
863- ""
864- } else {
865- s
866- }
867- } ;
868- let mut start_or_comma = || start_or_continue ( ", " ) ;
869-
870- match pat. ctor ( ) {
871- Struct | Variant ( _) | UnionField => match pat. ty ( ) . kind ( ) {
872- ty:: Adt ( def, _) if def. is_box ( ) => {
873- // Without `box_patterns`, the only legal pattern of type `Box` is `_` (outside
874- // of `std`). So this branch is only reachable when the feature is enabled and
875- // the pattern is a box pattern.
876- let subpattern = pat. iter_fields ( ) . next ( ) . unwrap ( ) ;
877- write ! ( f, "box {subpattern:?}" )
878- }
879- ty:: Adt ( ..) | ty:: Tuple ( ..) => {
880- let variant =
881- match pat. ty ( ) . kind ( ) {
882- ty:: Adt ( adt, _) => Some ( adt. variant (
883- RustcMatchCheckCtxt :: variant_index_for_adt ( pat. ctor ( ) , * adt) ,
884- ) ) ,
885- ty:: Tuple ( _) => None ,
886- _ => unreachable ! ( ) ,
887- } ;
888-
889- if let Some ( variant) = variant {
890- write ! ( f, "{}" , variant. name) ?;
891- }
892-
893- // Without `cx`, we can't know which field corresponds to which, so we can't
894- // get the names of the fields. Instead we just display everything as a tuple
895- // struct, which should be good enough.
896- write ! ( f, "(" ) ?;
897- for p in pat. iter_fields ( ) {
898- write ! ( f, "{}" , start_or_comma( ) ) ?;
899- write ! ( f, "{p:?}" ) ?;
900- }
901- write ! ( f, ")" )
902- }
903- _ => write ! ( f, "_" ) ,
904- } ,
905- // Note: given the expansion of `&str` patterns done in `expand_pattern`, we should
906- // be careful to detect strings here. However a string literal pattern will never
907- // be reported as a non-exhaustiveness witness, so we can ignore this issue.
908- Ref => {
909- let subpattern = pat. iter_fields ( ) . next ( ) . unwrap ( ) ;
910- write ! ( f, "&{:?}" , subpattern)
911- }
912- Slice ( slice) => {
913- let mut subpatterns = pat. iter_fields ( ) ;
914- write ! ( f, "[" ) ?;
915- match slice. kind {
916- SliceKind :: FixedLen ( _) => {
917- for p in subpatterns {
918- write ! ( f, "{}{:?}" , start_or_comma( ) , p) ?;
919- }
920- }
921- SliceKind :: VarLen ( prefix_len, _) => {
922- for p in subpatterns. by_ref ( ) . take ( prefix_len) {
923- write ! ( f, "{}{:?}" , start_or_comma( ) , p) ?;
924- }
925- write ! ( f, "{}" , start_or_comma( ) ) ?;
926- write ! ( f, ".." ) ?;
927- for p in subpatterns {
928- write ! ( f, "{}{:?}" , start_or_comma( ) , p) ?;
929- }
930- }
931- }
932- write ! ( f, "]" )
933- }
934- Bool ( b) => write ! ( f, "{b}" ) ,
935- // Best-effort, will render signed ranges incorrectly
936- IntRange ( range) => write ! ( f, "{range:?}" ) ,
937- F32Range ( lo, hi, end) => write ! ( f, "{lo}{end}{hi}" ) ,
938- F64Range ( lo, hi, end) => write ! ( f, "{lo}{end}{hi}" ) ,
939- Str ( value) => write ! ( f, "{value}" ) ,
940- Opaque ( ..) => write ! ( f, "<constant pattern>" ) ,
941- Or => {
942- for pat in pat. iter_fields ( ) {
943- write ! ( f, "{}{:?}" , start_or_continue( " | " ) , pat) ?;
944- }
945- Ok ( ( ) )
946- }
947- Wildcard | Missing { .. } | NonExhaustive | Hidden => write ! ( f, "_ : {:?}" , pat. ty( ) ) ,
948- }
949- }
950853}
951854
952855impl < ' p , ' tcx > TypeCx for RustcMatchCheckCtxt < ' p , ' tcx > {
@@ -978,12 +881,21 @@ impl<'p, 'tcx> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
978881 self . ctors_for_ty ( * ty)
979882 }
980883
981- fn debug_pat (
884+ fn write_variant_name (
982885 f : & mut fmt:: Formatter < ' _ > ,
983886 pat : & crate :: pat:: DeconstructedPat < ' _ , Self > ,
984887 ) -> fmt:: Result {
985- Self :: debug_pat ( f, pat)
888+ if let ty:: Adt ( adt, _) = pat. ty ( ) . kind ( ) {
889+ if adt. is_box ( ) {
890+ write ! ( f, "Box" ) ?
891+ } else {
892+ let variant = adt. variant ( Self :: variant_index_for_adt ( pat. ctor ( ) , * adt) ) ;
893+ write ! ( f, "{}" , variant. name) ?;
894+ }
895+ }
896+ Ok ( ( ) )
986897 }
898+
987899 fn bug ( & self , fmt : fmt:: Arguments < ' _ > ) -> ! {
988900 span_bug ! ( self . scrut_span, "{}" , fmt)
989901 }
0 commit comments