|
11 | 11 | use self::ImportDirectiveSubclass::*;
|
12 | 12 |
|
13 | 13 | use {AmbiguityError, AmbiguityKind, AmbiguityErrorMisc};
|
14 |
| -use {CrateLint, Module, ModuleOrUniformRoot, PerNS, UniformRootKind, Weak}; |
| 14 | +use {CrateLint, Module, ModuleOrUniformRoot, PerNS, ScopeSet, Weak}; |
15 | 15 | use Namespace::{self, TypeNS, MacroNS};
|
16 | 16 | use {NameBinding, NameBindingKind, ToNameBinding, PathResult, PrivacyError};
|
17 | 17 | use {Resolver, Segment};
|
@@ -162,45 +162,42 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
|
162 | 162 | ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
163 | 163 | let module = match module {
|
164 | 164 | ModuleOrUniformRoot::Module(module) => module,
|
165 |
| - ModuleOrUniformRoot::UniformRoot(uniform_root_kind) => { |
| 165 | + ModuleOrUniformRoot::ExternPrelude => { |
166 | 166 | assert!(!restricted_shadowing);
|
167 |
| - match uniform_root_kind { |
168 |
| - UniformRootKind::ExternPrelude => { |
169 |
| - return if let Some(binding) = self.extern_prelude_get(ident, !record_used) { |
170 |
| - Ok(binding) |
171 |
| - } else if !self.graph_root.unresolved_invocations.borrow().is_empty() { |
172 |
| - // Macro-expanded `extern crate` items can add names to extern prelude. |
173 |
| - Err((Undetermined, Weak::No)) |
174 |
| - } else { |
175 |
| - Err((Determined, Weak::No)) |
176 |
| - } |
177 |
| - } |
178 |
| - UniformRootKind::CurrentScope => { |
179 |
| - let parent_scope = |
180 |
| - parent_scope.expect("no parent scope for a single-segment import"); |
181 |
| - |
182 |
| - if ns == TypeNS { |
183 |
| - if ident.name == keywords::Crate.name() || |
184 |
| - ident.name == keywords::DollarCrate.name() { |
185 |
| - let module = self.resolve_crate_root(ident); |
186 |
| - let binding = (module, ty::Visibility::Public, |
187 |
| - module.span, Mark::root()) |
188 |
| - .to_name_binding(self.arenas); |
189 |
| - return Ok(binding); |
190 |
| - } else if ident.name == keywords::Super.name() || |
191 |
| - ident.name == keywords::SelfValue.name() { |
192 |
| - // FIXME: Implement these with renaming requirements so that e.g. |
193 |
| - // `use super;` doesn't work, but `use super as name;` does. |
194 |
| - // Fall through here to get an error from `early_resolve_...`. |
195 |
| - } |
196 |
| - } |
197 |
| - |
198 |
| - let binding = self.early_resolve_ident_in_lexical_scope( |
199 |
| - ident, ns, None, true, parent_scope, record_used, record_used, path_span |
200 |
| - ); |
201 |
| - return binding.map_err(|determinacy| (determinacy, Weak::No)); |
| 167 | + return if let Some(binding) = self.extern_prelude_get(ident, !record_used) { |
| 168 | + Ok(binding) |
| 169 | + } else if !self.graph_root.unresolved_invocations.borrow().is_empty() { |
| 170 | + // Macro-expanded `extern crate` items can add names to extern prelude. |
| 171 | + Err((Undetermined, Weak::No)) |
| 172 | + } else { |
| 173 | + Err((Determined, Weak::No)) |
| 174 | + } |
| 175 | + } |
| 176 | + ModuleOrUniformRoot::CurrentScope => { |
| 177 | + assert!(!restricted_shadowing); |
| 178 | + let parent_scope = |
| 179 | + parent_scope.expect("no parent scope for a single-segment import"); |
| 180 | + |
| 181 | + if ns == TypeNS { |
| 182 | + if ident.name == keywords::Crate.name() || |
| 183 | + ident.name == keywords::DollarCrate.name() { |
| 184 | + let module = self.resolve_crate_root(ident); |
| 185 | + let binding = (module, ty::Visibility::Public, |
| 186 | + module.span, Mark::root()) |
| 187 | + .to_name_binding(self.arenas); |
| 188 | + return Ok(binding); |
| 189 | + } else if ident.name == keywords::Super.name() || |
| 190 | + ident.name == keywords::SelfValue.name() { |
| 191 | + // FIXME: Implement these with renaming requirements so that e.g. |
| 192 | + // `use super;` doesn't work, but `use super as name;` does. |
| 193 | + // Fall through here to get an error from `early_resolve_...`. |
202 | 194 | }
|
203 | 195 | }
|
| 196 | + |
| 197 | + let binding = self.early_resolve_ident_in_lexical_scope( |
| 198 | + ident, ScopeSet::Import(ns), parent_scope, record_used, record_used, path_span |
| 199 | + ); |
| 200 | + return binding.map_err(|determinacy| (determinacy, Weak::No)); |
204 | 201 | }
|
205 | 202 | };
|
206 | 203 |
|
@@ -333,7 +330,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
|
333 | 330 | }
|
334 | 331 | let module = match glob_import.imported_module.get() {
|
335 | 332 | Some(ModuleOrUniformRoot::Module(module)) => module,
|
336 |
| - Some(ModuleOrUniformRoot::UniformRoot(_)) => continue, |
| 333 | + Some(_) => continue, |
337 | 334 | None => return Err((Undetermined, Weak::Yes)),
|
338 | 335 | };
|
339 | 336 | let (orig_current_module, mut ident) = (self.current_module, ident.modern());
|
@@ -966,9 +963,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
966 | 963 |
|
967 | 964 | return if all_ns_failed {
|
968 | 965 | let resolutions = match module {
|
969 |
| - ModuleOrUniformRoot::Module(module) => |
970 |
| - Some(module.resolutions.borrow()), |
971 |
| - ModuleOrUniformRoot::UniformRoot(_) => None, |
| 966 | + ModuleOrUniformRoot::Module(module) => Some(module.resolutions.borrow()), |
| 967 | + _ => None, |
972 | 968 | };
|
973 | 969 | let resolutions = resolutions.as_ref().into_iter().flat_map(|r| r.iter());
|
974 | 970 | let names = resolutions.filter_map(|(&(ref i, _), resolution)| {
|
@@ -1006,7 +1002,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
1006 | 1002 | format!("no `{}` in the root{}", ident, lev_suggestion)
|
1007 | 1003 | }
|
1008 | 1004 | }
|
1009 |
| - ModuleOrUniformRoot::UniformRoot(_) => { |
| 1005 | + _ => { |
1010 | 1006 | if !ident.is_path_segment_keyword() {
|
1011 | 1007 | format!("no `{}` external crate{}", ident, lev_suggestion)
|
1012 | 1008 | } else {
|
@@ -1107,9 +1103,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
1107 | 1103 | fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'b>) {
|
1108 | 1104 | let module = match directive.imported_module.get().unwrap() {
|
1109 | 1105 | ModuleOrUniformRoot::Module(module) => module,
|
1110 |
| - ModuleOrUniformRoot::UniformRoot(_) => { |
1111 |
| - self.session.span_err(directive.span, |
1112 |
| - "cannot glob-import all possible crates"); |
| 1106 | + _ => { |
| 1107 | + self.session.span_err(directive.span, "cannot glob-import all possible crates"); |
1113 | 1108 | return;
|
1114 | 1109 | }
|
1115 | 1110 | };
|
|
0 commit comments