diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/syntax_text.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/ra_syntax/src/syntax_text.rs b/crates/ra_syntax/src/syntax_text.rs index 6f15e3b35..d8adf782b 100644 --- a/crates/ra_syntax/src/syntax_text.rs +++ b/crates/ra_syntax/src/syntax_text.rs | |||
@@ -95,18 +95,21 @@ impl<'a> SyntaxText<'a> { | |||
95 | self.range.is_empty() | 95 | self.range.is_empty() |
96 | } | 96 | } |
97 | 97 | ||
98 | /// NB, the offsets here are absolute, and this probably doesn't make sense! | ||
99 | pub fn slice(&self, range: impl ops::RangeBounds<TextUnit>) -> SyntaxText<'a> { | 98 | pub fn slice(&self, range: impl ops::RangeBounds<TextUnit>) -> SyntaxText<'a> { |
100 | let start = match range.start_bound() { | 99 | let start = match range.start_bound() { |
101 | Bound::Included(b) => *b, | 100 | Bound::Included(&b) => b, |
102 | Bound::Excluded(b) => *b + TextUnit::from(1u32), | 101 | Bound::Excluded(_) => panic!("utf-aware slicing can't work this way"), |
103 | Bound::Unbounded => self.range.start(), | 102 | Bound::Unbounded => 0.into(), |
104 | }; | 103 | }; |
105 | let end = match range.end_bound() { | 104 | let end = match range.end_bound() { |
106 | Bound::Included(b) => *b + TextUnit::from(1u32), | 105 | Bound::Included(_) => panic!("utf-aware slicing can't work this way"), |
107 | Bound::Excluded(b) => *b, | 106 | Bound::Excluded(&b) => b, |
108 | Bound::Unbounded => self.range.end(), | 107 | Bound::Unbounded => self.len(), |
109 | }; | 108 | }; |
109 | assert!(start <= end); | ||
110 | let len = end - start; | ||
111 | let start = self.range.start() + start; | ||
112 | let end = start + len; | ||
110 | assert!( | 113 | assert!( |
111 | start <= end, | 114 | start <= end, |
112 | "invalid slice, range: {:?}, slice: {:?}", | 115 | "invalid slice, range: {:?}, slice: {:?}", |