2015-03-15 16:44:19 -05:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
use self::ImportDirectiveSubclass::*;
|
|
|
|
|
|
|
|
use Module;
|
|
|
|
use Namespace::{self, TypeNS, ValueNS};
|
2016-07-27 21:34:01 -05:00
|
|
|
use {NameBinding, NameBindingKind, PrivacyError, ToNameBinding};
|
2015-03-15 16:44:19 -05:00
|
|
|
use ResolveResult;
|
2016-01-13 19:42:45 -06:00
|
|
|
use ResolveResult::*;
|
2015-03-15 16:44:19 -05:00
|
|
|
use Resolver;
|
2016-03-12 20:53:22 -06:00
|
|
|
use UseLexicalScopeFlag::DontUseLexicalScope;
|
2015-03-15 16:44:19 -05:00
|
|
|
use {names_to_string, module_to_string};
|
2015-07-14 12:42:38 -05:00
|
|
|
use {resolve_error, ResolutionError};
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-04-09 18:19:53 -05:00
|
|
|
use rustc::ty;
|
2016-07-28 11:17:01 -05:00
|
|
|
use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
|
2016-03-29 04:54:26 -05:00
|
|
|
use rustc::hir::def::*;
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2015-08-16 05:32:28 -05:00
|
|
|
use syntax::ast::{NodeId, Name};
|
2015-12-14 11:06:31 -06:00
|
|
|
use syntax::util::lev_distance::find_best_match_for_name;
|
2016-06-21 17:08:13 -05:00
|
|
|
use syntax_pos::{Span, DUMMY_SP};
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-03-30 17:21:56 -05:00
|
|
|
use std::cell::{Cell, RefCell};
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-06-27 20:45:54 -05:00
|
|
|
impl<'a> Resolver<'a> {
|
|
|
|
pub fn resolve_imports(&mut self) {
|
|
|
|
ImportResolver { resolver: self }.resolve_imports();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-15 16:44:19 -05:00
|
|
|
/// Contains data for specific types of import directives.
|
2016-02-13 15:49:16 -06:00
|
|
|
#[derive(Clone, Debug)]
|
2015-03-15 16:44:19 -05:00
|
|
|
pub enum ImportDirectiveSubclass {
|
2016-02-13 15:49:16 -06:00
|
|
|
SingleImport {
|
|
|
|
target: Name,
|
|
|
|
source: Name,
|
|
|
|
type_determined: Cell<bool>,
|
|
|
|
value_determined: Cell<bool>,
|
|
|
|
},
|
2016-04-17 14:23:25 -05:00
|
|
|
GlobImport { is_prelude: bool },
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-02-13 15:49:16 -06:00
|
|
|
impl ImportDirectiveSubclass {
|
|
|
|
pub fn single(target: Name, source: Name) -> Self {
|
|
|
|
SingleImport {
|
|
|
|
target: target,
|
|
|
|
source: source,
|
|
|
|
type_determined: Cell::new(false),
|
|
|
|
value_determined: Cell::new(false),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-15 16:44:19 -05:00
|
|
|
/// One import directive.
|
2016-01-31 21:26:16 -06:00
|
|
|
#[derive(Debug,Clone)]
|
2016-03-16 20:13:31 -05:00
|
|
|
pub struct ImportDirective<'a> {
|
2016-04-16 20:57:09 -05:00
|
|
|
pub id: NodeId,
|
2016-08-16 19:42:14 -05:00
|
|
|
parent: Module<'a>,
|
2016-03-16 20:05:29 -05:00
|
|
|
module_path: Vec<Name>,
|
2016-03-16 20:16:33 -05:00
|
|
|
target_module: Cell<Option<Module<'a>>>, // the resolution of `module_path`
|
2016-03-16 20:05:29 -05:00
|
|
|
subclass: ImportDirectiveSubclass,
|
|
|
|
span: Span,
|
2016-04-09 18:19:53 -05:00
|
|
|
vis: ty::Visibility, // see note in ImportResolutionPerNamespace about how to use this
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-03-16 20:13:31 -05:00
|
|
|
impl<'a> ImportDirective<'a> {
|
2016-04-16 20:57:09 -05:00
|
|
|
pub fn is_glob(&self) -> bool {
|
2016-04-17 14:23:25 -05:00
|
|
|
match self.subclass { ImportDirectiveSubclass::GlobImport { .. } => true, _ => false }
|
2016-04-16 20:57:09 -05:00
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-02-09 00:26:27 -06:00
|
|
|
#[derive(Clone, Default)]
|
2016-03-17 03:43:17 -05:00
|
|
|
/// Records information about the resolution of a name in a namespace of a module.
|
2016-02-07 16:28:54 -06:00
|
|
|
pub struct NameResolution<'a> {
|
2016-03-17 03:43:17 -05:00
|
|
|
/// The single imports that define the name in the namespace.
|
|
|
|
single_imports: SingleImports<'a>,
|
2016-02-07 17:58:14 -06:00
|
|
|
/// The least shadowable known binding for this name, or None if there are no known bindings.
|
2016-02-07 15:23:58 -06:00
|
|
|
pub binding: Option<&'a NameBinding<'a>>,
|
2016-02-15 21:54:14 -06:00
|
|
|
duplicate_globs: Vec<&'a NameBinding<'a>>,
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-03-17 03:43:17 -05:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
enum SingleImports<'a> {
|
|
|
|
/// No single imports can define the name in the namespace.
|
|
|
|
None,
|
|
|
|
/// Only the given single import can define the name in the namespace.
|
|
|
|
MaybeOne(&'a ImportDirective<'a>),
|
|
|
|
/// At least one single import will define the name in the namespace.
|
|
|
|
AtLeastOne,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Default for SingleImports<'a> {
|
|
|
|
fn default() -> Self {
|
|
|
|
SingleImports::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> SingleImports<'a> {
|
|
|
|
fn add_directive(&mut self, directive: &'a ImportDirective<'a>) {
|
|
|
|
match *self {
|
|
|
|
SingleImports::None => *self = SingleImports::MaybeOne(directive),
|
|
|
|
// If two single imports can define the name in the namespace, we can assume that at
|
|
|
|
// least one of them will define it since otherwise both would have to define only one
|
|
|
|
// namespace, leading to a duplicate error.
|
|
|
|
SingleImports::MaybeOne(_) => *self = SingleImports::AtLeastOne,
|
|
|
|
SingleImports::AtLeastOne => {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn directive_failed(&mut self) {
|
|
|
|
match *self {
|
|
|
|
SingleImports::None => unreachable!(),
|
|
|
|
SingleImports::MaybeOne(_) => *self = SingleImports::None,
|
|
|
|
SingleImports::AtLeastOne => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-07 16:28:54 -06:00
|
|
|
impl<'a> NameResolution<'a> {
|
2016-03-17 03:43:17 -05:00
|
|
|
// Returns the binding for the name if it is known or None if it not known.
|
|
|
|
fn binding(&self) -> Option<&'a NameBinding<'a>> {
|
|
|
|
self.binding.and_then(|binding| match self.single_imports {
|
|
|
|
SingleImports::None => Some(binding),
|
2016-04-16 20:57:09 -05:00
|
|
|
_ if !binding.is_glob_import() => Some(binding),
|
2016-03-17 03:43:17 -05:00
|
|
|
_ => None, // The binding could be shadowed by a single import, so it is not known.
|
|
|
|
})
|
|
|
|
}
|
2016-08-01 15:43:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> ::ModuleS<'a> {
|
|
|
|
fn resolution(&self, name: Name, ns: Namespace) -> &'a RefCell<NameResolution<'a>> {
|
|
|
|
*self.resolutions.borrow_mut().entry((name, ns))
|
|
|
|
.or_insert_with(|| self.arenas.alloc_name_resolution())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Resolver<'a> {
|
|
|
|
/// Attempts to resolve the supplied name in the given module for the given namespace.
|
|
|
|
/// If successful, returns the binding corresponding to the name.
|
|
|
|
pub fn resolve_name_in_module(&mut self,
|
|
|
|
module: Module<'a>,
|
|
|
|
name: Name,
|
|
|
|
ns: Namespace,
|
|
|
|
allow_private_imports: bool,
|
|
|
|
record_used: bool)
|
|
|
|
-> ResolveResult<&'a NameBinding<'a>> {
|
|
|
|
self.populate_module_if_necessary(module);
|
|
|
|
|
|
|
|
let resolution = module.resolution(name, ns);
|
|
|
|
let resolution = match resolution.borrow_state() {
|
|
|
|
::std::cell::BorrowState::Unused => resolution.borrow_mut(),
|
|
|
|
_ => return Failed(None), // This happens when there is a cycle of imports
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Some(result) = self.try_result(&resolution, ns, allow_private_imports) {
|
|
|
|
// If the resolution doesn't depend on glob definability, check privacy and return.
|
|
|
|
return result.and_then(|binding| {
|
|
|
|
if !allow_private_imports && binding.is_import() && !binding.is_pseudo_public() {
|
|
|
|
return Failed(None);
|
|
|
|
}
|
|
|
|
if record_used {
|
|
|
|
self.record_use(name, ns, binding);
|
|
|
|
}
|
|
|
|
Success(binding)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the globs are determined
|
|
|
|
for directive in module.globs.borrow().iter() {
|
|
|
|
if !allow_private_imports && directive.vis != ty::Visibility::Public { continue }
|
|
|
|
if let Some(target_module) = directive.target_module.get() {
|
|
|
|
let result = self.resolve_name_in_module(target_module, name, ns, false, false);
|
|
|
|
if let Indeterminate = result {
|
|
|
|
return Indeterminate;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Indeterminate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Failed(None)
|
|
|
|
}
|
2016-03-17 03:43:17 -05:00
|
|
|
|
2016-02-15 21:54:14 -06:00
|
|
|
// Returns Some(the resolution of the name), or None if the resolution depends
|
|
|
|
// on whether more globs can define the name.
|
2016-08-01 15:43:48 -05:00
|
|
|
fn try_result(&mut self,
|
|
|
|
resolution: &NameResolution<'a>,
|
|
|
|
ns: Namespace,
|
|
|
|
allow_private_imports: bool)
|
2016-03-07 03:59:08 -06:00
|
|
|
-> Option<ResolveResult<&'a NameBinding<'a>>> {
|
2016-08-01 15:43:48 -05:00
|
|
|
match resolution.binding {
|
2016-04-16 20:57:09 -05:00
|
|
|
Some(binding) if !binding.is_glob_import() =>
|
2016-08-01 15:43:48 -05:00
|
|
|
return Some(Success(binding)), // Items and single imports are not shadowable.
|
|
|
|
_ => {}
|
2016-03-13 04:59:16 -05:00
|
|
|
};
|
|
|
|
|
2016-03-17 03:43:17 -05:00
|
|
|
// Check if a single import can still define the name.
|
2016-08-01 15:43:48 -05:00
|
|
|
match resolution.single_imports {
|
2016-03-17 03:43:17 -05:00
|
|
|
SingleImports::None => {},
|
|
|
|
SingleImports::AtLeastOne => return Some(Indeterminate),
|
|
|
|
SingleImports::MaybeOne(directive) => {
|
|
|
|
// If (1) we don't allow private imports, (2) no public single import can define
|
|
|
|
// the name, and (3) no public glob has defined the name, the resolution depends
|
|
|
|
// on whether more globs can define the name.
|
2016-04-09 18:19:53 -05:00
|
|
|
if !allow_private_imports && directive.vis != ty::Visibility::Public &&
|
2016-08-01 15:43:48 -05:00
|
|
|
!resolution.binding.map(NameBinding::is_pseudo_public).unwrap_or(false) {
|
2016-03-17 03:43:17 -05:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2016-03-17 19:05:08 -05:00
|
|
|
let target_module = match directive.target_module.get() {
|
|
|
|
Some(target_module) => target_module,
|
|
|
|
None => return Some(Indeterminate),
|
|
|
|
};
|
|
|
|
let name = match directive.subclass {
|
2016-03-30 17:21:56 -05:00
|
|
|
SingleImport { source, .. } => source,
|
2016-04-17 14:23:25 -05:00
|
|
|
GlobImport { .. } => unreachable!(),
|
2016-03-17 19:05:08 -05:00
|
|
|
};
|
2016-08-01 15:43:48 -05:00
|
|
|
match self.resolve_name_in_module(target_module, name, ns, false, false) {
|
2016-03-17 19:05:08 -05:00
|
|
|
Failed(_) => {}
|
|
|
|
_ => return Some(Indeterminate),
|
|
|
|
}
|
2016-03-17 03:43:17 -05:00
|
|
|
}
|
2016-03-13 04:59:16 -05:00
|
|
|
}
|
2016-03-17 03:43:17 -05:00
|
|
|
|
2016-08-01 15:43:48 -05:00
|
|
|
resolution.binding.map(Success)
|
2016-03-30 17:21:56 -05:00
|
|
|
}
|
|
|
|
|
2016-08-16 19:22:03 -05:00
|
|
|
// Add an import directive to the current module.
|
|
|
|
pub fn add_import_directive(&mut self,
|
2016-03-17 03:43:17 -05:00
|
|
|
module_path: Vec<Name>,
|
|
|
|
subclass: ImportDirectiveSubclass,
|
|
|
|
span: Span,
|
|
|
|
id: NodeId,
|
2016-04-17 14:23:25 -05:00
|
|
|
vis: ty::Visibility) {
|
2016-03-17 03:43:17 -05:00
|
|
|
let directive = self.arenas.alloc_import_directive(ImportDirective {
|
2016-08-16 19:42:14 -05:00
|
|
|
parent: self.current_module,
|
2016-03-17 03:43:17 -05:00
|
|
|
module_path: module_path,
|
|
|
|
target_module: Cell::new(None),
|
|
|
|
subclass: subclass,
|
|
|
|
span: span,
|
|
|
|
id: id,
|
2016-04-09 18:19:53 -05:00
|
|
|
vis: vis,
|
2016-03-17 03:43:17 -05:00
|
|
|
});
|
|
|
|
|
2016-08-16 19:52:18 -05:00
|
|
|
self.indeterminate_imports.push(directive);
|
2016-03-17 03:43:17 -05:00
|
|
|
match directive.subclass {
|
|
|
|
SingleImport { target, .. } => {
|
|
|
|
for &ns in &[ValueNS, TypeNS] {
|
2016-08-16 19:22:03 -05:00
|
|
|
let mut resolution = self.current_module.resolution(target, ns).borrow_mut();
|
|
|
|
resolution.single_imports.add_directive(directive);
|
2016-03-17 03:43:17 -05:00
|
|
|
}
|
|
|
|
}
|
2016-03-17 06:05:09 -05:00
|
|
|
// We don't add prelude imports to the globs since they only affect lexical scopes,
|
|
|
|
// which are not relevant to import resolution.
|
2016-04-17 14:23:25 -05:00
|
|
|
GlobImport { is_prelude: true } => {}
|
2016-08-16 19:22:03 -05:00
|
|
|
GlobImport { .. } => self.current_module.globs.borrow_mut().push(directive),
|
2016-03-17 06:05:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-30 23:53:04 -05:00
|
|
|
// Given a binding and an import directive that resolves to it,
|
|
|
|
// return the corresponding binding defined by the import directive.
|
|
|
|
fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>)
|
|
|
|
-> NameBinding<'a> {
|
|
|
|
NameBinding {
|
|
|
|
kind: NameBindingKind::Import {
|
|
|
|
binding: binding,
|
|
|
|
directive: directive,
|
|
|
|
},
|
|
|
|
span: directive.span,
|
|
|
|
vis: directive.vis,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 21:34:01 -05:00
|
|
|
// Define the name or return the existing binding if there is a collision.
|
|
|
|
pub fn try_define<T>(&mut self, module: Module<'a>, name: Name, ns: Namespace, binding: T)
|
|
|
|
-> Result<(), &'a NameBinding<'a>>
|
|
|
|
where T: ToNameBinding<'a>
|
|
|
|
{
|
|
|
|
let binding = self.arenas.alloc_name_binding(binding.to_name_binding());
|
|
|
|
self.update_resolution(module, name, ns, |_, resolution| {
|
|
|
|
if let Some(old_binding) = resolution.binding {
|
|
|
|
if binding.is_glob_import() {
|
|
|
|
resolution.duplicate_globs.push(binding);
|
|
|
|
} else if old_binding.is_glob_import() {
|
|
|
|
resolution.duplicate_globs.push(old_binding);
|
|
|
|
resolution.binding = Some(binding);
|
|
|
|
} else {
|
|
|
|
return Err(old_binding);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
resolution.binding = Some(binding);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use `f` to mutate the resolution of the name in the module.
|
2016-02-15 21:54:14 -06:00
|
|
|
// If the resolution becomes a success, define it in the module's glob importers.
|
2016-07-27 21:34:01 -05:00
|
|
|
fn update_resolution<T, F>(&mut self, module: Module<'a>, name: Name, ns: Namespace, f: F) -> T
|
|
|
|
where F: FnOnce(&mut Resolver<'a>, &mut NameResolution<'a>) -> T
|
2016-02-15 21:54:14 -06:00
|
|
|
{
|
2016-07-27 21:34:01 -05:00
|
|
|
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
|
|
|
|
// during which the resolution might end up getting re-defined via a glob cycle.
|
2016-04-07 17:14:44 -05:00
|
|
|
let (new_binding, t) = {
|
2016-07-27 21:34:01 -05:00
|
|
|
let mut resolution = &mut *module.resolution(name, ns).borrow_mut();
|
2016-04-07 17:14:44 -05:00
|
|
|
let was_known = resolution.binding().is_some();
|
2016-02-15 21:54:14 -06:00
|
|
|
|
2016-07-27 21:34:01 -05:00
|
|
|
let t = f(self, resolution);
|
2016-04-07 17:14:44 -05:00
|
|
|
|
|
|
|
if was_known { return t; }
|
|
|
|
match resolution.binding() {
|
|
|
|
Some(binding) => (binding, t),
|
|
|
|
None => return t,
|
2016-02-07 17:58:14 -06:00
|
|
|
}
|
2016-04-07 17:14:44 -05:00
|
|
|
};
|
|
|
|
|
2016-07-27 21:34:01 -05:00
|
|
|
// Define `new_binding` in `module`s glob importers.
|
|
|
|
if new_binding.is_importable() && new_binding.is_pseudo_public() {
|
2016-08-16 19:42:14 -05:00
|
|
|
for directive in module.glob_importers.borrow_mut().iter() {
|
2016-07-30 23:53:04 -05:00
|
|
|
let imported_binding = self.import(new_binding, directive);
|
2016-08-16 19:42:14 -05:00
|
|
|
let _ = self.try_define(directive.parent, name, ns, imported_binding);
|
2016-07-27 21:34:01 -05:00
|
|
|
}
|
2016-02-15 21:54:14 -06:00
|
|
|
}
|
2016-07-27 21:34:01 -05:00
|
|
|
|
|
|
|
t
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-31 21:26:16 -06:00
|
|
|
struct ImportResolvingError<'a> {
|
2016-03-16 20:13:31 -05:00
|
|
|
import_directive: &'a ImportDirective<'a>,
|
2015-08-04 01:14:32 -05:00
|
|
|
span: Span,
|
|
|
|
help: String,
|
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-04-23 22:26:10 -05:00
|
|
|
struct ImportResolver<'a, 'b: 'a> {
|
|
|
|
resolver: &'a mut Resolver<'b>,
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-07-28 11:17:01 -05:00
|
|
|
impl<'a, 'b: 'a> ::std::ops::Deref for ImportResolver<'a, 'b> {
|
|
|
|
type Target = Resolver<'b>;
|
|
|
|
fn deref(&self) -> &Resolver<'b> {
|
|
|
|
self.resolver
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'b: 'a> ::std::ops::DerefMut for ImportResolver<'a, 'b> {
|
|
|
|
fn deref_mut(&mut self) -> &mut Resolver<'b> {
|
|
|
|
self.resolver
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'b: 'a> ty::NodeIdTree for ImportResolver<'a, 'b> {
|
|
|
|
fn is_descendant_of(&self, node: NodeId, ancestor: NodeId) -> bool {
|
|
|
|
self.resolver.is_descendant_of(node, ancestor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-23 22:26:10 -05:00
|
|
|
impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
2015-03-15 16:44:19 -05:00
|
|
|
// Import resolution
|
|
|
|
//
|
|
|
|
// This is a fixed-point algorithm. We resolve imports until our efforts
|
|
|
|
// are stymied by an unresolved import; then we bail out of the current
|
|
|
|
// module and continue. We terminate successfully once no more imports
|
|
|
|
// remain or unsuccessfully when no forward progress in resolving imports
|
|
|
|
// is made.
|
|
|
|
|
2016-08-14 18:42:05 -05:00
|
|
|
fn set_current_module(&mut self, module: Module<'b>) {
|
|
|
|
self.current_module = module;
|
|
|
|
self.current_vis = ty::Visibility::Restricted({
|
|
|
|
let normal_module = self.get_nearest_normal_module_parent_or_self(module);
|
|
|
|
self.definitions.as_local_node_id(normal_module.def_id().unwrap()).unwrap()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-15 16:44:19 -05:00
|
|
|
/// Resolves all imports for the crate. This method performs the fixed-
|
|
|
|
/// point iteration.
|
|
|
|
fn resolve_imports(&mut self) {
|
|
|
|
let mut i = 0;
|
2016-08-16 19:52:18 -05:00
|
|
|
let mut prev_num_indeterminates = self.indeterminate_imports.len() + 1;
|
2016-02-17 03:29:17 -06:00
|
|
|
let mut errors = Vec::new();
|
|
|
|
|
2016-08-16 19:52:18 -05:00
|
|
|
while self.indeterminate_imports.len() < prev_num_indeterminates {
|
|
|
|
prev_num_indeterminates = self.indeterminate_imports.len();
|
|
|
|
debug!("(resolving imports) iteration {}, {} imports left", i, prev_num_indeterminates);
|
|
|
|
|
|
|
|
let mut imports = Vec::new();
|
|
|
|
::std::mem::swap(&mut imports, &mut self.indeterminate_imports);
|
|
|
|
|
|
|
|
for import in imports {
|
|
|
|
match self.resolve_import(&import) {
|
|
|
|
Failed(err) => {
|
|
|
|
let (span, help) = match err {
|
|
|
|
Some((span, msg)) => (span, format!(". {}", msg)),
|
|
|
|
None => (import.span, String::new()),
|
|
|
|
};
|
|
|
|
errors.push(ImportResolvingError {
|
|
|
|
import_directive: import,
|
|
|
|
span: span,
|
|
|
|
help: help,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Indeterminate => self.indeterminate_imports.push(import),
|
|
|
|
Success(()) => {}
|
2016-04-17 15:23:10 -05:00
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-08-16 19:52:18 -05:00
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for module in self.arenas.local_modules().iter() {
|
|
|
|
self.finalize_resolutions_in(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report unresolved imports only if no hard error was already reported
|
|
|
|
// to avoid generating multiple errors on the same import.
|
|
|
|
if errors.len() == 0 {
|
|
|
|
if let Some(import) = self.indeterminate_imports.iter().next() {
|
|
|
|
let error = ResolutionError::UnresolvedImport(None);
|
|
|
|
resolve_error(self.resolver, import.span, error);
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
2016-08-16 19:52:18 -05:00
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-08-16 19:52:18 -05:00
|
|
|
for e in errors {
|
|
|
|
self.import_resolving_error(e)
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-13 00:36:09 -05:00
|
|
|
// Define a "dummy" resolution containing a Def::Err as a placeholder for a
|
|
|
|
// failed resolution
|
2016-08-16 19:42:14 -05:00
|
|
|
fn import_dummy_binding(&mut self, directive: &'b ImportDirective<'b>) {
|
2016-07-13 00:36:09 -05:00
|
|
|
if let SingleImport { target, .. } = directive.subclass {
|
2016-07-28 11:17:01 -05:00
|
|
|
let dummy_binding = self.arenas.alloc_name_binding(NameBinding {
|
2016-02-07 17:58:14 -06:00
|
|
|
kind: NameBindingKind::Def(Def::Err),
|
2016-04-26 20:13:15 -05:00
|
|
|
span: DUMMY_SP,
|
2016-04-09 18:19:53 -05:00
|
|
|
vis: ty::Visibility::Public,
|
2016-01-31 21:26:16 -06:00
|
|
|
});
|
2016-07-30 23:53:04 -05:00
|
|
|
let dummy_binding = self.import(dummy_binding, directive);
|
2016-01-31 21:26:16 -06:00
|
|
|
|
2016-08-16 19:42:14 -05:00
|
|
|
let _ = self.try_define(directive.parent, target, ValueNS, dummy_binding.clone());
|
|
|
|
let _ = self.try_define(directive.parent, target, TypeNS, dummy_binding);
|
2016-01-31 21:26:16 -06:00
|
|
|
}
|
2016-07-13 00:36:09 -05:00
|
|
|
}
|
2016-01-31 21:26:16 -06:00
|
|
|
|
2016-07-13 00:36:09 -05:00
|
|
|
/// Resolves an `ImportResolvingError` into the correct enum discriminant
|
|
|
|
/// and passes that on to `resolve_error`.
|
2016-07-27 21:34:01 -05:00
|
|
|
fn import_resolving_error(&mut self, e: ImportResolvingError<'b>) {
|
2016-07-13 00:36:09 -05:00
|
|
|
// If the error is a single failed import then create a "fake" import
|
|
|
|
// resolution for it so that later resolve stages won't complain.
|
2016-08-16 19:42:14 -05:00
|
|
|
self.import_dummy_binding(e.import_directive);
|
2016-01-31 21:26:16 -06:00
|
|
|
let path = import_path_to_string(&e.import_directive.module_path,
|
2016-02-14 20:22:59 -06:00
|
|
|
&e.import_directive.subclass);
|
2016-01-31 21:26:16 -06:00
|
|
|
resolve_error(self.resolver,
|
|
|
|
e.span,
|
|
|
|
ResolutionError::UnresolvedImport(Some((&path, &e.help))));
|
|
|
|
}
|
|
|
|
|
2015-03-15 16:44:19 -05:00
|
|
|
/// Attempts to resolve the given import. The return value indicates
|
|
|
|
/// failure if we're certain the name does not exist, indeterminate if we
|
|
|
|
/// don't know whether the name exists at the moment due to other
|
|
|
|
/// currently-unresolved imports, or success if we know the name exists.
|
|
|
|
/// If successful, the resolved bindings are written into the module.
|
2016-03-16 20:13:31 -05:00
|
|
|
fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResult<()> {
|
2015-03-15 16:44:19 -05:00
|
|
|
debug!("(resolving import for module) resolving import `{}::...` in `{}`",
|
2016-03-12 20:53:22 -06:00
|
|
|
names_to_string(&directive.module_path),
|
2016-07-28 11:17:01 -05:00
|
|
|
module_to_string(self.current_module));
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-08-16 19:52:18 -05:00
|
|
|
let module = directive.parent;
|
2016-08-14 18:42:05 -05:00
|
|
|
self.set_current_module(module);
|
2016-08-16 19:52:18 -05:00
|
|
|
|
2016-03-17 19:57:05 -05:00
|
|
|
let target_module = match directive.target_module.get() {
|
|
|
|
Some(module) => module,
|
2016-07-28 11:17:01 -05:00
|
|
|
_ => match self.resolve_module_path(&directive.module_path,
|
|
|
|
DontUseLexicalScope,
|
|
|
|
directive.span) {
|
2016-03-17 19:57:05 -05:00
|
|
|
Success(module) => module,
|
|
|
|
Indeterminate => return Indeterminate,
|
|
|
|
Failed(err) => return Failed(err),
|
|
|
|
},
|
2016-03-12 20:53:22 -06:00
|
|
|
};
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-03-17 19:57:05 -05:00
|
|
|
directive.target_module.set(Some(target_module));
|
2016-02-13 15:49:16 -06:00
|
|
|
let (source, target, value_determined, type_determined) = match directive.subclass {
|
|
|
|
SingleImport { source, target, ref value_determined, ref type_determined } =>
|
|
|
|
(source, target, value_determined, type_determined),
|
2016-04-17 14:23:25 -05:00
|
|
|
GlobImport { .. } => return self.resolve_glob_import(target_module, directive),
|
2016-02-13 15:49:16 -06:00
|
|
|
};
|
2016-02-07 17:58:14 -06:00
|
|
|
|
2015-03-15 16:44:19 -05:00
|
|
|
// We need to resolve both namespaces for this to succeed.
|
2016-07-28 11:17:01 -05:00
|
|
|
let value_result = self.resolve_name_in_module(target_module, source, ValueNS, false, true);
|
|
|
|
let type_result = self.resolve_name_in_module(target_module, source, TypeNS, false, true);
|
2016-02-13 15:49:16 -06:00
|
|
|
|
2016-07-25 18:04:42 -05:00
|
|
|
let mut privacy_error = true;
|
2016-02-13 15:49:16 -06:00
|
|
|
for &(ns, result, determined) in &[(ValueNS, &value_result, value_determined),
|
|
|
|
(TypeNS, &type_result, type_determined)] {
|
2016-07-25 18:04:42 -05:00
|
|
|
match *result {
|
|
|
|
Failed(..) if !determined.get() => {
|
|
|
|
determined.set(true);
|
2016-07-29 12:52:56 -05:00
|
|
|
self.update_resolution(module, target, ns, |_, resolution| {
|
2016-07-25 18:04:42 -05:00
|
|
|
resolution.single_imports.directive_failed()
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Success(binding) if !binding.is_importable() => {
|
2016-02-13 15:49:16 -06:00
|
|
|
let msg = format!("`{}` is not directly importable", target);
|
2016-08-09 16:31:57 -05:00
|
|
|
struct_span_err!(self.session, directive.span, E0253, "{}", &msg)
|
|
|
|
.span_label(directive.span, &format!("cannot be imported directly"))
|
|
|
|
.emit();
|
2016-07-13 00:36:09 -05:00
|
|
|
// Do not import this illegal binding. Import a dummy binding and pretend
|
|
|
|
// everything is fine
|
2016-08-16 19:42:14 -05:00
|
|
|
self.import_dummy_binding(directive);
|
2016-07-13 00:36:09 -05:00
|
|
|
return Success(());
|
2016-02-13 15:49:16 -06:00
|
|
|
}
|
2016-07-28 11:17:01 -05:00
|
|
|
Success(binding) if !self.is_accessible(binding.vis) => {}
|
2016-07-25 18:04:42 -05:00
|
|
|
Success(binding) if !determined.get() => {
|
|
|
|
determined.set(true);
|
2016-07-30 23:53:04 -05:00
|
|
|
let imported_binding = self.import(binding, directive);
|
2016-07-29 12:52:56 -05:00
|
|
|
let conflict = self.try_define(module, target, ns, imported_binding);
|
2016-07-25 18:04:42 -05:00
|
|
|
if let Err(old_binding) = conflict {
|
2016-07-30 23:53:04 -05:00
|
|
|
let binding = &self.import(binding, directive);
|
2016-07-29 12:52:56 -05:00
|
|
|
self.report_conflict(module, target, ns, binding, old_binding);
|
2016-07-25 18:04:42 -05:00
|
|
|
}
|
|
|
|
privacy_error = false;
|
2016-02-16 07:14:32 -06:00
|
|
|
}
|
2016-07-25 18:04:42 -05:00
|
|
|
Success(_) => privacy_error = false,
|
|
|
|
_ => {}
|
2016-02-13 15:49:16 -06:00
|
|
|
}
|
2016-02-07 17:58:14 -06:00
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-02-11 00:17:01 -06:00
|
|
|
match (&value_result, &type_result) {
|
|
|
|
(&Indeterminate, _) | (_, &Indeterminate) => return Indeterminate,
|
|
|
|
(&Failed(_), &Failed(_)) => {
|
2016-03-30 23:44:04 -05:00
|
|
|
let resolutions = target_module.resolutions.borrow();
|
|
|
|
let names = resolutions.iter().filter_map(|(&(ref name, _), resolution)| {
|
2016-04-08 20:06:57 -05:00
|
|
|
if *name == source { return None; } // Never suggest the same name
|
2016-03-30 23:44:04 -05:00
|
|
|
match *resolution.borrow() {
|
|
|
|
NameResolution { binding: Some(_), .. } => Some(name),
|
|
|
|
NameResolution { single_imports: SingleImports::None, .. } => None,
|
|
|
|
_ => Some(name),
|
|
|
|
}
|
|
|
|
});
|
2016-02-11 00:17:01 -06:00
|
|
|
let lev_suggestion = match find_best_match_for_name(names, &source.as_str(), None) {
|
|
|
|
Some(name) => format!(". Did you mean to use `{}`?", name),
|
|
|
|
None => "".to_owned(),
|
|
|
|
};
|
2016-04-08 20:06:57 -05:00
|
|
|
let module_str = module_to_string(target_module);
|
|
|
|
let msg = if &module_str == "???" {
|
|
|
|
format!("There is no `{}` in the crate root{}", source, lev_suggestion)
|
|
|
|
} else {
|
|
|
|
format!("There is no `{}` in `{}`{}", source, module_str, lev_suggestion)
|
|
|
|
};
|
2016-02-11 00:17:01 -06:00
|
|
|
return Failed(Some((directive.span, msg)));
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
2016-07-25 18:04:42 -05:00
|
|
|
if privacy_error {
|
|
|
|
for &(ns, result) in &[(ValueNS, &value_result), (TypeNS, &type_result)] {
|
|
|
|
let binding = match *result { Success(binding) => binding, _ => continue };
|
2016-07-28 11:17:01 -05:00
|
|
|
self.privacy_errors.push(PrivacyError(directive.span, source, binding));
|
2016-07-30 23:53:04 -05:00
|
|
|
let imported_binding = self.import(binding, directive);
|
|
|
|
let _ = self.try_define(module, target, ns, imported_binding);
|
2016-07-25 18:04:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-21 21:00:29 -06:00
|
|
|
match (&value_result, &type_result) {
|
2016-07-28 11:17:01 -05:00
|
|
|
(&Success(binding), _) if !binding.pseudo_vis().is_at_least(directive.vis, self) &&
|
|
|
|
self.is_accessible(binding.vis) => {
|
2016-01-13 19:42:45 -06:00
|
|
|
let msg = format!("`{}` is private, and cannot be reexported", source);
|
2016-02-24 02:47:45 -06:00
|
|
|
let note_msg = format!("consider marking `{}` as `pub` in the imported module",
|
2016-01-13 19:42:45 -06:00
|
|
|
source);
|
2016-07-28 11:17:01 -05:00
|
|
|
struct_span_err!(self.session, directive.span, E0364, "{}", &msg)
|
2016-01-13 19:42:45 -06:00
|
|
|
.span_note(directive.span, ¬e_msg)
|
|
|
|
.emit();
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-07-28 11:17:01 -05:00
|
|
|
(_, &Success(binding)) if !binding.pseudo_vis().is_at_least(directive.vis, self) &&
|
|
|
|
self.is_accessible(binding.vis) => {
|
2016-04-09 19:44:14 -05:00
|
|
|
if binding.is_extern_crate() {
|
2016-02-15 21:54:14 -06:00
|
|
|
let msg = format!("extern crate `{}` is private, and cannot be reexported \
|
|
|
|
(error E0364), consider declaring with `pub`",
|
2016-01-13 19:42:45 -06:00
|
|
|
source);
|
2016-07-28 11:17:01 -05:00
|
|
|
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg);
|
2016-02-15 21:54:14 -06:00
|
|
|
} else {
|
2016-08-14 14:30:50 -05:00
|
|
|
let mut err = struct_span_err!(self.session, directive.span, E0365,
|
|
|
|
"`{}` is private, and cannot be reexported",
|
|
|
|
source);
|
|
|
|
err.span_label(directive.span, &format!("reexport of private `{}`", source));
|
|
|
|
err.note(&format!("consider declaring type or module `{}` with `pub`", source));
|
|
|
|
err.emit();
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
2016-01-13 19:42:45 -06:00
|
|
|
}
|
2015-12-14 11:06:31 -06:00
|
|
|
|
2016-01-21 21:00:29 -06:00
|
|
|
_ => {}
|
2016-01-13 19:42:45 -06:00
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
|
2016-02-07 17:06:10 -06:00
|
|
|
// Record what this import resolves to for later uses in documentation,
|
|
|
|
// this may resolve to either a value or a type, but for documentation
|
|
|
|
// purposes it's good enough to just favor one over the other.
|
2016-02-24 21:36:17 -06:00
|
|
|
let def = match type_result.success().and_then(NameBinding::def) {
|
|
|
|
Some(def) => def,
|
|
|
|
None => value_result.success().and_then(NameBinding::def).unwrap(),
|
2016-02-07 17:06:10 -06:00
|
|
|
};
|
2016-06-03 15:15:00 -05:00
|
|
|
let path_resolution = PathResolution::new(def);
|
2016-07-28 11:17:01 -05:00
|
|
|
self.def_map.insert(directive.id, path_resolution);
|
2015-03-15 16:44:19 -05:00
|
|
|
|
|
|
|
debug!("(resolving single import) successfully resolved import");
|
2016-01-21 21:00:29 -06:00
|
|
|
return Success(());
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Resolves a glob import. Note that this function cannot fail; it either
|
|
|
|
// succeeds or bails out (as importing * from an empty module or a module
|
|
|
|
// that exports nothing is valid). target_module is the module we are
|
|
|
|
// actually importing, i.e., `foo` in `use foo::*`.
|
2016-03-16 20:13:31 -05:00
|
|
|
fn resolve_glob_import(&mut self, target_module: Module<'b>, directive: &'b ImportDirective<'b>)
|
2015-03-15 16:44:19 -05:00
|
|
|
-> ResolveResult<()> {
|
2016-03-08 16:27:12 -06:00
|
|
|
if let Some(Def::Trait(_)) = target_module.def {
|
2016-07-28 11:17:01 -05:00
|
|
|
self.session.span_err(directive.span, "items in traits are not importable.");
|
2016-03-08 16:27:12 -06:00
|
|
|
}
|
|
|
|
|
2016-07-29 12:52:56 -05:00
|
|
|
let module = self.current_module;
|
|
|
|
if module.def_id() == target_module.def_id() {
|
2016-02-07 17:58:14 -06:00
|
|
|
// This means we are trying to glob import a module into itself, and it is a no-go
|
|
|
|
let msg = "Cannot glob-import a module into itself.".into();
|
|
|
|
return Failed(Some((directive.span, msg)));
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
2016-07-28 11:17:01 -05:00
|
|
|
self.populate_module_if_necessary(target_module);
|
2016-02-15 21:54:14 -06:00
|
|
|
|
2016-04-17 14:23:25 -05:00
|
|
|
if let GlobImport { is_prelude: true } = directive.subclass {
|
2016-07-28 11:17:01 -05:00
|
|
|
self.prelude = Some(target_module);
|
2016-03-08 19:46:46 -06:00
|
|
|
return Success(());
|
|
|
|
}
|
|
|
|
|
2016-03-17 06:05:09 -05:00
|
|
|
// Add to target_module's glob_importers
|
2016-08-16 19:42:14 -05:00
|
|
|
target_module.glob_importers.borrow_mut().push(directive);
|
2016-02-15 21:54:14 -06:00
|
|
|
|
2016-07-27 21:34:01 -05:00
|
|
|
// Ensure that `resolutions` isn't borrowed during `try_define`,
|
2016-04-11 13:30:48 -05:00
|
|
|
// since it might get updated via a glob cycle.
|
2016-04-07 17:14:44 -05:00
|
|
|
let bindings = target_module.resolutions.borrow().iter().filter_map(|(name, resolution)| {
|
|
|
|
resolution.borrow().binding().map(|binding| (*name, binding))
|
|
|
|
}).collect::<Vec<_>>();
|
|
|
|
for ((name, ns), binding) in bindings {
|
2016-04-16 20:57:09 -05:00
|
|
|
if binding.is_importable() && binding.is_pseudo_public() {
|
2016-07-30 23:53:04 -05:00
|
|
|
let imported_binding = self.import(binding, directive);
|
|
|
|
let _ = self.try_define(module, name, ns, imported_binding);
|
2016-02-07 17:58:14 -06:00
|
|
|
}
|
2016-02-15 21:54:14 -06:00
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
|
|
|
|
// Record the destination of this import
|
2015-11-16 01:59:50 -06:00
|
|
|
if let Some(did) = target_module.def_id() {
|
2016-06-03 15:15:00 -05:00
|
|
|
let resolution = PathResolution::new(Def::Mod(did));
|
2016-07-28 11:17:01 -05:00
|
|
|
self.def_map.insert(directive.id, resolution);
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
debug!("(resolving glob import) successfully resolved import");
|
2016-02-07 17:58:14 -06:00
|
|
|
return Success(());
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-04-17 19:26:18 -05:00
|
|
|
// Miscellaneous post-processing, including recording reexports, reporting conflicts,
|
|
|
|
// reporting the PRIVATE_IN_PUBLIC lint, and reporting unresolved imports.
|
2016-08-16 19:52:18 -05:00
|
|
|
fn finalize_resolutions_in(&mut self, module: Module<'b>) {
|
2016-02-15 21:54:14 -06:00
|
|
|
// Since import resolution is finished, globs will not define any more names.
|
2016-03-17 06:05:09 -05:00
|
|
|
*module.globs.borrow_mut() = Vec::new();
|
2016-02-15 21:54:14 -06:00
|
|
|
|
|
|
|
let mut reexports = Vec::new();
|
|
|
|
for (&(name, ns), resolution) in module.resolutions.borrow().iter() {
|
2016-03-30 17:21:56 -05:00
|
|
|
let resolution = resolution.borrow();
|
2016-02-15 21:54:14 -06:00
|
|
|
let binding = match resolution.binding {
|
|
|
|
Some(binding) => binding,
|
|
|
|
None => continue,
|
|
|
|
};
|
|
|
|
|
2016-07-27 13:54:16 -05:00
|
|
|
// Report conflicts
|
|
|
|
for duplicate_glob in resolution.duplicate_globs.iter() {
|
|
|
|
// FIXME #31337: We currently allow items to shadow glob-imported re-exports.
|
|
|
|
if !binding.is_import() {
|
|
|
|
if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind {
|
|
|
|
if binding.is_import() { continue }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.report_conflict(module, name, ns, duplicate_glob, binding);
|
|
|
|
}
|
|
|
|
|
2016-04-11 00:35:18 -05:00
|
|
|
if binding.vis == ty::Visibility::Public &&
|
|
|
|
(binding.is_import() || binding.is_extern_crate()) {
|
2016-02-15 21:54:14 -06:00
|
|
|
if let Some(def) = binding.def() {
|
|
|
|
reexports.push(Export { name: name, def_id: def.def_id() });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-16 20:57:09 -05:00
|
|
|
if let NameBindingKind::Import { binding: orig_binding, directive, .. } = binding.kind {
|
2016-04-11 00:35:18 -05:00
|
|
|
if ns == TypeNS && orig_binding.is_variant() &&
|
2016-07-28 11:17:01 -05:00
|
|
|
!orig_binding.vis.is_at_least(binding.vis, self) {
|
2016-02-15 21:54:14 -06:00
|
|
|
let msg = format!("variant `{}` is private, and cannot be reexported \
|
|
|
|
(error E0364), consider declaring its enum as `pub`",
|
|
|
|
name);
|
2016-07-28 11:17:01 -05:00
|
|
|
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, binding.span, msg);
|
2016-02-15 21:54:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if reexports.len() > 0 {
|
|
|
|
if let Some(def_id) = module.def_id() {
|
2016-07-28 11:17:01 -05:00
|
|
|
let node_id = self.definitions.as_local_node_id(def_id).unwrap();
|
|
|
|
self.export_map.insert(node_id, reexports);
|
2016-02-15 21:54:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
|
2016-02-14 20:22:59 -06:00
|
|
|
fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) -> String {
|
2015-03-15 16:44:19 -05:00
|
|
|
if names.is_empty() {
|
|
|
|
import_directive_subclass_to_string(subclass)
|
|
|
|
} else {
|
|
|
|
(format!("{}::{}",
|
|
|
|
names_to_string(names),
|
2015-10-26 14:31:11 -05:00
|
|
|
import_directive_subclass_to_string(subclass)))
|
|
|
|
.to_string()
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-14 20:22:59 -06:00
|
|
|
fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> String {
|
|
|
|
match *subclass {
|
2016-02-13 15:49:16 -06:00
|
|
|
SingleImport { source, .. } => source.to_string(),
|
2016-04-17 14:23:25 -05:00
|
|
|
GlobImport { .. } => "*".to_string(),
|
2015-03-15 16:44:19 -05:00
|
|
|
}
|
|
|
|
}
|