about summary refs log tree commit diff
path: root/crates/syntax/src
diff options
context:
space:
mode:
authorRyo Yoshida <low.ryoshida@gmail.com>2023-02-13 18:43:59 +0900
committerRyo Yoshida <low.ryoshida@gmail.com>2023-02-13 18:43:59 +0900
commit92fdfb548ea68636a4c823c8138cfef2af41dcbf (patch)
tree0400c096b8cb384b2b7e10ea3f7f4e0008b92da2 /crates/syntax/src
parent646f97385709fab31db2f10661125c0bbbda6b7c (diff)
downloadrust-92fdfb548ea68636a4c823c8138cfef2af41dcbf.tar.gz
rust-92fdfb548ea68636a4c823c8138cfef2af41dcbf.zip
Make `is_raw_identifier()` public util function
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/ast/make.rs5
-rw-r--r--crates/syntax/src/utils.rs7
2 files changed, 8 insertions, 4 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 78ed2a73e58..5aebe4cd9f5 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -12,7 +12,7 @@
 use itertools::Itertools;
 use stdx::{format_to, never};
 
-use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxToken};
+use crate::{ast, utils::is_raw_identifier, AstNode, SourceFile, SyntaxKind, SyntaxToken};
 
 /// While the parent module defines basic atomic "constructors", the `ext`
 /// module defines shortcuts for common things.
@@ -111,8 +111,7 @@ pub fn name_ref(name_ref: &str) -> ast::NameRef {
     ast_from_text(&format!("fn f() {{ {raw_escape}{name_ref}; }}"))
 }
 fn raw_ident_esc(ident: &str) -> &'static str {
-    let is_keyword = parser::SyntaxKind::from_keyword(ident).is_some();
-    if is_keyword && !matches!(ident, "self" | "crate" | "super" | "Self") {
+    if is_raw_identifier(ident) {
         "r#"
     } else {
         ""
diff --git a/crates/syntax/src/utils.rs b/crates/syntax/src/utils.rs
index f4c02518b4c..25f34ea9d39 100644
--- a/crates/syntax/src/utils.rs
+++ b/crates/syntax/src/utils.rs
@@ -2,7 +2,7 @@
 
 use itertools::Itertools;
 
-use crate::{ast, match_ast, AstNode};
+use crate::{ast, match_ast, AstNode, SyntaxKind};
 
 pub fn path_to_string_stripping_turbo_fish(path: &ast::Path) -> String {
     path.syntax()
@@ -23,6 +23,11 @@ pub fn path_to_string_stripping_turbo_fish(path: &ast::Path) -> String {
         .join("::")
 }
 
+pub fn is_raw_identifier(name: &str) -> bool {
+    let is_keyword = SyntaxKind::from_keyword(name).is_some();
+    is_keyword && !matches!(name, "self" | "crate" | "super" | "Self")
+}
+
 #[cfg(test)]
 mod tests {
     use super::path_to_string_stripping_turbo_fish;