Skip to content

Commit e0e48ac

Browse files
committed
Treat booleans as integers with valid range 0..=1
1 parent 14a0b10 commit e0e48ac

File tree

1 file changed

+3
-4
lines changed
  • compiler/rustc_mir_build/src/thir/pattern

1 file changed

+3
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,7 @@ fn all_constructors<'a, 'tcx>(
14851485
)
14861486
};
14871487
match *pcx.ty.kind() {
1488-
ty::Bool => {
1489-
[true, false].iter().map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b))).collect()
1490-
}
1488+
ty::Bool => vec![make_range(0, 1)],
14911489
ty::Array(ref sub_ty, len) if len.try_eval_usize(cx.tcx, cx.param_env).is_some() => {
14921490
let len = len.eval_usize(cx.tcx, cx.param_env);
14931491
if len != 0 && cx.is_uninhabited(sub_ty) {
@@ -1600,7 +1598,7 @@ impl<'tcx> IntRange<'tcx> {
16001598
#[inline]
16011599
fn is_integral(ty: Ty<'_>) -> bool {
16021600
match ty.kind() {
1603-
ty::Char | ty::Int(_) | ty::Uint(_) => true,
1601+
ty::Char | ty::Int(_) | ty::Uint(_) | ty::Bool => true,
16041602
_ => false,
16051603
}
16061604
}
@@ -1622,6 +1620,7 @@ impl<'tcx> IntRange<'tcx> {
16221620
#[inline]
16231621
fn integral_size_and_signed_bias(tcx: TyCtxt<'tcx>, ty: Ty<'_>) -> Option<(Size, u128)> {
16241622
match *ty.kind() {
1623+
ty::Bool => Some((Size::from_bytes(1), 0)),
16251624
ty::Char => Some((Size::from_bytes(4), 0)),
16261625
ty::Int(ity) => {
16271626
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();

0 commit comments

Comments
 (0)