diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-17 14:39:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-17 14:39:07 +0000 |
commit | b90f9e6d594584ab003a33142bb2193aea6f8bcd (patch) | |
tree | 05d3cf8ec0fcca490ffbac1534d3a08c2eeb854c /crates/ra_hir_def | |
parent | f51a3fed9f8227a2b3bc8521b529cb9734ff0e7e (diff) | |
parent | aca022f1d49a6d945f3ef4f8c781d7337120b68d (diff) |
Merge #2581
2581: Refactor PathKind r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/path_resolution.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path/lower/lower_use.rs | 4 |
5 files changed, 26 insertions, 15 deletions
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 | ||
13 | use std::iter::successors; | ||
14 | |||
13 | use hir_expand::name::Name; | 15 | use hir_expand::name::Name; |
14 | use ra_db::Edition; | 16 | use ra_db::Edition; |
15 | use test_utils::tested_by; | 17 | use 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)] |
101 | pub enum PathKind { | 101 | pub 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 |