aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax')
-rw-r--r--crates/syntax/src/ast/make.rs33
1 files changed, 28 insertions, 5 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 4a0ffcbb0..3a184094c 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -28,18 +28,41 @@ pub fn assoc_item_list() -> ast::AssocItemList {
28pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { 28pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
29 ast_from_text(&format!("use {};", name_ref)) 29 ast_from_text(&format!("use {};", name_ref))
30} 30}
31
31pub fn path_segment_self() -> ast::PathSegment { 32pub fn path_segment_self() -> ast::PathSegment {
32 ast_from_text("use self;") 33 ast_from_text("use self;")
33} 34}
35
36pub fn path_segment_super() -> ast::PathSegment {
37 ast_from_text("use super;")
38}
39
40pub fn path_segment_crate() -> ast::PathSegment {
41 ast_from_text("use crate;")
42}
43
34pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { 44pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path {
35 path_from_text(&format!("use {}", segment)) 45 ast_from_text(&format!("use {}", segment))
36} 46}
47
37pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { 48pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path {
38 path_from_text(&format!("{}::{}", qual, segment)) 49 ast_from_text(&format!("{}::{}", qual, segment))
39} 50}
40// FIXME: make this private 51
41pub fn path_from_text(text: &str) -> ast::Path { 52pub fn path_concat(first: ast::Path, second: ast::Path) -> ast::Path {
42 ast_from_text(text) 53 ast_from_text(&format!("{}::{}", first, second))
54}
55
56pub fn path_from_segments(
57 segments: impl IntoIterator<Item = ast::PathSegment>,
58 is_abs: bool,
59) -> ast::Path {
60 let segments = segments.into_iter().map(|it| it.syntax().clone()).join("::");
61 ast_from_text(&if is_abs {
62 format!("use ::{};", segments)
63 } else {
64 format!("use {};", segments)
65 })
43} 66}
44 67
45pub fn glob_use_tree() -> ast::UseTree { 68pub fn glob_use_tree() -> ast::UseTree {