Struct rustc_pattern_analysis::constructor::IntRange
source · pub struct IntRange {
pub lo: MaybeInfiniteInt,
pub hi: MaybeInfiniteInt,
}Expand description
An exclusive interval, used for precise integer exhaustiveness checking. IntRanges always
store a contiguous range.
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§
§lo: MaybeInfiniteInt§hi: MaybeInfiniteIntImplementations§
source§impl IntRange
impl IntRange
sourcepub fn is_singleton(&self) -> bool
pub fn is_singleton(&self) -> bool
Best effort; will not know that e.g. 255u8.. is a singleton.
pub fn from_singleton(x: MaybeInfiniteInt) -> IntRange
pub fn from_range( lo: MaybeInfiniteInt, hi: MaybeInfiniteInt, end: RangeEnd ) -> IntRange
fn is_subrange(&self, other: &Self) -> bool
fn intersection(&self, other: &Self) -> Option<Self>
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.
isize/usize
Whereas a wildcard of type i32 stands for the range i32::MIN..=i32::MAX, a usize
wildcard stands for 0..PosInfinity and a isize wildcard stands for
NegInfinity..PosInfinity. In other words, as far as IntRange is concerned, there are
values before isize::MIN and after usize::MAX/isize::MAX.
This is to avoid e.g. 0..(u32::MAX as usize) from being exhaustive on one architecture and
not others. This was decided in https://github.com/rust-lang/rfcs/pull/2591.
These infinities affect splitting subtly: it is possible to get NegInfinity..0 and
usize::MAX+1..PosInfinity in the output. Diagnostics must be careful to handle these
fictitious ranges sensibly.
Trait Implementations§
source§impl Debug for IntRange
impl Debug for IntRange
Note: this will render signed ranges incorrectly. To render properly, convert to a pattern first.
source§impl PartialEq for IntRange
impl PartialEq for IntRange
impl Copy 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
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: 48 bytes