diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-13 20:01:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-13 20:01:57 +0100 |
| commit | 5c2aa6dc6f78ce8cd65dd526ed8a84d2be425c1e (patch) | |
| tree | 72f8f799f20c847a80cf005fe3fa191ed26abaf5 /compiler/rustc_pattern_analysis | |
| parent | b3376bb92f32c82021e718f98239b3719acf6900 (diff) | |
| parent | c4236785c72fdf04176716393c910b1fb011d15f (diff) | |
| download | rust-5c2aa6dc6f78ce8cd65dd526ed8a84d2be425c1e.tar.gz rust-5c2aa6dc6f78ce8cd65dd526ed8a84d2be425c1e.zip | |
Rollup merge of #122437 - Nadrieril:no-after-max, r=compiler-errors
pattern analysis: remove `MaybeInfiniteInt::JustAfterMax` It was inherited from before half-open ranges, but it doesn't pull its weight anymore. We lose a tiny bit of diagnostic precision as can be seen in the test. I'm generally in favor of half-open ranges over explicit `x..=MAX` ranges anyway.
Diffstat (limited to 'compiler/rustc_pattern_analysis')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/constructor.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc.rs | 2 |
2 files changed, 6 insertions, 9 deletions
diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 1faecb7e1dd..bbb89576ef7 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -195,8 +195,6 @@ pub enum MaybeInfiniteInt { /// Encoded value. DO NOT CONSTRUCT BY HAND; use `new_finite_{int,uint}`. #[non_exhaustive] Finite(u128), - /// The integer after `u128::MAX`. We need it to represent `x..=u128::MAX` as an exclusive range. - JustAfterMax, PosInfinity, } @@ -232,18 +230,18 @@ impl MaybeInfiniteInt { pub fn minus_one(self) -> Option<Self> { match self { Finite(n) => n.checked_sub(1).map(Finite), - JustAfterMax => Some(Finite(u128::MAX)), x => Some(x), } } - /// Note: this will not turn a finite value into an infinite one or vice-versa. + /// Note: this will turn `u128::MAX` into `PosInfinity`. This means `plus_one` and `minus_one` + /// are not strictly inverses, but that poses no problem in our use of them. + /// this will not turn a finite value into an infinite one or vice-versa. pub fn plus_one(self) -> Option<Self> { match self { Finite(n) => match n.checked_add(1) { Some(m) => Some(Finite(m)), - None => Some(JustAfterMax), + None => Some(PosInfinity), }, - JustAfterMax => None, x => Some(x), } } @@ -277,8 +275,7 @@ impl IntRange { } /// Construct a range with these boundaries. - /// `lo` must not be `PosInfinity` or `JustAfterMax`. `hi` must not be `NegInfinity`. - /// If `end` is `Included`, `hi` must also not be `JustAfterMax`. + /// `lo` must not be `PosInfinity`. `hi` must not be `NegInfinity`. #[inline] pub fn from_range(lo: MaybeInfiniteInt, mut hi: MaybeInfiniteInt, end: RangeEnd) -> IntRange { if end == RangeEnd::Included { diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index d00faadccb0..fd51fbedeef 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -706,7 +706,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { None => PatRangeBoundary::PosInfinity, } } - JustAfterMax | PosInfinity => PatRangeBoundary::PosInfinity, + PosInfinity => PatRangeBoundary::PosInfinity, } } |
