diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-02-05 16:21:54 +0000 | 
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-03-06 10:50:23 +0000 | 
| commit | a2c1211b6de0c1a93c3ff1f97c49acc237f620a6 (patch) | |
| tree | b874786b63e39044bed6facda1438123c3d10733 /compiler/rustc_middle | |
| parent | e8f7a382be12a812b7d73f58967f740a0cf9d9af (diff) | |
| download | rust-a2c1211b6de0c1a93c3ff1f97c49acc237f620a6.tar.gz rust-a2c1211b6de0c1a93c3ff1f97c49acc237f620a6.zip  | |
Hide the end of ranges in pretty printing if it's also the maximum of the type
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/ty/pattern.rs | 24 | 
1 files changed, 23 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/pattern.rs b/compiler/rustc_middle/src/ty/pattern.rs index 89dadb36ad6..4cad1ab2099 100644 --- a/compiler/rustc_middle/src/ty/pattern.rs +++ b/compiler/rustc_middle/src/ty/pattern.rs @@ -27,7 +27,29 @@ impl<'tcx> fmt::Debug for PatternKind<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { PatternKind::Range { start, end } => { - write!(f, "{start}..={end}") + write!(f, "{start}")?; + + if let Some(c) = end.try_to_value() { + let end = c.valtree.unwrap_leaf(); + let size = end.size(); + let max = match c.ty.kind() { + ty::Int(_) => { + Some(ty::ScalarInt::truncate_from_int(size.signed_int_max(), size)) + } + ty::Uint(_) => { + Some(ty::ScalarInt::truncate_from_uint(size.unsigned_int_max(), size)) + } + ty::Char => Some(ty::ScalarInt::truncate_from_uint(char::MAX, size)), + _ => None, + }; + if let Some((max, _)) = max + && end == max + { + return write!(f, ".."); + } + } + + write!(f, "..={end}") } } }  | 
