diff options
Diffstat (limited to 'crates/ra_hir_def/src/path.rs')
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index e84efe2ab..bfa921de2 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -76,6 +76,19 @@ impl ModPath { | |||
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | /// Returns the number of segments in the path (counting special segments like `$crate` and | ||
80 | /// `super`). | ||
81 | pub fn len(&self) -> usize { | ||
82 | self.segments.len() | ||
83 | + match self.kind { | ||
84 | PathKind::Plain => 0, | ||
85 | PathKind::Super(i) => i as usize, | ||
86 | PathKind::Crate => 1, | ||
87 | PathKind::Abs => 0, | ||
88 | PathKind::DollarCrate(_) => 1, | ||
89 | } | ||
90 | } | ||
91 | |||
79 | pub fn is_ident(&self) -> bool { | 92 | pub fn is_ident(&self) -> bool { |
80 | self.kind == PathKind::Plain && self.segments.len() == 1 | 93 | self.kind == PathKind::Plain && self.segments.len() == 1 |
81 | } | 94 | } |
@@ -273,7 +286,7 @@ impl From<Name> for ModPath { | |||
273 | impl Display for ModPath { | 286 | impl Display for ModPath { |
274 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 287 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
275 | let mut first_segment = true; | 288 | let mut first_segment = true; |
276 | let mut add_segment = |s| { | 289 | let mut add_segment = |s| -> fmt::Result { |
277 | if !first_segment { | 290 | if !first_segment { |
278 | f.write_str("::")?; | 291 | f.write_str("::")?; |
279 | } | 292 | } |