use resolve_imports::ImportDirective;
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
use {Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, ToNameBinding};
-use {ModuleOrUniformRoot, PerNS, Resolver, ResolverArenas};
+use {ModuleOrUniformRoot, PerNS, Resolver, ResolverArenas, ExternPreludeEntry};
use Namespace::{self, TypeNS, ValueNS, MacroNS};
use {resolve_error, resolve_struct_error, ResolutionError};
use rustc_metadata::cstore::LoadedMacro;
use std::cell::Cell;
+use std::ptr;
use rustc_data_structures::sync::Lrc;
use syntax::ast::{Name, Ident};
let module =
self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX });
self.populate_module_if_necessary(module);
- if injected_crate_name().map_or(false, |name| item.ident.name == name) {
+ if injected_crate_name().map_or(false, |name| ident.name == name) {
self.injected_crate = Some(module);
}
let used = self.process_legacy_macro_imports(item, module, expansion);
let binding =
(module, ty::Visibility::Public, sp, expansion).to_name_binding(self.arenas);
+ if ptr::eq(self.current_module, self.graph_root) {
+ if let Some(entry) = self.extern_prelude.get(&ident.modern()) {
+ if expansion != Mark::root() && orig_name.is_some() &&
+ entry.extern_crate_item.is_none() {
+ self.session.span_err(item.span, "macro-expanded `extern crate` items \
+ cannot shadow names passed with \
+ `--extern`");
+ }
+ }
+ let entry = self.extern_prelude.entry(ident.modern())
+ .or_insert(ExternPreludeEntry {
+ extern_crate_item: None,
+ introduced_by_item: true,
+ });
+ entry.extern_crate_item = Some(binding);
+ if orig_name.is_some() {
+ entry.introduced_by_item = true;
+ }
+ }
let directive = self.arenas.alloc_import_directive(ImportDirective {
root_id: item.id,
id: item.id,
parent,
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
- subclass: ImportDirectiveSubclass::ExternCrate(orig_name),
+ subclass: ImportDirectiveSubclass::ExternCrate {
+ source: orig_name,
+ target: ident,
+ },
root_span: item.span,
span: item.span,
module_path: Vec::new(),
ItemKind::GlobalAsm(..) => {}
- ItemKind::Mod(..) if item.ident == keywords::Invalid.ident() => {} // Crate root
+ ItemKind::Mod(..) if ident == keywords::Invalid.ident() => {} // Crate root
ItemKind::Mod(..) => {
let def_id = self.definitions.local_def_id(item.id);