Skip to content

Commit 4aee3b1

Browse files
committed
matches: Clarify the behavior of exhaustive check
1 parent 5416a71 commit 4aee3b1

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

clippy_lints/src/matches.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,9 @@ fn check_single_match_opt_like(
848848
(&paths::RESULT, "Ok"),
849849
];
850850

851-
// We want to suggest to exclude an arm that contains only wildcards or forms the ehaustive
852-
// match with the second branch.
853-
if !contains_only_wilds(arms[1].pat) && !form_exhaustive_tuples(arms[0].pat, arms[1].pat) {
851+
// We want to suggest to exclude an arm that contains only wildcards or forms the exhaustive
852+
// match with the second branch, without enum variants in matches.
853+
if !contains_only_wilds(arms[1].pat) && !form_exhaustive_matches(arms[0].pat, arms[1].pat) {
854854
return;
855855
}
856856

@@ -907,30 +907,30 @@ fn contains_only_wilds(pat: &Pat<'_>) -> bool {
907907
}
908908
}
909909

910-
/// Returns true if the given patterns form the tuples that exhaustively matches all possible
911-
/// parameters.
910+
/// Returns true if the given patterns forms only exhaustive matches that don't contain enum
911+
/// patterns without a wildcard.
912912
///
913-
/// Here are some examples:
913+
/// For example:
914914
///
915915
/// ```
916-
/// // Doesn't form exhaustive match, because the first arm may contain not only E::V.
916+
/// // Returns false, because the first arm contain enum without a wildcard.
917917
/// match x {
918918
/// (Some(E::V), _) => todo!(),
919919
/// (None, _) => {}
920920
/// }
921921
///
922-
/// // Forms exhaustive match, because the patterns cover all possible cases at the same positions.
922+
/// // Returns true, because the both arms form exhaustive matches and without enum variants.
923923
/// match x {
924924
/// (Some(_), _) => todo!(),
925925
/// (None, _) => {}
926926
/// }
927927
/// ```
928-
fn form_exhaustive_tuples(left: &Pat<'_>, right: &Pat<'_>) -> bool {
928+
fn form_exhaustive_matches(left: &Pat<'_>, right: &Pat<'_>) -> bool {
929929
match (&left.kind, &right.kind) {
930930
(PatKind::Wild, _) | (_, PatKind::Wild) => true,
931931
(PatKind::Tuple(left_in, left_pos), PatKind::Tuple(right_in, right_pos)) => {
932-
// We don't actually know the position and presence of the `..` (dotdot) operator in
933-
// the arms, so we need to evaluate the correct offsets here in order to iterate in
932+
// We don't actually know the position and the presence of the `..` (dotdot) operator
933+
// in the arms, so we need to evaluate the correct offsets here in order to iterate in
934934
// both arms at the same time.
935935
let len = max(
936936
left_in.len() + {

0 commit comments

Comments
 (0)