aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-09-29 11:29:33 +0100
committerGitHub <[email protected]>2020-09-29 11:29:33 +0100
commit18c62c8a39d95ce3bb10ff5446bb589b1128a090 (patch)
treef829779003722fb50082b5aa55a725aed841d449 /crates/hir_def/src
parent7b674f9ab491fdd01278c21f539e65239518e296 (diff)
parentf2ae412ccfa96c4bde42f0b004594c4d6fa54634 (diff)
Merge #6019
6019: Remove make::path_from_text r=matklad a=Veykril This removes the `make::path_from_text` function, which according to a note should've been private. I removed it since it didn't really serve a purpose as it was simply wrapping `make::ast_from_text`. Co-authored-by: Lukas Wirth <[email protected]>
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 }