Treat booleans as integers with valid range 0..=1
This commit is contained in:
parent
99852e0db6
commit
3708c86de1
1 changed files with 3 additions and 4 deletions
|
@ -1485,9 +1485,7 @@ fn all_constructors<'a, 'tcx>(
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
match *pcx.ty.kind() {
|
match *pcx.ty.kind() {
|
||||||
ty::Bool => {
|
ty::Bool => vec![make_range(0, 1)],
|
||||||
[true, false].iter().map(|&b| ConstantValue(ty::Const::from_bool(cx.tcx, b))).collect()
|
|
||||||
}
|
|
||||||
ty::Array(ref sub_ty, len) if len.try_eval_usize(cx.tcx, cx.param_env).is_some() => {
|
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);
|
let len = len.eval_usize(cx.tcx, cx.param_env);
|
||||||
if len != 0 && cx.is_uninhabited(sub_ty) {
|
if len != 0 && cx.is_uninhabited(sub_ty) {
|
||||||
|
@ -1600,7 +1598,7 @@ impl<'tcx> IntRange<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_integral(ty: Ty<'_>) -> bool {
|
fn is_integral(ty: Ty<'_>) -> bool {
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Char | ty::Int(_) | ty::Uint(_) => true,
|
ty::Char | ty::Int(_) | ty::Uint(_) | ty::Bool => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1622,6 +1620,7 @@ impl<'tcx> IntRange<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn integral_size_and_signed_bias(tcx: TyCtxt<'tcx>, ty: Ty<'_>) -> Option<(Size, u128)> {
|
fn integral_size_and_signed_bias(tcx: TyCtxt<'tcx>, ty: Ty<'_>) -> Option<(Size, u128)> {
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
|
ty::Bool => Some((Size::from_bytes(1), 0)),
|
||||||
ty::Char => Some((Size::from_bytes(4), 0)),
|
ty::Char => Some((Size::from_bytes(4), 0)),
|
||||||
ty::Int(ity) => {
|
ty::Int(ity) => {
|
||||||
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
|
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue