diff options
Diffstat (limited to 'crates/syntax')
-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 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 { | |||
28 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { | 28 | pub 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 | |||
31 | pub fn path_segment_self() -> ast::PathSegment { | 32 | pub fn path_segment_self() -> ast::PathSegment { |
32 | ast_from_text("use self;") | 33 | ast_from_text("use self;") |
33 | } | 34 | } |
35 | |||
36 | pub fn path_segment_super() -> ast::PathSegment { | ||
37 | ast_from_text("use super;") | ||
38 | } | ||
39 | |||
40 | pub fn path_segment_crate() -> ast::PathSegment { | ||
41 | ast_from_text("use crate;") | ||
42 | } | ||
43 | |||
34 | pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { | 44 | pub 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 | |||
37 | pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { | 48 | pub 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 | |
41 | pub fn path_from_text(text: &str) -> ast::Path { | 52 | pub 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 | |||
56 | pub 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 | ||
45 | pub fn glob_use_tree() -> ast::UseTree { | 68 | pub fn glob_use_tree() -> ast::UseTree { |