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/hir_def/src/path.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 99395667d..40ec38f56 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs @@ -13,7 +13,7 @@ use hir_expand::{ hygiene::Hygiene, name::{AsName, Name}, }; -use syntax::ast; +use syntax::ast::{self, make}; use crate::{ type_ref::{TypeBound, TypeRef}, @@ -104,6 +104,26 @@ impl ModPath { } self.segments.first() } + + pub fn to_ast_path(&self) -> ast::Path { + let mut segments = Vec::new(); + let mut is_abs = false; + match self.kind { + PathKind::Plain => {} + PathKind::Super(0) => segments.push(make::path_segment_self()), + PathKind::Super(n) => segments.extend((0..n).map(|_| make::path_segment_super())), + PathKind::Crate => segments.push(make::path_segment_crate()), + PathKind::Abs => is_abs = true, + PathKind::DollarCrate(_) => (), + } + + segments.extend( + self.segments + .iter() + .map(|segment| make::path_segment(make::name_ref(&segment.to_string()))), + ); + make::path_from_segments(segments, is_abs) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -290,10 +310,8 @@ impl Display for ModPath { }; match self.kind { PathKind::Plain => {} + PathKind::Super(0) => add_segment("self")?, PathKind::Super(n) => { - if n == 0 { - add_segment("self")?; - } for _ in 0..n { add_segment("super")?; } -- cgit v1.2.3