aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast/make.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/ast/make.rs')
-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 25e8a359d..580eb3690 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -24,18 +24,41 @@ pub fn ty(text: &str) -> ast::Type {
24pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { 24pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
25 ast_from_text(&format!("use {};", name_ref)) 25 ast_from_text(&format!("use {};", name_ref))
26} 26}
27
27pub fn path_segment_self() -> ast::PathSegment { 28pub fn path_segment_self() -> ast::PathSegment {
28 ast_from_text("use self;") 29 ast_from_text("use self;")
29} 30}
31
32pub fn path_segment_super() -> ast::PathSegment {
33 ast_from_text("use super;")
34}
35
36pub fn path_segment_crate() -> ast::PathSegment {
37 ast_from_text("use crate;")
38}
39
30pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { 40pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path {
31 path_from_text(&format!("use {}", segment)) 41 ast_from_text(&format!("use {}", segment))
32} 42}
43
33pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { 44pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path {
34 path_from_text(&format!("{}::{}", qual, segment)) 45 ast_from_text(&format!("{}::{}", qual, segment))
35} 46}
36// FIXME: make this private 47
37pub fn path_from_text(text: &str) -> ast::Path { 48pub fn path_concat(first: ast::Path, second: ast::Path) -> ast::Path {
38 ast_from_text(text) 49 ast_from_text(&format!("{}::{}", first, second))
50}
51
52pub fn path_from_segments(
53 segments: impl IntoIterator<Item = ast::PathSegment>,
54 is_abs: bool,
55) -> ast::Path {
56 let segments = segments.into_iter().map(|it| it.syntax().clone()).join("::");
57 ast_from_text(&if is_abs {
58 format!("use ::{};", segments)
59 } else {
60 format!("use {};", segments)
61 })
39} 62}
40 63
41pub fn use_tree( 64pub fn use_tree(