Skip to content

Commit 6a622ba

Browse files
In rustc_pattern_analysis, put true witnesses before false witnesses
In rustc it doesn't really matter what the order of the witnesses is, but I'm planning to use the witnesses for implementing the "add missing match arms" assist in rust-analyzer, and there `true` before `false` is the natural order (like `Some` before `None`), and also what the current assist does. The current order doesn't seem to be intentional; the code was created when bool ctors became their own thing, not just int ctors, but for integer, 0 before 1 is indeed the natural order.
1 parent 4b596bb commit 6a622ba

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,16 +1130,16 @@ impl<Cx: PatCx> ConstructorSet<Cx> {
11301130
seen_false = true;
11311131
}
11321132
}
1133-
if seen_false {
1134-
present.push(Bool(false));
1135-
} else {
1136-
missing.push(Bool(false));
1137-
}
11381133
if seen_true {
11391134
present.push(Bool(true));
11401135
} else {
11411136
missing.push(Bool(true));
11421137
}
1138+
if seen_false {
1139+
present.push(Bool(false));
1140+
} else {
1141+
missing.push(Bool(false));
1142+
}
11431143
}
11441144
ConstructorSet::Integers { range_1, range_2 } => {
11451145
let seen_ranges: Vec<_> =

compiler/rustc_pattern_analysis/tests/exhaustiveness.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ fn test_witnesses() {
176176
),
177177
vec!["Enum::Variant1(_)", "Enum::Variant2(_)", "_"],
178178
);
179+
180+
// Assert we put `true` before `false`.
181+
assert_witnesses(AllOfThem, Ty::Bool, Vec::new(), vec!["true", "false"]);
179182
}
180183

181184
#[test]

0 commit comments

Comments
 (0)