aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/find_path.rs12
-rw-r--r--crates/ra_hir_def/src/path.rs11
-rw-r--r--crates/ra_hir_def/src/path/lower/lower_use.rs8
3 files changed, 14 insertions, 17 deletions
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index f7dc8acb7..8cc2fb160 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -35,7 +35,7 @@ fn find_path_inner(
35 let def_map = db.crate_def_map(from.krate); 35 let def_map = db.crate_def_map(from.krate);
36 let from_scope: &crate::item_scope::ItemScope = &def_map.modules[from.local_id].scope; 36 let from_scope: &crate::item_scope::ItemScope = &def_map.modules[from.local_id].scope;
37 if let Some((name, _)) = from_scope.name_of(item) { 37 if let Some((name, _)) = from_scope.name_of(item) {
38 return Some(ModPath::from_simple_segments(PathKind::Plain, vec![name.clone()])); 38 return Some(ModPath::from_segments(PathKind::Plain, vec![name.clone()]));
39 } 39 }
40 40
41 // - if the item is the crate root, return `crate` 41 // - if the item is the crate root, return `crate`
@@ -45,12 +45,12 @@ fn find_path_inner(
45 local_id: def_map.root, 45 local_id: def_map.root,
46 })) 46 }))
47 { 47 {
48 return Some(ModPath::from_simple_segments(PathKind::Crate, Vec::new())); 48 return Some(ModPath::from_segments(PathKind::Crate, Vec::new()));
49 } 49 }
50 50
51 // - if the item is the module we're in, use `self` 51 // - if the item is the module we're in, use `self`
52 if item == ItemInNs::Types(from.into()) { 52 if item == ItemInNs::Types(from.into()) {
53 return Some(ModPath::from_simple_segments(PathKind::Super(0), Vec::new())); 53 return Some(ModPath::from_segments(PathKind::Super(0), Vec::new()));
54 } 54 }
55 55
56 // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly) 56 // - if the item is the parent module, use `super` (this is not used recursively, since `super::super` is ugly)
@@ -61,14 +61,14 @@ fn find_path_inner(
61 local_id: parent_id, 61 local_id: parent_id,
62 })) 62 }))
63 { 63 {
64 return Some(ModPath::from_simple_segments(PathKind::Super(1), Vec::new())); 64 return Some(ModPath::from_segments(PathKind::Super(1), Vec::new()));
65 } 65 }
66 } 66 }
67 67
68 // - if the item is the crate root of a dependency crate, return the name from the extern prelude 68 // - if the item is the crate root of a dependency crate, return the name from the extern prelude
69 for (name, def_id) in &def_map.extern_prelude { 69 for (name, def_id) in &def_map.extern_prelude {
70 if item == ItemInNs::Types(*def_id) { 70 if item == ItemInNs::Types(*def_id) {
71 return Some(ModPath::from_simple_segments(PathKind::Plain, vec![name.clone()])); 71 return Some(ModPath::from_segments(PathKind::Plain, vec![name.clone()]));
72 } 72 }
73 } 73 }
74 74
@@ -79,7 +79,7 @@ fn find_path_inner(
79 &prelude_def_map.modules[prelude_module.local_id].scope; 79 &prelude_def_map.modules[prelude_module.local_id].scope;
80 if let Some((name, vis)) = prelude_scope.name_of(item) { 80 if let Some((name, vis)) = prelude_scope.name_of(item) {
81 if vis.is_visible_from(db, from) { 81 if vis.is_visible_from(db, from) {
82 return Some(ModPath::from_simple_segments(PathKind::Plain, vec![name.clone()])); 82 return Some(ModPath::from_segments(PathKind::Plain, vec![name.clone()]));
83 } 83 }
84 } 84 }
85 } 85 }
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 9f93a5424..ab290e2c9 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -39,10 +39,7 @@ impl ModPath {
39 lower::lower_path(path, hygiene).map(|it| it.mod_path) 39 lower::lower_path(path, hygiene).map(|it| it.mod_path)
40 } 40 }
41 41
42 pub fn from_simple_segments( 42 pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath {
43 kind: PathKind,
44 segments: impl IntoIterator<Item = Name>,
45 ) -> ModPath {
46 let segments = segments.into_iter().collect::<Vec<_>>(); 43 let segments = segments.into_iter().collect::<Vec<_>>();
47 ModPath { kind, segments } 44 ModPath { kind, segments }
48 } 45 }
@@ -240,7 +237,7 @@ impl From<Name> for Path {
240 fn from(name: Name) -> Path { 237 fn from(name: Name) -> Path {
241 Path { 238 Path {
242 type_anchor: None, 239 type_anchor: None,
243 mod_path: ModPath::from_simple_segments(PathKind::Plain, iter::once(name)), 240 mod_path: ModPath::from_segments(PathKind::Plain, iter::once(name)),
244 generic_args: vec![None], 241 generic_args: vec![None],
245 } 242 }
246 } 243 }
@@ -248,7 +245,7 @@ impl From<Name> for Path {
248 245
249impl From<Name> for ModPath { 246impl From<Name> for ModPath {
250 fn from(name: Name) -> ModPath { 247 fn from(name: Name) -> ModPath {
251 ModPath::from_simple_segments(PathKind::Plain, iter::once(name)) 248 ModPath::from_segments(PathKind::Plain, iter::once(name))
252 } 249 }
253} 250}
254 251
@@ -311,7 +308,7 @@ macro_rules! __known_path {
311macro_rules! __path { 308macro_rules! __path {
312 ($start:ident $(:: $seg:ident)*) => ({ 309 ($start:ident $(:: $seg:ident)*) => ({
313 $crate::__known_path!($start $(:: $seg)*); 310 $crate::__known_path!($start $(:: $seg)*);
314 $crate::path::ModPath::from_simple_segments($crate::path::PathKind::Abs, vec![ 311 $crate::path::ModPath::from_segments($crate::path::PathKind::Abs, vec![
315 $crate::path::__name![$start], $($crate::path::__name![$seg],)* 312 $crate::path::__name![$start], $($crate::path::__name![$seg],)*
316 ]) 313 ])
317 }); 314 });
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs
index 3218eaf0a..531878174 100644
--- a/crates/ra_hir_def/src/path/lower/lower_use.rs
+++ b/crates/ra_hir_def/src/path/lower/lower_use.rs
@@ -84,7 +84,7 @@ fn convert_path(prefix: Option<ModPath>, path: ast::Path, hygiene: &Hygiene) ->
84 res 84 res
85 } 85 }
86 Either::Right(crate_id) => { 86 Either::Right(crate_id) => {
87 return Some(ModPath::from_simple_segments( 87 return Some(ModPath::from_segments(
88 PathKind::DollarCrate(crate_id), 88 PathKind::DollarCrate(crate_id),
89 iter::empty(), 89 iter::empty(),
90 )) 90 ))
@@ -95,19 +95,19 @@ fn convert_path(prefix: Option<ModPath>, path: ast::Path, hygiene: &Hygiene) ->
95 if prefix.is_some() { 95 if prefix.is_some() {
96 return None; 96 return None;
97 } 97 }
98 ModPath::from_simple_segments(PathKind::Crate, iter::empty()) 98 ModPath::from_segments(PathKind::Crate, iter::empty())
99 } 99 }
100 ast::PathSegmentKind::SelfKw => { 100 ast::PathSegmentKind::SelfKw => {
101 if prefix.is_some() { 101 if prefix.is_some() {
102 return None; 102 return None;
103 } 103 }
104 ModPath::from_simple_segments(PathKind::Super(0), iter::empty()) 104 ModPath::from_segments(PathKind::Super(0), iter::empty())
105 } 105 }
106 ast::PathSegmentKind::SuperKw => { 106 ast::PathSegmentKind::SuperKw => {
107 if prefix.is_some() { 107 if prefix.is_some() {
108 return None; 108 return None;
109 } 109 }
110 ModPath::from_simple_segments(PathKind::Super(1), iter::empty()) 110 ModPath::from_segments(PathKind::Super(1), iter::empty())
111 } 111 }
112 ast::PathSegmentKind::Type { .. } => { 112 ast::PathSegmentKind::Type { .. } => {
113 // not allowed in imports 113 // not allowed in imports