Struct rustc_mir_build::thir::pattern::deconstruct_pat::IntRange
source · pub(super) struct IntRange {
range: RangeInclusive<u128>,
bias: u128,
}
Expand description
An inclusive interval, used for precise integer exhaustiveness checking.
IntRange
s always store a contiguous range. This means that values are
encoded such that 0
encodes the minimum value for the integer,
regardless of the signedness.
For example, the pattern -128..=127i8
is encoded as 0..=255
.
This makes comparisons and arithmetic on interval endpoints much more
straightforward. See signed_bias
for details.
IntRange
is never used to encode an empty range or a “range” that wraps
around the (offset) space: i.e., range.lo <= range.hi
.
Fields
range: RangeInclusive<u128>
bias: u128
Keeps the bias used for encoding the range. It depends on the type of the range and
possibly the pointer size of the current architecture. The algorithm ensures we never
compare IntRange
s with different types/architectures.
Implementations
sourceimpl IntRange
impl IntRange
fn is_integral(ty: Ty<'_>) -> bool
fn is_singleton(&self) -> bool
fn boundaries(&self) -> (u128, u128)
fn integral_size_and_signed_bias(
tcx: TyCtxt<'_>,
ty: Ty<'_>
) -> Option<(Size, u128)>
fn from_constant<'tcx>(
tcx: TyCtxt<'tcx>,
param_env: ParamEnv<'tcx>,
value: ConstantKind<'tcx>
) -> Option<IntRange>
fn from_range<'tcx>(
tcx: TyCtxt<'tcx>,
lo: u128,
hi: u128,
ty: Ty<'tcx>,
end: &RangeEnd
) -> Option<IntRange>
fn signed_bias(tcx: TyCtxt<'_>, ty: Ty<'_>) -> u128
fn is_subrange(&self, other: &Self) -> bool
fn intersection(&self, other: &Self) -> Option<Self>
fn suspicious_intersection(&self, other: &Self) -> bool
sourcefn to_pat<'tcx>(&self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Pat<'tcx>
fn to_pat<'tcx>(&self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Pat<'tcx>
Only used for displaying the range properly.
sourcepub(super) fn lint_overlapping_range_endpoints<'a, 'p: 'a, 'tcx: 'a>(
&self,
pcx: &PatCtxt<'_, 'p, 'tcx>,
pats: impl Iterator<Item = &'a DeconstructedPat<'p, 'tcx>>,
column_count: usize,
hir_id: HirId
)
pub(super) fn lint_overlapping_range_endpoints<'a, 'p: 'a, 'tcx: 'a>(
&self,
pcx: &PatCtxt<'_, 'p, 'tcx>,
pats: impl Iterator<Item = &'a DeconstructedPat<'p, 'tcx>>,
column_count: usize,
hir_id: HirId
)
Lint on likely incorrect range patterns (#63987)
sourcefn is_covered_by(&self, other: &Self) -> bool
fn is_covered_by(&self, other: &Self) -> bool
See Constructor::is_covered_by
Trait Implementations
sourceimpl Debug for IntRange
impl Debug for IntRange
Note: this is often not what we want: e.g. false
is converted into the range 0..=0
and
would be displayed as such. To render properly, convert to a pattern first.
impl Eq for IntRange
impl StructuralEq for IntRange
impl StructuralPartialEq for IntRange
Auto Trait Implementations
impl RefUnwindSafe for IntRange
impl Send for IntRange
impl Sync for IntRange
impl Unpin for IntRange
impl UnwindSafe for IntRange
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 56 bytes