aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r--crates/syntax/src/ast/make.rs4
-rw-r--r--crates/syntax/src/ast/node_ext.rs20
2 files changed, 13 insertions, 11 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index c08f2c14f..c6a7b99b7 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -268,14 +268,14 @@ pub fn arg_list(args: impl IntoIterator<Item = ast::Expr>) -> ast::ArgList {
268} 268}
269 269
270pub fn ident_pat(name: ast::Name) -> ast::IdentPat { 270pub fn ident_pat(name: ast::Name) -> ast::IdentPat {
271 return from_text(name.text()); 271 return from_text(&name.text());
272 272
273 fn from_text(text: &str) -> ast::IdentPat { 273 fn from_text(text: &str) -> ast::IdentPat {
274 ast_from_text(&format!("fn f({}: ())", text)) 274 ast_from_text(&format!("fn f({}: ())", text))
275 } 275 }
276} 276}
277pub fn ident_mut_pat(name: ast::Name) -> ast::IdentPat { 277pub fn ident_mut_pat(name: ast::Name) -> ast::IdentPat {
278 return from_text(name.text()); 278 return from_text(&name.text());
279 279
280 fn from_text(text: &str) -> ast::IdentPat { 280 fn from_text(text: &str) -> ast::IdentPat {
281 ast_from_text(&format!("fn f(mut {}: ())", text)) 281 ast_from_text(&format!("fn f(mut {}: ())", text))
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index bdf907a21..ae98dbd26 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -8,23 +8,23 @@ use parser::SyntaxKind;
8 8
9use crate::{ 9use crate::{
10 ast::{self, support, AstNode, AstToken, AttrsOwner, NameOwner, SyntaxNode}, 10 ast::{self, support, AstNode, AstToken, AttrsOwner, NameOwner, SyntaxNode},
11 SmolStr, SyntaxElement, SyntaxToken, T, 11 SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
12}; 12};
13 13
14impl ast::Lifetime { 14impl ast::Lifetime {
15 pub fn text(&self) -> &str { 15 pub fn text(&self) -> TokenText {
16 text_of_first_token(self.syntax()) 16 text_of_first_token(self.syntax())
17 } 17 }
18} 18}
19 19
20impl ast::Name { 20impl ast::Name {
21 pub fn text(&self) -> &str { 21 pub fn text(&self) -> TokenText {
22 text_of_first_token(self.syntax()) 22 text_of_first_token(self.syntax())
23 } 23 }
24} 24}
25 25
26impl ast::NameRef { 26impl ast::NameRef {
27 pub fn text(&self) -> &str { 27 pub fn text(&self) -> TokenText {
28 text_of_first_token(self.syntax()) 28 text_of_first_token(self.syntax())
29 } 29 }
30 30
@@ -33,12 +33,14 @@ impl ast::NameRef {
33 } 33 }
34} 34}
35 35
36fn text_of_first_token(node: &SyntaxNode) -> &str { 36fn text_of_first_token(node: &SyntaxNode) -> TokenText {
37 let t = 37 let first_token =
38 node.green().children().next().and_then(|it| it.into_token()).unwrap().text().to_string(); 38 node.green().children().next().and_then(|it| it.into_token()).unwrap().to_owned();
39 Box::leak(Box::new(t)) 39
40 TokenText(first_token)
40} 41}
41 42
43#[derive(Debug, PartialEq, Eq, Clone)]
42pub enum Macro { 44pub enum Macro {
43 MacroRules(ast::MacroRules), 45 MacroRules(ast::MacroRules),
44 MacroDef(ast::MacroDef), 46 MacroDef(ast::MacroDef),
@@ -378,7 +380,7 @@ impl fmt::Display for NameOrNameRef {
378} 380}
379 381
380impl NameOrNameRef { 382impl NameOrNameRef {
381 pub fn text(&self) -> &str { 383 pub fn text(&self) -> TokenText {
382 match self { 384 match self {
383 NameOrNameRef::Name(name) => name.text(), 385 NameOrNameRef::Name(name) => name.text(),
384 NameOrNameRef::NameRef(name_ref) => name_ref.text(), 386 NameOrNameRef::NameRef(name_ref) => name_ref.text(),