Skip to content

Commit c423678

Browse files
committed
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.
1 parent 9ce37dc commit c423678

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ pub enum MaybeInfiniteInt {
195195
/// Encoded value. DO NOT CONSTRUCT BY HAND; use `new_finite_{int,uint}`.
196196
#[non_exhaustive]
197197
Finite(u128),
198-
/// The integer after `u128::MAX`. We need it to represent `x..=u128::MAX` as an exclusive range.
199-
JustAfterMax,
200198
PosInfinity,
201199
}
202200

@@ -232,18 +230,18 @@ impl MaybeInfiniteInt {
232230
pub fn minus_one(self) -> Option<Self> {
233231
match self {
234232
Finite(n) => n.checked_sub(1).map(Finite),
235-
JustAfterMax => Some(Finite(u128::MAX)),
236233
x => Some(x),
237234
}
238235
}
239-
/// Note: this will not turn a finite value into an infinite one or vice-versa.
236+
/// Note: this will turn `u128::MAX` into `PosInfinity`. This means `plus_one` and `minus_one`
237+
/// are not strictly inverses, but that poses no problem in our use of them.
238+
/// this will not turn a finite value into an infinite one or vice-versa.
240239
pub fn plus_one(self) -> Option<Self> {
241240
match self {
242241
Finite(n) => match n.checked_add(1) {
243242
Some(m) => Some(Finite(m)),
244-
None => Some(JustAfterMax),
243+
None => Some(PosInfinity),
245244
},
246-
JustAfterMax => None,
247245
x => Some(x),
248246
}
249247
}
@@ -277,8 +275,7 @@ impl IntRange {
277275
}
278276

279277
/// Construct a range with these boundaries.
280-
/// `lo` must not be `PosInfinity` or `JustAfterMax`. `hi` must not be `NegInfinity`.
281-
/// If `end` is `Included`, `hi` must also not be `JustAfterMax`.
278+
/// `lo` must not be `PosInfinity`. `hi` must not be `NegInfinity`.
282279
#[inline]
283280
pub fn from_range(lo: MaybeInfiniteInt, mut hi: MaybeInfiniteInt, end: RangeEnd) -> IntRange {
284281
if end == RangeEnd::Included {

compiler/rustc_pattern_analysis/src/rustc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
710710
None => PatRangeBoundary::PosInfinity,
711711
}
712712
}
713-
JustAfterMax | PosInfinity => PatRangeBoundary::PosInfinity,
713+
PosInfinity => PatRangeBoundary::PosInfinity,
714714
}
715715
}
716716

tests/ui/half-open-range-patterns/half-open-range-pats-exhaustive-fail.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,17 @@ help: ensure that all possible cases are being handled by adding a match arm wit
394394
LL | match $s { $($t)+ => {}, u128::MAX => todo!() }
395395
| ++++++++++++++++++++++
396396

397-
error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211454_u128..=u128::MAX` not covered
397+
error[E0004]: non-exhaustive patterns: `340282366920938463463374607431768211454_u128..` not covered
398398
--> $DIR/half-open-range-pats-exhaustive-fail.rs:93:12
399399
|
400400
LL | m!(0, ..ALMOST_MAX);
401-
| ^ pattern `340282366920938463463374607431768211454_u128..=u128::MAX` not covered
401+
| ^ pattern `340282366920938463463374607431768211454_u128..` not covered
402402
|
403403
= note: the matched value is of type `u128`
404404
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
405405
|
406-
LL | match $s { $($t)+ => {}, 340282366920938463463374607431768211454_u128..=u128::MAX => todo!() }
407-
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
406+
LL | match $s { $($t)+ => {}, 340282366920938463463374607431768211454_u128.. => todo!() }
407+
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
408408

409409
error[E0004]: non-exhaustive patterns: `0_u128` not covered
410410
--> $DIR/half-open-range-pats-exhaustive-fail.rs:94:12
@@ -754,17 +754,17 @@ help: ensure that all possible cases are being handled by adding a match arm wit
754754
LL | match $s { $($t)+ => {}, i128::MAX => todo!() }
755755
| ++++++++++++++++++++++
756756

757-
error[E0004]: non-exhaustive patterns: `170141183460469231731687303715884105726_i128..=i128::MAX` not covered
757+
error[E0004]: non-exhaustive patterns: `170141183460469231731687303715884105726_i128..` not covered
758758
--> $DIR/half-open-range-pats-exhaustive-fail.rs:161:12
759759
|
760760
LL | m!(0, ..ALMOST_MAX);
761-
| ^ pattern `170141183460469231731687303715884105726_i128..=i128::MAX` not covered
761+
| ^ pattern `170141183460469231731687303715884105726_i128..` not covered
762762
|
763763
= note: the matched value is of type `i128`
764764
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
765765
|
766-
LL | match $s { $($t)+ => {}, 170141183460469231731687303715884105726_i128..=i128::MAX => todo!() }
767-
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
766+
LL | match $s { $($t)+ => {}, 170141183460469231731687303715884105726_i128.. => todo!() }
767+
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
768768

769769
error[E0004]: non-exhaustive patterns: `i128::MIN` not covered
770770
--> $DIR/half-open-range-pats-exhaustive-fail.rs:162:12

tests/ui/pattern/usefulness/integer-ranges/exhaustiveness.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ help: ensure that all possible cases are being handled by adding a match arm wit
107107
LL | match $s { $($t)+ => {}, u128::MAX => todo!() }
108108
| ++++++++++++++++++++++
109109

110-
error[E0004]: non-exhaustive patterns: `5_u128..=u128::MAX` not covered
110+
error[E0004]: non-exhaustive patterns: `5_u128..` not covered
111111
--> $DIR/exhaustiveness.rs:61:8
112112
|
113113
LL | m!(0u128, 0..=4);
114-
| ^^^^^ pattern `5_u128..=u128::MAX` not covered
114+
| ^^^^^ pattern `5_u128..` not covered
115115
|
116116
= note: the matched value is of type `u128`
117117
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
118118
|
119-
LL | match $s { $($t)+ => {}, 5_u128..=u128::MAX => todo!() }
120-
| +++++++++++++++++++++++++++++++
119+
LL | match $s { $($t)+ => {}, 5_u128.. => todo!() }
120+
| +++++++++++++++++++++
121121

122122
error[E0004]: non-exhaustive patterns: `0_u128` not covered
123123
--> $DIR/exhaustiveness.rs:62:8

0 commit comments

Comments
 (0)