aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/path.rs')
-rw-r--r--crates/ra_hir/src/path.rs44
1 files changed, 11 insertions, 33 deletions
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs
index cb0a04500..6a24c8aa7 100644
--- a/crates/ra_hir/src/path.rs
+++ b/crates/ra_hir/src/path.rs
@@ -66,14 +66,9 @@ impl Path {
66 66
67 match segment.kind()? { 67 match segment.kind()? {
68 ast::PathSegmentKind::Name(name) => { 68 ast::PathSegmentKind::Name(name) => {
69 let args = segment 69 let args =
70 .type_arg_list() 70 segment.type_arg_list().and_then(GenericArgs::from_ast).map(Arc::new);
71 .and_then(GenericArgs::from_ast) 71 let segment = PathSegment { name: name.as_name(), args_and_bindings: args };
72 .map(Arc::new);
73 let segment = PathSegment {
74 name: name.as_name(),
75 args_and_bindings: args,
76 };
77 segments.push(segment); 72 segments.push(segment);
78 } 73 }
79 ast::PathSegmentKind::CrateKw => { 74 ast::PathSegmentKind::CrateKw => {
@@ -153,10 +148,7 @@ impl From<Name> for Path {
153 fn from(name: Name) -> Path { 148 fn from(name: Name) -> Path {
154 Path { 149 Path {
155 kind: PathKind::Plain, 150 kind: PathKind::Plain,
156 segments: vec![PathSegment { 151 segments: vec![PathSegment { name, args_and_bindings: None }],
157 name,
158 args_and_bindings: None,
159 }],
160 } 152 }
161 } 153 }
162} 154}
@@ -209,18 +201,13 @@ fn expand_use_tree<'a>(
209} 201}
210 202
211fn convert_path(prefix: Option<Path>, path: &ast::Path) -> Option<Path> { 203fn convert_path(prefix: Option<Path>, path: &ast::Path) -> Option<Path> {
212 let prefix = if let Some(qual) = path.qualifier() { 204 let prefix =
213 Some(convert_path(prefix, qual)?) 205 if let Some(qual) = path.qualifier() { Some(convert_path(prefix, qual)?) } else { prefix };
214 } else {
215 prefix
216 };
217 let segment = path.segment()?; 206 let segment = path.segment()?;
218 let res = match segment.kind()? { 207 let res = match segment.kind()? {
219 ast::PathSegmentKind::Name(name) => { 208 ast::PathSegmentKind::Name(name) => {
220 let mut res = prefix.unwrap_or_else(|| Path { 209 let mut res = prefix
221 kind: PathKind::Plain, 210 .unwrap_or_else(|| Path { kind: PathKind::Plain, segments: Vec::with_capacity(1) });
222 segments: Vec::with_capacity(1),
223 });
224 res.segments.push(PathSegment { 211 res.segments.push(PathSegment {
225 name: name.as_name(), 212 name: name.as_name(),
226 args_and_bindings: None, // no type args in use 213 args_and_bindings: None, // no type args in use
@@ -231,28 +218,19 @@ fn convert_path(prefix: Option<Path>, path: &ast::Path) -> Option<Path> {
231 if prefix.is_some() { 218 if prefix.is_some() {
232 return None; 219 return None;
233 } 220 }
234 Path { 221 Path { kind: PathKind::Crate, segments: Vec::new() }
235 kind: PathKind::Crate,
236 segments: Vec::new(),
237 }
238 } 222 }
239 ast::PathSegmentKind::SelfKw => { 223 ast::PathSegmentKind::SelfKw => {
240 if prefix.is_some() { 224 if prefix.is_some() {
241 return None; 225 return None;
242 } 226 }
243 Path { 227 Path { kind: PathKind::Self_, segments: Vec::new() }
244 kind: PathKind::Self_,
245 segments: Vec::new(),
246 }
247 } 228 }
248 ast::PathSegmentKind::SuperKw => { 229 ast::PathSegmentKind::SuperKw => {
249 if prefix.is_some() { 230 if prefix.is_some() {
250 return None; 231 return None;
251 } 232 }
252 Path { 233 Path { kind: PathKind::Super, segments: Vec::new() }
253 kind: PathKind::Super,
254 segments: Vec::new(),
255 }
256 } 234 }
257 }; 235 };
258 Some(res) 236 Some(res)