diff options
Diffstat (limited to 'crates/ra_hir_def/src/path.rs')
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index e38d924fa..1e2da6b48 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -26,8 +26,6 @@ pub enum PathKind { | |||
26 | Crate, | 26 | Crate, |
27 | /// Absolute path (::foo) | 27 | /// Absolute path (::foo) |
28 | Abs, | 28 | Abs, |
29 | /// Type based path like `<T>::foo` | ||
30 | Type(Box<TypeRef>), | ||
31 | /// `$crate` from macro expansion | 29 | /// `$crate` from macro expansion |
32 | DollarCrate(CrateId), | 30 | DollarCrate(CrateId), |
33 | } | 31 | } |
@@ -84,6 +82,8 @@ impl ModPath { | |||
84 | 82 | ||
85 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 83 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
86 | pub struct Path { | 84 | pub struct Path { |
85 | /// Type based path like `<T>::foo` | ||
86 | type_anchor: Option<Box<TypeRef>>, | ||
87 | mod_path: ModPath, | 87 | mod_path: ModPath, |
88 | /// Invariant: the same len as self.path.segments | 88 | /// Invariant: the same len as self.path.segments |
89 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 89 | generic_args: Vec<Option<Arc<GenericArgs>>>, |
@@ -126,7 +126,7 @@ impl Path { | |||
126 | 126 | ||
127 | /// Converts an `ast::NameRef` into a single-identifier `Path`. | 127 | /// Converts an `ast::NameRef` into a single-identifier `Path`. |
128 | pub(crate) fn from_name_ref(name_ref: &ast::NameRef) -> Path { | 128 | pub(crate) fn from_name_ref(name_ref: &ast::NameRef) -> Path { |
129 | Path { mod_path: name_ref.as_name().into(), generic_args: vec![None] } | 129 | Path { type_anchor: None, mod_path: name_ref.as_name().into(), generic_args: vec![None] } |
130 | } | 130 | } |
131 | 131 | ||
132 | /// `true` if this path is just a standalone `self` | 132 | /// `true` if this path is just a standalone `self` |
@@ -138,6 +138,10 @@ impl Path { | |||
138 | &self.mod_path.kind | 138 | &self.mod_path.kind |
139 | } | 139 | } |
140 | 140 | ||
141 | pub fn type_anchor(&self) -> Option<&TypeRef> { | ||
142 | self.type_anchor.as_ref().map(|it| &**it) | ||
143 | } | ||
144 | |||
141 | pub fn segments(&self) -> PathSegments<'_> { | 145 | pub fn segments(&self) -> PathSegments<'_> { |
142 | PathSegments { | 146 | PathSegments { |
143 | segments: self.mod_path.segments.as_slice(), | 147 | segments: self.mod_path.segments.as_slice(), |
@@ -154,6 +158,7 @@ impl Path { | |||
154 | return None; | 158 | return None; |
155 | } | 159 | } |
156 | let res = Path { | 160 | let res = Path { |
161 | type_anchor: self.type_anchor.clone(), | ||
157 | mod_path: ModPath { | 162 | mod_path: ModPath { |
158 | kind: self.mod_path.kind.clone(), | 163 | kind: self.mod_path.kind.clone(), |
159 | segments: self.mod_path.segments[..self.mod_path.segments.len() - 1].to_vec(), | 164 | segments: self.mod_path.segments[..self.mod_path.segments.len() - 1].to_vec(), |
@@ -226,6 +231,7 @@ impl GenericArgs { | |||
226 | impl From<Name> for Path { | 231 | impl From<Name> for Path { |
227 | fn from(name: Name) -> Path { | 232 | fn from(name: Name) -> Path { |
228 | Path { | 233 | Path { |
234 | type_anchor: None, | ||
229 | mod_path: ModPath::from_simple_segments(PathKind::Plain, iter::once(name)), | 235 | mod_path: ModPath::from_simple_segments(PathKind::Plain, iter::once(name)), |
230 | generic_args: vec![None], | 236 | generic_args: vec![None], |
231 | } | 237 | } |