From f2ae412ccfa96c4bde42f0b004594c4d6fa54634 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 16 Sep 2020 21:29:48 +0200 Subject: Remove make::path_from_text --- crates/syntax/src/ast/make.rs | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'crates/syntax/src/ast/make.rs') 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 { pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { ast_from_text(&format!("use {};", name_ref)) } + pub fn path_segment_self() -> ast::PathSegment { ast_from_text("use self;") } + +pub fn path_segment_super() -> ast::PathSegment { + ast_from_text("use super;") +} + +pub fn path_segment_crate() -> ast::PathSegment { + ast_from_text("use crate;") +} + pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { - path_from_text(&format!("use {}", segment)) + ast_from_text(&format!("use {}", segment)) } + pub fn path_qualified(qual: ast::Path, segment: ast::PathSegment) -> ast::Path { - path_from_text(&format!("{}::{}", qual, segment)) + ast_from_text(&format!("{}::{}", qual, segment)) } -// FIXME: make this private -pub fn path_from_text(text: &str) -> ast::Path { - ast_from_text(text) + +pub fn path_concat(first: ast::Path, second: ast::Path) -> ast::Path { + ast_from_text(&format!("{}::{}", first, second)) +} + +pub fn path_from_segments( + segments: impl IntoIterator, + is_abs: bool, +) -> ast::Path { + let segments = segments.into_iter().map(|it| it.syntax().clone()).join("::"); + ast_from_text(&if is_abs { + format!("use ::{};", segments) + } else { + format!("use {};", segments) + }) } pub fn use_tree( -- cgit v1.2.3