aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src')
-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 734310458..209b18e78 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},
@@ -100,6 +100,26 @@ impl ModPath {
100 } 100 }
101 self.segments.first() 101 self.segments.first()
102 } 102 }
103
104 pub fn to_ast_path(&self) -> ast::Path {
105 let mut segments = Vec::new();
106 let mut is_abs = false;
107 match self.kind {
108 PathKind::Plain => {}
109 PathKind::Super(0) => segments.push(make::path_segment_self()),
110 PathKind::Super(n) => segments.extend((0..n).map(|_| make::path_segment_super())),
111 PathKind::Crate => segments.push(make::path_segment_crate()),
112 PathKind::Abs => is_abs = true,
113 PathKind::DollarCrate(_) => (),
114 }
115
116 segments.extend(
117 self.segments
118 .iter()
119 .map(|segment| make::path_segment(make::name_ref(&segment.to_string()))),
120 );
121 make::path_from_segments(segments, is_abs)
122 }
103} 123}
104 124
105#[derive(Debug, Clone, PartialEq, Eq, Hash)] 125#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -286,10 +306,8 @@ impl Display for ModPath {
286 }; 306 };
287 match self.kind { 307 match self.kind {
288 PathKind::Plain => {} 308 PathKind::Plain => {}
309 PathKind::Super(0) => add_segment("self")?,
289 PathKind::Super(n) => { 310 PathKind::Super(n) => {
290 if n == 0 {
291 add_segment("self")?;
292 }
293 for _ in 0..n { 311 for _ in 0..n {
294 add_segment("super")?; 312 add_segment("super")?;
295 } 313 }