Skip to content

Commit 170fae2

Browse files
committed
Log the output of is_useful in the or-pattern case too
1 parent 7009d20 commit 170fae2

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,14 @@ fn is_useful<'p, 'tcx>(
904904

905905
assert!(rows.iter().all(|r| r.len() == v.len()));
906906

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+
907913
// 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() {
909915
// We expand the or pattern, trying each of its branches in turn and keeping careful track
910916
// of possible unreachable sub-branches.
911917
let mut matrix = matrix.clone();
@@ -920,30 +926,30 @@ fn is_useful<'p, 'tcx>(
920926
}
921927
(u, span)
922928
});
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+
};
947953
debug!("is_useful::returns({:#?}, {:#?}) = {:?}", matrix, v, ret);
948954
ret
949955
}

0 commit comments

Comments
 (0)