Skip to content

Commit 354b45f

Browse files
committed
Improve Range: Debug impl
1 parent bdab213 commit 354b45f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,18 @@ impl IntRange {
391391
/// first.
392392
impl fmt::Debug for IntRange {
393393
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
394-
if let Finite(lo) = self.lo {
394+
if self.is_singleton() {
395+
// Only finite ranges can be singletons.
396+
let Finite(lo) = self.lo else { unreachable!() };
395397
write!(f, "{lo}")?;
396-
}
397-
write!(f, "{}", RangeEnd::Excluded)?;
398-
if let Finite(hi) = self.hi {
399-
write!(f, "{hi}")?;
398+
} else {
399+
if let Finite(lo) = self.lo {
400+
write!(f, "{lo}")?;
401+
}
402+
write!(f, "{}", RangeEnd::Excluded)?;
403+
if let Finite(hi) = self.hi {
404+
write!(f, "{hi}")?;
405+
}
400406
}
401407
Ok(())
402408
}

0 commit comments

Comments
 (0)