@@ -904,8 +904,14 @@ fn is_useful<'p, 'tcx>(
904
904
905
905
assert ! ( rows. iter( ) . all( |r| r. len( ) == v. len( ) ) ) ;
906
906
907
+ // FIXME(Nadrieril): Hack to work around type normalization issues (see #72476).
908
+ let ty = matrix. heads ( ) . next ( ) . map ( |r| r. ty ) . unwrap_or ( v. head ( ) . ty ) ;
909
+ let pcx = PatCtxt { cx, matrix, ty, span : v. head ( ) . span , is_top_level } ;
910
+
911
+ debug ! ( "is_useful_expand_first_col: ty={:#?}, expanding {:#?}" , pcx. ty, v. head( ) ) ;
912
+
907
913
// If the first pattern is an or-pattern, expand it.
908
- if let Some ( vs) = v. expand_or_pat ( ) {
914
+ let ret = if let Some ( vs) = v. expand_or_pat ( ) {
909
915
// We expand the or pattern, trying each of its branches in turn and keeping careful track
910
916
// of possible unreachable sub-branches.
911
917
let mut matrix = matrix. clone ( ) ;
@@ -920,30 +926,30 @@ fn is_useful<'p, 'tcx>(
920
926
}
921
927
( u, span)
922
928
} ) ;
923
- return Usefulness :: merge ( usefulnesses, v. len ( ) ) ;
924
- }
925
-
926
- // FIXME(Nadrieril): Hack to work around type normalization issues (see #72476).
927
- let ty = matrix . heads ( ) . next ( ) . map ( |r| r . ty ) . unwrap_or ( v . head ( ) . ty ) ;
928
- let pcx = PatCtxt { cx , matrix , ty , span : v . head ( ) . span , is_top_level } ;
929
-
930
- debug ! ( "is_useful_expand_first_col: ty={:#?}, expanding {:#?}" , pcx. ty , v . head ( ) ) ;
931
-
932
- let ret = v
933
- . head_ctor ( cx )
934
- . split ( pcx, Some ( hir_id ) )
935
- . into_iter ( )
936
- . map ( |ctor| {
937
- // We cache the result of `Fields::wildcards` because it is used a lot.
938
- let ctor_wild_subpatterns = Fields :: wildcards ( pcx , & ctor ) ;
939
- let matrix = pcx . matrix . specialize_constructor ( pcx , & ctor , & ctor_wild_subpatterns ) ;
940
- let v = v . pop_head_constructor ( & ctor_wild_subpatterns ) ;
941
- let usefulness =
942
- is_useful ( pcx. cx , & matrix , & v , witness_preference , hir_id , is_under_guard , false ) ;
943
- usefulness . apply_constructor ( pcx , & ctor , & ctor_wild_subpatterns )
944
- } )
945
- . find ( |result| result . is_useful ( ) )
946
- . unwrap_or ( NotUseful ) ;
929
+ Usefulness :: merge ( usefulnesses, v. len ( ) )
930
+ } else {
931
+ v . head_ctor ( cx )
932
+ . split ( pcx , Some ( hir_id ) )
933
+ . into_iter ( )
934
+ . map ( |ctor| {
935
+ // We cache the result of `Fields::wildcards` because it is used a lot.
936
+ let ctor_wild_subpatterns = Fields :: wildcards ( pcx, & ctor ) ;
937
+ let matrix = pcx . matrix . specialize_constructor ( pcx , & ctor , & ctor_wild_subpatterns ) ;
938
+ let v = v. pop_head_constructor ( & ctor_wild_subpatterns ) ;
939
+ let usefulness = is_useful (
940
+ pcx. cx ,
941
+ & matrix ,
942
+ & v ,
943
+ witness_preference ,
944
+ hir_id ,
945
+ is_under_guard ,
946
+ false ,
947
+ ) ;
948
+ usefulness . apply_constructor ( pcx, & ctor , & ctor_wild_subpatterns )
949
+ } )
950
+ . find ( |result| result . is_useful ( ) )
951
+ . unwrap_or ( NotUseful )
952
+ } ;
947
953
debug ! ( "is_useful::returns({:#?}, {:#?}) = {:?}" , matrix, v, ret) ;
948
954
ret
949
955
}
0 commit comments