diff options
author | uHOOCCOOHu <[email protected]> | 2019-09-15 12:48:24 +0100 |
---|---|---|
committer | uHOOCCOOHu <[email protected]> | 2019-09-15 12:48:24 +0100 |
commit | de9670fe456d89f97e8044d4e0919d2c16d1087f (patch) | |
tree | 495c5d987e0f2cd754c3e4e6b20adafcf1f23403 /crates/ra_hir/src/path.rs | |
parent | 4926bed42680d329f906be93450bec6b2ba0e99b (diff) |
Move store TypeRef of type based path in PathKind
Diffstat (limited to 'crates/ra_hir/src/path.rs')
-rw-r--r-- | crates/ra_hir/src/path.rs | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index 7c19fda14..9e449f6cc 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs | |||
@@ -10,7 +10,6 @@ use crate::{name, type_ref::TypeRef, AsName, Name}; | |||
10 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 10 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
11 | pub struct Path { | 11 | pub struct Path { |
12 | pub kind: PathKind, | 12 | pub kind: PathKind, |
13 | pub type_ref: Option<Box<TypeRef>>, | ||
14 | pub segments: Vec<PathSegment>, | 13 | pub segments: Vec<PathSegment>, |
15 | } | 14 | } |
16 | 15 | ||
@@ -43,7 +42,7 @@ pub enum GenericArg { | |||
43 | // or lifetime... | 42 | // or lifetime... |
44 | } | 43 | } |
45 | 44 | ||
46 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 45 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
47 | pub enum PathKind { | 46 | pub enum PathKind { |
48 | Plain, | 47 | Plain, |
49 | Self_, | 48 | Self_, |
@@ -52,7 +51,7 @@ pub enum PathKind { | |||
52 | // Absolute path | 51 | // Absolute path |
53 | Abs, | 52 | Abs, |
54 | // Type based path like `<T>::foo` | 53 | // Type based path like `<T>::foo` |
55 | Type, | 54 | Type(Box<TypeRef>), |
56 | } | 55 | } |
57 | 56 | ||
58 | impl Path { | 57 | impl Path { |
@@ -69,7 +68,6 @@ impl Path { | |||
69 | pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> Path { | 68 | pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> Path { |
70 | Path { | 69 | Path { |
71 | kind, | 70 | kind, |
72 | type_ref: None, | ||
73 | segments: segments | 71 | segments: segments |
74 | .into_iter() | 72 | .into_iter() |
75 | .map(|name| PathSegment { name, args_and_bindings: None }) | 73 | .map(|name| PathSegment { name, args_and_bindings: None }) |
@@ -81,7 +79,6 @@ impl Path { | |||
81 | pub fn from_ast(mut path: ast::Path) -> Option<Path> { | 79 | pub fn from_ast(mut path: ast::Path) -> Option<Path> { |
82 | let mut kind = PathKind::Plain; | 80 | let mut kind = PathKind::Plain; |
83 | let mut segments = Vec::new(); | 81 | let mut segments = Vec::new(); |
84 | let mut path_type_ref = None; | ||
85 | loop { | 82 | loop { |
86 | let segment = path.segment()?; | 83 | let segment = path.segment()?; |
87 | 84 | ||
@@ -112,8 +109,7 @@ impl Path { | |||
112 | match trait_ref { | 109 | match trait_ref { |
113 | // <T>::foo | 110 | // <T>::foo |
114 | None => { | 111 | None => { |
115 | kind = PathKind::Type; | 112 | kind = PathKind::Type(Box::new(self_type)); |
116 | path_type_ref = Some(Box::new(self_type)); | ||
117 | } | 113 | } |
118 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo | 114 | // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo |
119 | Some(trait_ref) => { | 115 | Some(trait_ref) => { |
@@ -154,7 +150,7 @@ impl Path { | |||
154 | }; | 150 | }; |
155 | } | 151 | } |
156 | segments.reverse(); | 152 | segments.reverse(); |
157 | return Some(Path { kind, type_ref: path_type_ref, segments }); | 153 | return Some(Path { kind, segments }); |
158 | 154 | ||
159 | fn qualifier(path: &ast::Path) -> Option<ast::Path> { | 155 | fn qualifier(path: &ast::Path) -> Option<ast::Path> { |
160 | if let Some(q) = path.qualifier() { | 156 | if let Some(q) = path.qualifier() { |
@@ -309,11 +305,8 @@ fn convert_path(prefix: Option<Path>, path: ast::Path) -> Option<Path> { | |||
309 | let res = match segment.kind()? { | 305 | let res = match segment.kind()? { |
310 | ast::PathSegmentKind::Name(name) => { | 306 | ast::PathSegmentKind::Name(name) => { |
311 | // no type args in use | 307 | // no type args in use |
312 | let mut res = prefix.unwrap_or_else(|| Path { | 308 | let mut res = prefix |
313 | kind: PathKind::Plain, | 309 | .unwrap_or_else(|| Path { kind: PathKind::Plain, segments: Vec::with_capacity(1) }); |
314 | type_ref: None, | ||
315 | segments: Vec::with_capacity(1), | ||
316 | }); | ||
317 | res.segments.push(PathSegment { | 310 | res.segments.push(PathSegment { |
318 | name: name.as_name(), | 311 | name: name.as_name(), |
319 | args_and_bindings: None, // no type args in use | 312 | args_and_bindings: None, // no type args in use |