diff options
author | Mikhail Rakhmanov <[email protected]> | 2020-06-13 07:42:15 +0100 |
---|---|---|
committer | Mikhail Rakhmanov <[email protected]> | 2020-06-13 07:42:15 +0100 |
commit | 16bbf4ab7f132e6e5e5318dccdef9a5d71afdd7f (patch) | |
tree | 4b79fa8c046be56b02427ba843e70cdf3ac05767 /crates/ra_hir_def/src/path.rs | |
parent | eeb8b9e236796da8734ba81a49164864497f7226 (diff) | |
parent | b56ad148db0c69eb279c225f45d324b4e80e7367 (diff) |
Merge branch 'master' into keyword_completion
# Conflicts:
# docs/user/generated_features.adoc
Diffstat (limited to 'crates/ra_hir_def/src/path.rs')
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index e84efe2ab..ba16442bd 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 | } |
@@ -310,16 +323,16 @@ pub use hir_expand::name as __name; | |||
310 | 323 | ||
311 | #[macro_export] | 324 | #[macro_export] |
312 | macro_rules! __known_path { | 325 | macro_rules! __known_path { |
313 | (std::iter::IntoIterator) => {}; | 326 | (core::iter::IntoIterator) => {}; |
314 | (std::result::Result) => {}; | 327 | (core::result::Result) => {}; |
315 | (std::ops::Range) => {}; | 328 | (core::ops::Range) => {}; |
316 | (std::ops::RangeFrom) => {}; | 329 | (core::ops::RangeFrom) => {}; |
317 | (std::ops::RangeFull) => {}; | 330 | (core::ops::RangeFull) => {}; |
318 | (std::ops::RangeTo) => {}; | 331 | (core::ops::RangeTo) => {}; |
319 | (std::ops::RangeToInclusive) => {}; | 332 | (core::ops::RangeToInclusive) => {}; |
320 | (std::ops::RangeInclusive) => {}; | 333 | (core::ops::RangeInclusive) => {}; |
321 | (std::future::Future) => {}; | 334 | (core::future::Future) => {}; |
322 | (std::ops::Try) => {}; | 335 | (core::ops::Try) => {}; |
323 | ($path:path) => { | 336 | ($path:path) => { |
324 | compile_error!("Please register your known path in the path module") | 337 | compile_error!("Please register your known path in the path module") |
325 | }; | 338 | }; |