aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-24 23:57:47 +0100
committerAleksey Kladov <[email protected]>2020-04-25 10:59:18 +0100
commit63a462f37ca584e1a585a69e30823ce25d4d252f (patch)
tree005ab4d5b50f7d031be9f4056bd1fccd68473587 /crates/ra_syntax/src/ast
parentdc2151085e9b117bc87307bf47edf3d17a170b49 (diff)
Switch to TryFrom
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/tokens.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs
index 26b8f9c36..8e04b0bbd 100644
--- a/crates/ra_syntax/src/ast/tokens.rs
+++ b/crates/ra_syntax/src/ast/tokens.rs
@@ -1,5 +1,7 @@
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
3use std::convert::{TryFrom, TryInto};
4
3use crate::{ 5use crate::{
4 ast::{AstToken, Comment, RawString, String, Whitespace}, 6 ast::{AstToken, Comment, RawString, String, Whitespace},
5 TextRange, TextSize, 7 TextRange, TextSize,
@@ -95,8 +97,8 @@ impl QuoteOffsets {
95 } 97 }
96 98
97 let start = TextSize::from(0); 99 let start = TextSize::from(0);
98 let left_quote = TextSize::from_usize(left_quote) + TextSize::of('"'); 100 let left_quote = TextSize::try_from(left_quote).unwrap() + TextSize::of('"');
99 let right_quote = TextSize::from_usize(right_quote); 101 let right_quote = TextSize::try_from(right_quote).unwrap();
100 let end = TextSize::of(literal); 102 let end = TextSize::of(literal);
101 103
102 let res = QuoteOffsets { 104 let res = QuoteOffsets {
@@ -498,7 +500,7 @@ 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::new(TextSize::from_usize(range.start), TextSize::from_usize(range.end)) 503 TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap())
502 + offset, 504 + offset,
503 unescaped_char, 505 unescaped_char,
504 )) 506 ))
@@ -518,11 +520,7 @@ impl HasFormatSpecifier for RawString {
518 520
519 let mut res = Vec::with_capacity(text.len()); 521 let mut res = Vec::with_capacity(text.len());
520 for (idx, c) in text.char_indices() { 522 for (idx, c) in text.char_indices() {
521 res.push(( 523 res.push((TextRange::at(idx.try_into().unwrap(), TextSize::of(c)) + offset, Ok(c)));
522 TextRange::new(TextSize::from_usize(idx), TextSize::from_usize(idx + c.len_utf8()))
523 + offset,
524 Ok(c),
525 ));
526 } 524 }
527 Some(res) 525 Some(res)
528 } 526 }