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:
@@ -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<_> =
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user