diff options
Diffstat (limited to 'crates/syntax/src/ast/node_ext.rs')
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index bdf907a21..6d7db5fb2 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -12,19 +12,19 @@ use crate::{ | |||
12 | }; | 12 | }; |
13 | 13 | ||
14 | impl ast::Lifetime { | 14 | impl ast::Lifetime { |
15 | pub fn text(&self) -> &str { | 15 | pub fn text(&self) -> SmolStr { |
16 | text_of_first_token(self.syntax()) | 16 | text_of_first_token(self.syntax()) |
17 | } | 17 | } |
18 | } | 18 | } |
19 | 19 | ||
20 | impl ast::Name { | 20 | impl ast::Name { |
21 | pub fn text(&self) -> &str { | 21 | pub fn text(&self) -> SmolStr { |
22 | text_of_first_token(self.syntax()) | 22 | text_of_first_token(self.syntax()) |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | impl ast::NameRef { | 26 | impl ast::NameRef { |
27 | pub fn text(&self) -> &str { | 27 | pub fn text(&self) -> SmolStr { |
28 | text_of_first_token(self.syntax()) | 28 | text_of_first_token(self.syntax()) |
29 | } | 29 | } |
30 | 30 | ||
@@ -33,10 +33,8 @@ impl ast::NameRef { | |||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | fn text_of_first_token(node: &SyntaxNode) -> &str { | 36 | fn text_of_first_token(node: &SyntaxNode) -> SmolStr { |
37 | let t = | 37 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text().into() |
38 | node.green().children().next().and_then(|it| it.into_token()).unwrap().text().to_string(); | ||
39 | Box::leak(Box::new(t)) | ||
40 | } | 38 | } |
41 | 39 | ||
42 | pub enum Macro { | 40 | pub enum Macro { |
@@ -378,7 +376,7 @@ impl fmt::Display for NameOrNameRef { | |||
378 | } | 376 | } |
379 | 377 | ||
380 | impl NameOrNameRef { | 378 | impl NameOrNameRef { |
381 | pub fn text(&self) -> &str { | 379 | pub fn text(&self) -> SmolStr { |
382 | match self { | 380 | match self { |
383 | NameOrNameRef::Name(name) => name.text(), | 381 | NameOrNameRef::Name(name) => name.text(), |
384 | NameOrNameRef::NameRef(name_ref) => name_ref.text(), | 382 | NameOrNameRef::NameRef(name_ref) => name_ref.text(), |