diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-25 11:16:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-25 11:16:02 +0100 |
commit | 29fc409e7fe5b12dcf6bfbcca622d79c4c8fcb72 (patch) | |
tree | e42f7bd1490bca66e0786d5bf2b3194aeaa57a93 /crates/ra_syntax/src/ast | |
parent | 27a7718880d93f55f905da606d108d3b3c682ab4 (diff) | |
parent | e87346950039a54c3f0b02d6056cbb92ca38eb28 (diff) |
Merge #4131
4131: Switch to text-size r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/tokens.rs | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index aa34b682d..8e04b0bbd 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs | |||
@@ -1,8 +1,10 @@ | |||
1 | //! There are many AstNodes, but only a few tokens, so we hand-write them here. | 1 | //! There are many AstNodes, but only a few tokens, so we hand-write them here. |
2 | 2 | ||
3 | use std::convert::{TryFrom, TryInto}; | ||
4 | |||
3 | use crate::{ | 5 | use crate::{ |
4 | ast::{AstToken, Comment, RawString, String, Whitespace}, | 6 | ast::{AstToken, Comment, RawString, String, Whitespace}, |
5 | TextRange, TextUnit, | 7 | TextRange, TextSize, |
6 | }; | 8 | }; |
7 | 9 | ||
8 | impl Comment { | 10 | impl Comment { |
@@ -94,14 +96,14 @@ impl QuoteOffsets { | |||
94 | return None; | 96 | return None; |
95 | } | 97 | } |
96 | 98 | ||
97 | let start = TextUnit::from(0); | 99 | let start = TextSize::from(0); |
98 | let left_quote = TextUnit::from_usize(left_quote) + TextUnit::of_char('"'); | 100 | let left_quote = TextSize::try_from(left_quote).unwrap() + TextSize::of('"'); |
99 | let right_quote = TextUnit::from_usize(right_quote); | 101 | let right_quote = TextSize::try_from(right_quote).unwrap(); |
100 | let end = TextUnit::of_str(literal); | 102 | let end = TextSize::of(literal); |
101 | 103 | ||
102 | let res = QuoteOffsets { | 104 | let res = QuoteOffsets { |
103 | quotes: [TextRange::from_to(start, left_quote), TextRange::from_to(right_quote, end)], | 105 | quotes: [TextRange::new(start, left_quote), TextRange::new(right_quote, end)], |
104 | contents: TextRange::from_to(left_quote, right_quote), | 106 | contents: TextRange::new(left_quote, right_quote), |
105 | }; | 107 | }; |
106 | Some(res) | 108 | Some(res) |
107 | } | 109 | } |
@@ -168,7 +170,7 @@ impl HasStringValue for RawString { | |||
168 | impl RawString { | 170 | impl RawString { |
169 | pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> { | 171 | pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> { |
170 | let contents_range = self.text_range_between_quotes()?; | 172 | let contents_range = self.text_range_between_quotes()?; |
171 | assert!(range.is_subrange(&TextRange::offset_len(0.into(), contents_range.len()))); | 173 | assert!(TextRange::up_to(contents_range.len()).contains_range(range)); |
172 | Some(range + contents_range.start()) | 174 | Some(range + contents_range.start()) |
173 | } | 175 | } |
174 | } | 176 | } |
@@ -459,7 +461,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
459 | while let Some((r, Ok(next_char))) = chars.peek() { | 461 | while let Some((r, Ok(next_char))) = chars.peek() { |
460 | if next_char.is_ascii_digit() { | 462 | if next_char.is_ascii_digit() { |
461 | chars.next(); | 463 | chars.next(); |
462 | range = range.extend_to(r); | 464 | range = range.cover(*r); |
463 | } else { | 465 | } else { |
464 | break; | 466 | break; |
465 | } | 467 | } |
@@ -477,7 +479,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
477 | while let Some((r, Ok(next_char))) = chars.peek() { | 479 | while let Some((r, Ok(next_char))) = chars.peek() { |
478 | if *next_char == '_' || next_char.is_ascii_digit() || next_char.is_alphabetic() { | 480 | if *next_char == '_' || next_char.is_ascii_digit() || next_char.is_alphabetic() { |
479 | chars.next(); | 481 | chars.next(); |
480 | range = range.extend_to(r); | 482 | range = range.cover(*r); |
481 | } else { | 483 | } else { |
482 | break; | 484 | break; |
483 | } | 485 | } |
@@ -498,10 +500,8 @@ impl HasFormatSpecifier for String { | |||
498 | let mut res = Vec::with_capacity(text.len()); | 500 | let mut res = Vec::with_capacity(text.len()); |
499 | rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| { | 501 | rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| { |
500 | res.push(( | 502 | res.push(( |
501 | TextRange::from_to( | 503 | TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap()) |
502 | TextUnit::from_usize(range.start), | 504 | + offset, |
503 | TextUnit::from_usize(range.end), | ||
504 | ) + offset, | ||
505 | unescaped_char, | 505 | unescaped_char, |
506 | )) | 506 | )) |
507 | }); | 507 | }); |
@@ -520,13 +520,7 @@ impl HasFormatSpecifier for RawString { | |||
520 | 520 | ||
521 | let mut res = Vec::with_capacity(text.len()); | 521 | let mut res = Vec::with_capacity(text.len()); |
522 | for (idx, c) in text.char_indices() { | 522 | for (idx, c) in text.char_indices() { |
523 | res.push(( | 523 | res.push((TextRange::at(idx.try_into().unwrap(), TextSize::of(c)) + offset, Ok(c))); |
524 | TextRange::from_to( | ||
525 | TextUnit::from_usize(idx), | ||
526 | TextUnit::from_usize(idx + c.len_utf8()), | ||
527 | ) + offset, | ||
528 | Ok(c), | ||
529 | )); | ||
530 | } | 524 | } |
531 | Some(res) | 525 | Some(res) |
532 | } | 526 | } |