diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-10-02 14:19:52 +0200 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2020-10-18 14:21:20 +0100 |
| commit | 3708c86de1a77d47f53fd376659184a64f3ce706 (patch) | |
| tree | 9862d9d5fe98d2dc0096e46611456726189849de | |
| parent | 99852e0db6cdb62894e87eae2a41310b8400a5bf (diff) | |
| download | rust-3708c86de1a77d47f53fd376659184a64f3ce706.tar.gz rust-3708c86de1a77d47f53fd376659184a64f3ce706.zip | |
Treat booleans as integers with valid range 0..=1
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/_match.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/_match.rs b/compiler/rustc_mir_build/src/thir/pattern/_match.rs index d16ba191681..ac5e114d45b 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/_match.rs @@ -1485,9 +1485,7 @@ fn all_constructors<'a, 'tcx>( ) }; match *pcx.ty.kind() { - ty::Bool => { - [true, false].iter().map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b))).collect() - } + ty::Bool => vec![make_range(0, 1)], ty::Array(ref sub_ty, len) if len.try_eval_usize(cx.tcx, cx.param_env).is_some() => { let len = len.eval_usize(cx.tcx, cx.param_env); if len != 0 && cx.is_uninhabited(sub_ty) { @@ -1600,7 +1598,7 @@ impl<'tcx> IntRange<'tcx> { #[inline] fn is_integral(ty: Ty<'_>) -> bool { match ty.kind() { - ty::Char | ty::Int(_) | ty::Uint(_) => true, + ty::Char | ty::Int(_) | ty::Uint(_) | ty::Bool => true, _ => false, } } @@ -1622,6 +1620,7 @@ impl<'tcx> IntRange<'tcx> { #[inline] fn integral_size_and_signed_bias(tcx: TyCtxt<'tcx>, ty: Ty<'_>) -> Option<(Size, u128)> { match *ty.kind() { + ty::Bool => Some((Size::from_bytes(1), 0)), ty::Char => Some((Size::from_bytes(4), 0)), ty::Int(ity) => { let size = Integer::from_attr(&tcx, SignedInt(ity)).size(); |
