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