diff options
author | Aleksey Kladov <[email protected]> | 2020-11-06 17:39:09 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-11-06 17:39:09 +0000 |
commit | 6bcc33e5b7e32a79865be4893fcc33caf8d831d6 (patch) | |
tree | 0dcd37ddfdc8cf4e4fddbed04bd6b03ffb1b5241 /crates/syntax/src/ast | |
parent | 3820b26a9325b26acd614bcad57d410e7286226e (diff) |
Better imports
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index c5ef92733..44f967acb 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs | |||
@@ -8,11 +8,11 @@ use std::{ | |||
8 | use rustc_lexer::unescape::{unescape_literal, Mode}; | 8 | use rustc_lexer::unescape::{unescape_literal, Mode}; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | ast::{AstToken, Comment, RawString, String, Whitespace}, | 11 | ast::{self, AstToken}, |
12 | TextRange, TextSize, | 12 | TextRange, TextSize, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | impl Comment { | 15 | impl ast::Comment { |
16 | pub fn kind(&self) -> CommentKind { | 16 | pub fn kind(&self) -> CommentKind { |
17 | kind_by_prefix(self.text()) | 17 | kind_by_prefix(self.text()) |
18 | } | 18 | } |
@@ -80,7 +80,7 @@ fn kind_by_prefix(text: &str) -> CommentKind { | |||
80 | panic!("bad comment text: {:?}", text) | 80 | panic!("bad comment text: {:?}", text) |
81 | } | 81 | } |
82 | 82 | ||
83 | impl Whitespace { | 83 | impl ast::Whitespace { |
84 | pub fn spans_multiple_lines(&self) -> bool { | 84 | pub fn spans_multiple_lines(&self) -> bool { |
85 | let text = self.text(); | 85 | let text = self.text(); |
86 | text.find('\n').map_or(false, |idx| text[idx + 1..].contains('\n')) | 86 | text.find('\n').map_or(false, |idx| text[idx + 1..].contains('\n')) |
@@ -138,19 +138,19 @@ pub trait HasQuotes: AstToken { | |||
138 | } | 138 | } |
139 | } | 139 | } |
140 | 140 | ||
141 | impl HasQuotes for String {} | 141 | impl HasQuotes for ast::String {} |
142 | impl HasQuotes for RawString {} | 142 | impl HasQuotes for ast::RawString {} |
143 | 143 | ||
144 | pub trait HasStringValue: HasQuotes { | 144 | pub trait HasStringValue: HasQuotes { |
145 | fn value(&self) -> Option<Cow<'_, str>>; | 145 | fn value(&self) -> Option<Cow<'_, str>>; |
146 | } | 146 | } |
147 | 147 | ||
148 | impl HasStringValue for String { | 148 | impl HasStringValue for ast::String { |
149 | fn value(&self) -> Option<Cow<'_, str>> { | 149 | fn value(&self) -> Option<Cow<'_, str>> { |
150 | let text = self.text().as_str(); | 150 | let text = self.text().as_str(); |
151 | let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()]; | 151 | let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()]; |
152 | 152 | ||
153 | let mut buf = std::string::String::with_capacity(text.len()); | 153 | let mut buf = String::with_capacity(text.len()); |
154 | let mut has_error = false; | 154 | let mut has_error = false; |
155 | unescape_literal(text, Mode::Str, &mut |_, unescaped_char| match unescaped_char { | 155 | unescape_literal(text, Mode::Str, &mut |_, unescaped_char| match unescaped_char { |
156 | Ok(c) => buf.push(c), | 156 | Ok(c) => buf.push(c), |
@@ -166,7 +166,7 @@ impl HasStringValue for String { | |||
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | impl HasStringValue for RawString { | 169 | impl HasStringValue for ast::RawString { |
170 | fn value(&self) -> Option<Cow<'_, str>> { | 170 | fn value(&self) -> Option<Cow<'_, str>> { |
171 | let text = self.text().as_str(); | 171 | let text = self.text().as_str(); |
172 | let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()]; | 172 | let text = &text[self.text_range_between_quotes()? - self.syntax().text_range().start()]; |
@@ -174,7 +174,7 @@ impl HasStringValue for RawString { | |||
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | impl RawString { | 177 | impl ast::RawString { |
178 | pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> { | 178 | pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> { |
179 | let contents_range = self.text_range_between_quotes()?; | 179 | let contents_range = self.text_range_between_quotes()?; |
180 | assert!(TextRange::up_to(contents_range.len()).contains_range(range)); | 180 | assert!(TextRange::up_to(contents_range.len()).contains_range(range)); |
@@ -500,7 +500,7 @@ pub trait HasFormatSpecifier: AstToken { | |||
500 | } | 500 | } |
501 | } | 501 | } |
502 | 502 | ||
503 | impl HasFormatSpecifier for String { | 503 | impl HasFormatSpecifier for ast::String { |
504 | fn char_ranges( | 504 | fn char_ranges( |
505 | &self, | 505 | &self, |
506 | ) -> Option<Vec<(TextRange, Result<char, rustc_lexer::unescape::EscapeError>)>> { | 506 | ) -> Option<Vec<(TextRange, Result<char, rustc_lexer::unescape::EscapeError>)>> { |
@@ -521,7 +521,7 @@ impl HasFormatSpecifier for String { | |||
521 | } | 521 | } |
522 | } | 522 | } |
523 | 523 | ||
524 | impl HasFormatSpecifier for RawString { | 524 | impl HasFormatSpecifier for ast::RawString { |
525 | fn char_ranges( | 525 | fn char_ranges( |
526 | &self, | 526 | &self, |
527 | ) -> Option<Vec<(TextRange, Result<char, rustc_lexer::unescape::EscapeError>)>> { | 527 | ) -> Option<Vec<(TextRange, Result<char, rustc_lexer::unescape::EscapeError>)>> { |