about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/syntax
diff options
context:
space:
mode:
authorPrajwal S N <prajwalnadig21@gmail.com>2025-04-15 11:52:22 +0530
committerPrajwal S N <prajwalnadig21@gmail.com>2025-04-16 13:06:42 +0530
commitda70675eefea6dda23ec211f7bfd1daff32e97a5 (patch)
treee7b32457f205b185e9749f50cbceec2af0f42d95 /src/tools/rust-analyzer/crates/syntax
parentd9b61b3382e83c8e3aaab0239da74e0526aed283 (diff)
downloadrust-da70675eefea6dda23ec211f7bfd1daff32e97a5.tar.gz
rust-da70675eefea6dda23ec211f7bfd1daff32e97a5.zip
fix: use `ast::TokenTree` in `make::expr_macro`
Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
Diffstat (limited to 'src/tools/rust-analyzer/crates/syntax')
-rw-r--r--src/tools/rust-analyzer/crates/syntax/src/ast/make.rs18
-rw-r--r--src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs6
2 files changed, 12 insertions, 12 deletions
diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs
index 6fdf10f199e..d608a35effa 100644
--- a/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs
+++ b/src/tools/rust-analyzer/crates/syntax/src/ast/make.rs
@@ -32,12 +32,9 @@ pub mod ext {
     use super::*;
 
     pub fn simple_ident_pat(name: ast::Name) -> ast::IdentPat {
-        return from_text(&name.text());
-
-        fn from_text(text: &str) -> ast::IdentPat {
-            ast_from_text(&format!("fn f({text}: ())"))
-        }
+        ast_from_text(&format!("fn f({}: ())", name.text()))
     }
+
     pub fn ident_path(ident: &str) -> ast::Path {
         path_unqualified(path_segment(name_ref(ident)))
     }
@@ -81,7 +78,6 @@ pub mod ext {
     pub fn expr_self() -> ast::Expr {
         expr_from_text("self")
     }
-
     pub fn zero_number() -> ast::Expr {
         expr_from_text("0")
     }
@@ -116,6 +112,10 @@ pub mod ext {
     pub fn ty_result(t: ast::Type, e: ast::Type) -> ast::Type {
         ty_from_text(&format!("Result<{t}, {e}>"))
     }
+
+    pub fn token_tree_from_node(node: &ast::SyntaxNode) -> ast::TokenTree {
+        ast_from_text(&format!("todo!{node}"))
+    }
 }
 
 pub fn name(name: &str) -> ast::Name {
@@ -643,8 +643,8 @@ pub fn expr_method_call(
 ) -> ast::MethodCallExpr {
     expr_from_text(&format!("{receiver}.{method}{arg_list}"))
 }
-pub fn expr_macro(path: ast::Path, arg_list: ast::ArgList) -> ast::MacroExpr {
-    expr_from_text(&format!("{path}!{arg_list}"))
+pub fn expr_macro(path: ast::Path, tt: ast::TokenTree) -> ast::MacroExpr {
+    expr_from_text(&format!("{path}!{tt}"))
 }
 pub fn expr_ref(expr: ast::Expr, exclusive: bool) -> ast::Expr {
     expr_from_text(&if exclusive { format!("&mut {expr}") } else { format!("&{expr}") })
@@ -1226,7 +1226,7 @@ pub fn meta_path(path: ast::Path) -> ast::Meta {
 
 pub fn token_tree(
     delimiter: SyntaxKind,
-    tt: Vec<NodeOrToken<ast::TokenTree, SyntaxToken>>,
+    tt: impl IntoIterator<Item = NodeOrToken<ast::TokenTree, SyntaxToken>>,
 ) -> ast::TokenTree {
     let (l_delimiter, r_delimiter) = match delimiter {
         T!['('] => ('(', ')'),
diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs
index 9b816d0b2f3..1854000d3db 100644
--- a/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs
+++ b/src/tools/rust-analyzer/crates/syntax/src/ast/syntax_factory/constructors.rs
@@ -584,15 +584,15 @@ impl SyntaxFactory {
         ast
     }
 
-    pub fn expr_macro(&self, path: ast::Path, args: ast::ArgList) -> ast::MacroExpr {
-        let ast = make::expr_macro(path.clone(), args.clone()).clone_for_update();
+    pub fn expr_macro(&self, path: ast::Path, tt: ast::TokenTree) -> ast::MacroExpr {
+        let ast = make::expr_macro(path.clone(), tt.clone()).clone_for_update();
 
         if let Some(mut mapping) = self.mappings() {
             let macro_call = ast.macro_call().unwrap();
             let mut builder = SyntaxMappingBuilder::new(macro_call.syntax().clone());
             builder.map_node(path.syntax().clone(), macro_call.path().unwrap().syntax().clone());
             builder
-                .map_node(args.syntax().clone(), macro_call.token_tree().unwrap().syntax().clone());
+                .map_node(tt.syntax().clone(), macro_call.token_tree().unwrap().syntax().clone());
             builder.finish(&mut mapping);
         }