Unnamed repository; edit this file 'description' to name the repository.
Merge rust-analyzer/text-size#20
20: Don't silently wrap for too-large str r=matklad a=CAD97
Closes rust-analyzer/text-size#19
Co-authored-by: CAD97 <[email protected]>
Co-authored-by: Christopher Durham <[email protected]>
| -rw-r--r-- | lib/text-size/src/traits.rs | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/text-size/src/traits.rs b/lib/text-size/src/traits.rs index d90f3d431c..ca4b7d9b42 100644 --- a/lib/text-size/src/traits.rs +++ b/lib/text-size/src/traits.rs @@ -8,14 +8,9 @@ pub trait TextSized: Copy { impl TextSized for &'_ str { fn text_size(self) -> TextSize { - let len = self.len(); - if let Ok(size) = len.try_into() { - size - } else if cfg!(debug_assertions) { - panic!("overflow when converting to TextSize"); - } else { - TextSize(len as u32) - } + self.len() + .try_into() + .unwrap_or_else(|_| panic!("string too large ({}) for TextSize", self.len())) } } |