diff options
Diffstat (limited to 'crates/syntax/src')
-rw-r--r-- | crates/syntax/src/ast/make.rs | 33 |
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 { | |||
24 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { | 24 | pub 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 | |||
27 | pub fn path_segment_self() -> ast::PathSegment { | 28 | pub fn path_segment_self() -> ast::PathSegment { |
28 | ast_from_text("use self;") | 29 | ast_from_text("use self;") |
29 | } | 30 | } |
31 | |||
32 | pub fn path_segment_super() -> ast::PathSegment { | ||
33 | ast_from_text("use super;") | ||
34 | } | ||
35 | |||
36 | pub fn path_segment_crate() -> ast::PathSegment { | ||
37 | ast_from_text("use crate;") | ||
38 | } | ||
39 | |||
30 | pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { | 40 | pub 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 | |||
33 | pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { | 44 | pub 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 | |
37 | pub fn path_from_text(text: &str) -> ast::Path { | 48 | pub 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 | |||
52 | pub 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 | ||
41 | pub fn use_tree( | 64 | pub fn use_tree( |