Struct rustc_mir_build::thir::pattern::deconstruct_pat::IntRange
source · pub(crate) struct IntRange {
range: RangeInclusive<u128>,
}Expand description
An inclusive interval, used for precise integer exhaustiveness checking.
IntRanges 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>Implementations§
source§impl IntRange
impl IntRange
fn is_integral(ty: Ty<'_>) -> bool
fn is_singleton(&self) -> bool
fn boundaries(&self) -> (u128, u128)
fn from_bits<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, bits: u128) -> IntRange
fn from_range<'tcx>( tcx: TyCtxt<'tcx>, lo: u128, hi: u128, ty: Ty<'tcx>, end: RangeEnd ) -> 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 split(
&self,
column_ranges: impl Iterator<Item = IntRange>
) -> impl Iterator<Item = (Presence, IntRange)>
fn split( &self, column_ranges: impl Iterator<Item = IntRange> ) -> impl Iterator<Item = (Presence, IntRange)>
Partition a range of integers into disjoint subranges. This does constructor splitting for integer ranges as explained at the top of the file.
This returns an output that covers self. The output is split so that the only
intersections between an output range and a column range are inclusions. No output range
straddles the boundary of one of the inputs.
Additionally, we track for each output range whether it is covered by one of the column ranges or not.
The following input:
(--------------------------) // `self`
(------) (----------) (-)
(------) (--------)
is first intersected with self:
(--------------------------) // `self`
(----) (----------) (-)
(------) (--------)
and then iterated over as follows:
(-(--)-(-)-(------)-)--(-)-
where each sequence of dashes is an output range, and dashes outside parentheses are marked
as Presence::Missing.
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.
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,
lint_root: 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, lint_root: HirId )
Lint on likely incorrect range patterns (#63987)
Trait Implementations§
source§impl 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.
source§impl PartialEq<IntRange> for IntRange
impl PartialEq<IntRange> for IntRange
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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: 40 bytes