aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/path.rs26
1 files changed, 22 insertions, 4 deletions
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::{
13 hygiene::Hygiene, 13 hygiene::Hygiene,
14 name::{AsName, Name}, 14 name::{AsName, Name},
15}; 15};
16use syntax::ast; 16use syntax::ast::{self, make};
17 17
18use crate::{ 18use crate::{
19 type_ref::{TypeBound, TypeRef}, 19 type_ref::{TypeBound, TypeRef},
@@ -104,6 +104,26 @@ impl ModPath {
104 } 104 }
105 self.segments.first() 105 self.segments.first()
106 } 106 }
107
108 pub fn to_ast_path(&self) -> ast::Path {
109 let mut segments = Vec::new();
110 let mut is_abs = false;
111 match self.kind {
112 PathKind::Plain => {}
113 PathKind::Super(0) => segments.push(make::path_segment_self()),
114 PathKind::Super(n) => segments.extend((0..n).map(|_| make::path_segment_super())),
115 PathKind::Crate => segments.push(make::path_segment_crate()),
116 PathKind::Abs => is_abs = true,
117 PathKind::DollarCrate(_) => (),
118 }
119
120 segments.extend(
121 self.segments
122 .iter()
123 .map(|segment| make::path_segment(make::name_ref(&segment.to_string()))),
124 );
125 make::path_from_segments(segments, is_abs)
126 }
107} 127}
108 128
109#[derive(Debug, Clone, PartialEq, Eq, Hash)] 129#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -290,10 +310,8 @@ impl Display for ModPath {
290 }; 310 };
291 match self.kind { 311 match self.kind {
292 PathKind::Plain => {} 312 PathKind::Plain => {}
313 PathKind::Super(0) => add_segment("self")?,
293 PathKind::Super(n) => { 314 PathKind::Super(n) => {
294 if n == 0 {
295 add_segment("self")?;
296 }
297 for _ in 0..n { 315 for _ in 0..n {
298 add_segment("super")?; 316 add_segment("super")?;
299 } 317 }