aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assists/add_import.rs10
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs26
-rw-r--r--crates/ra_hir_def/src/path.rs5
-rw-r--r--crates/ra_hir_def/src/path/lower.rs4
-rw-r--r--crates/ra_hir_def/src/path/lower/lower_use.rs4
6 files changed, 34 insertions, 17 deletions
diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/assists/add_import.rs
index f81b4184a..ceffee9b8 100644
--- a/crates/ra_assists/src/assists/add_import.rs
+++ b/crates/ra_assists/src/assists/add_import.rs
@@ -582,8 +582,14 @@ fn collect_hir_path_segments(path: &hir::Path) -> Option<Vec<SmolStr>> {
582 hir::PathKind::Abs => ps.push("".into()), 582 hir::PathKind::Abs => ps.push("".into()),
583 hir::PathKind::Crate => ps.push("crate".into()), 583 hir::PathKind::Crate => ps.push("crate".into()),
584 hir::PathKind::Plain => {} 584 hir::PathKind::Plain => {}
585 hir::PathKind::Self_ => ps.push("self".into()), 585 hir::PathKind::Super(0) => ps.push("self".into()),
586 hir::PathKind::Super => ps.push("super".into()), 586 hir::PathKind::Super(lvl) => {
587 let mut chain = "super".to_string();
588 for _ in 0..*lvl {
589 chain += "::super";
590 }
591 ps.push(chain.into());
592 }
587 hir::PathKind::Type(_) | hir::PathKind::DollarCrate(_) => return None, 593 hir::PathKind::Type(_) | hir::PathKind::DollarCrate(_) => return None,
588 } 594 }
589 ps.extend(path.segments().iter().map(|it| it.name.to_string().into())); 595 ps.extend(path.segments().iter().map(|it| it.name.to_string().into()));
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 912a073ea..8bbf7ffa2 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -890,7 +890,7 @@ where
890 // We rewrite simple path `macro_name` to `self::macro_name` to force resolve in module scope only. 890 // We rewrite simple path `macro_name` to `self::macro_name` to force resolve in module scope only.
891 let mut path = mac.path.clone(); 891 let mut path = mac.path.clone();
892 if path.is_ident() { 892 if path.is_ident() {
893 path.kind = PathKind::Self_; 893 path.kind = PathKind::Super(0);
894 } 894 }
895 895
896 self.def_collector.unexpanded_macros.push(MacroDirective { 896 self.def_collector.unexpanded_macros.push(MacroDirective {
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index 4a249e7e7..a3bfc1542 100644
--- a/crates/ra_hir_def/src/nameres/path_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/path_resolution.rs
@@ -10,6 +10,8 @@
10//! 10//!
11//! `ReachedFixedPoint` signals about this. 11//! `ReachedFixedPoint` signals about this.
12 12
13use std::iter::successors;
14
13use hir_expand::name::Name; 15use hir_expand::name::Name;
14use ra_db::Edition; 16use ra_db::Edition;
15use test_utils::tested_by; 17use test_utils::tested_by;
@@ -97,9 +99,6 @@ impl CrateDefMap {
97 PathKind::Crate => { 99 PathKind::Crate => {
98 PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into()) 100 PerNs::types(ModuleId { krate: self.krate, local_id: self.root }.into())
99 } 101 }
100 PathKind::Self_ => {
101 PerNs::types(ModuleId { krate: self.krate, local_id: original_module }.into())
102 }
103 // plain import or absolute path in 2015: crate-relative with 102 // plain import or absolute path in 2015: crate-relative with
104 // fallback to extern prelude (with the simplification in 103 // fallback to extern prelude (with the simplification in
105 // rust-lang/rust#57745) 104 // rust-lang/rust#57745)
@@ -123,9 +122,22 @@ impl CrateDefMap {
123 log::debug!("resolving {:?} in module", segment); 122 log::debug!("resolving {:?} in module", segment);
124 self.resolve_name_in_module(db, original_module, &segment, prefer_module(idx)) 123 self.resolve_name_in_module(db, original_module, &segment, prefer_module(idx))
125 } 124 }
126 PathKind::Super => { 125 // PathKind::Self_ => {
127 if let Some(p) = self.modules[original_module].parent { 126 // PerNs::types(ModuleId { krate: self.krate, local_id: original_module }.into())
128 PerNs::types(ModuleId { krate: self.krate, local_id: p }.into()) 127 // }
128 // PathKind::Super => {
129 // if let Some(p) = self.modules[original_module].parent {
130 // PerNs::types(ModuleId { krate: self.krate, local_id: p }.into())
131 // } else {
132 // log::debug!("super path in root module");
133 // return ResolvePathResult::empty(ReachedFixedPoint::Yes);
134 // }
135 // }
136 PathKind::Super(lvl) => {
137 let m = successors(Some(original_module), |m| self.modules[*m].parent)
138 .nth(lvl as usize);
139 if let Some(local_id) = m {
140 PerNs::types(ModuleId { krate: self.krate, local_id }.into())
129 } else { 141 } else {
130 log::debug!("super path in root module"); 142 log::debug!("super path in root module");
131 return ResolvePathResult::empty(ReachedFixedPoint::Yes); 143 return ResolvePathResult::empty(ReachedFixedPoint::Yes);
@@ -170,7 +182,7 @@ impl CrateDefMap {
170 if module.krate != self.krate { 182 if module.krate != self.krate {
171 let path = ModPath { 183 let path = ModPath {
172 segments: path.segments[i..].to_vec(), 184 segments: path.segments[i..].to_vec(),
173 kind: PathKind::Self_, 185 kind: PathKind::Super(0),
174 }; 186 };
175 log::debug!("resolving {:?} in other crate", path); 187 log::debug!("resolving {:?} in other crate", path);
176 let defp_map = db.crate_def_map(module.krate); 188 let defp_map = db.crate_def_map(module.krate);
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 20d6d98ea..3b26e8337 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -56,7 +56,7 @@ impl ModPath {
56 } 56 }
57 57
58 pub fn is_self(&self) -> bool { 58 pub fn is_self(&self) -> bool {
59 self.kind == PathKind::Self_ && self.segments.is_empty() 59 self.kind == PathKind::Super(0) && self.segments.is_empty()
60 } 60 }
61 61
62 /// If this path is a single identifier, like `foo`, return its name. 62 /// If this path is a single identifier, like `foo`, return its name.
@@ -100,8 +100,7 @@ pub enum GenericArg {
100#[derive(Debug, Clone, PartialEq, Eq, Hash)] 100#[derive(Debug, Clone, PartialEq, Eq, Hash)]
101pub enum PathKind { 101pub enum PathKind {
102 Plain, 102 Plain,
103 Self_, 103 Super(u8),
104 Super,
105 Crate, 104 Crate,
106 // Absolute path 105 // Absolute path
107 Abs, 106 Abs,
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs
index a2e995198..c71b52d89 100644
--- a/crates/ra_hir_def/src/path/lower.rs
+++ b/crates/ra_hir_def/src/path/lower.rs
@@ -95,11 +95,11 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
95 break; 95 break;
96 } 96 }
97 ast::PathSegmentKind::SelfKw => { 97 ast::PathSegmentKind::SelfKw => {
98 kind = PathKind::Self_; 98 kind = PathKind::Super(0);
99 break; 99 break;
100 } 100 }
101 ast::PathSegmentKind::SuperKw => { 101 ast::PathSegmentKind::SuperKw => {
102 kind = PathKind::Super; 102 kind = PathKind::Super(1);
103 break; 103 break;
104 } 104 }
105 } 105 }
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 ea3fdb56c..062c02063 100644
--- a/crates/ra_hir_def/src/path/lower/lower_use.rs
+++ b/crates/ra_hir_def/src/path/lower/lower_use.rs
@@ -95,13 +95,13 @@ 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::Self_, iter::empty()) 98 ModPath::from_simple_segments(PathKind::Super(0), iter::empty())
99 } 99 }
100 ast::PathSegmentKind::SuperKw => { 100 ast::PathSegmentKind::SuperKw => {
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, iter::empty()) 104 ModPath::from_simple_segments(PathKind::Super(1), iter::empty())
105 } 105 }
106 ast::PathSegmentKind::Type { .. } => { 106 ast::PathSegmentKind::Type { .. } => {
107 // not allowed in imports 107 // not allowed in imports