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.
This commit is contained in:
Chayim Refael Friedman
2025-07-28 00:01:28 +03:00
parent 4b596bbd84
commit 6bf3cbe39e
6 changed files with 15 additions and 12 deletions

View File

@@ -1130,16 +1130,16 @@ impl<Cx: PatCx> ConstructorSet<Cx> {
seen_false = true;
}
}
if seen_false {
present.push(Bool(false));
} else {
missing.push(Bool(false));
}
if seen_true {
present.push(Bool(true));
} else {
missing.push(Bool(true));
}
if seen_false {
present.push(Bool(false));
} else {
missing.push(Bool(false));
}
}
ConstructorSet::Integers { range_1, range_2 } => {
let seen_ranges: Vec<_> =

View File

@@ -176,6 +176,9 @@ fn test_witnesses() {
),
vec!["Enum::Variant1(_)", "Enum::Variant2(_)", "_"],
);
// Assert we put `true` before `false`.
assert_witnesses(AllOfThem, Ty::Bool, Vec::new(), vec!["true", "false"]);
}
#[test]