Skip to content

resolve: More groundwork for item_like_imports (RFC 1560) #35776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 21, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add type Determinacy.
  • Loading branch information
jseyfried committed Aug 18, 2016
commit a6e8f3ba8332cc4a7c32a64cf0df6f67b32a3dd3
25 changes: 16 additions & 9 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use self::Determinacy::*;
use self::ImportDirectiveSubclass::*;

use Module;
Expand Down Expand Up @@ -36,14 +37,20 @@ impl<'a> Resolver<'a> {
}
}

#[derive(Copy, Clone, Debug)]
pub enum Determinacy {
Determined,
Undetermined,
}

/// Contains data for specific types of import directives.
#[derive(Clone, Debug)]
pub enum ImportDirectiveSubclass<'a> {
SingleImport {
target: Name,
source: Name,
value_result: Cell<Result<&'a NameBinding<'a>, bool /* determined? */>>,
type_result: Cell<Result<&'a NameBinding<'a>, bool /* determined? */>>,
value_result: Cell<Result<&'a NameBinding<'a>, Determinacy>>,
type_result: Cell<Result<&'a NameBinding<'a>, Determinacy>>,
},
GlobImport { is_prelude: bool },
}
Expand All @@ -53,8 +60,8 @@ impl<'a> ImportDirectiveSubclass<'a> {
SingleImport {
target: target,
source: source,
type_result: Cell::new(Err(false)),
value_result: Cell::new(Err(false)),
type_result: Cell::new(Err(Undetermined)),
value_result: Cell::new(Err(Undetermined)),
}
}
}
Expand Down Expand Up @@ -497,21 +504,21 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {

let mut indeterminate = false;
for &(ns, result) in &[(ValueNS, value_result), (TypeNS, type_result)] {
if let Err(false) = result.get() {
if let Err(Undetermined) = result.get() {
result.set({
match self.resolve_name_in_module(module, source, ns, false, None) {
Success(binding) => Ok(binding),
Indeterminate => Err(false),
Failed(_) => Err(true),
Indeterminate => Err(Undetermined),
Failed(_) => Err(Determined),
}
});
} else {
continue
};

match result.get() {
Err(false) => indeterminate = true,
Err(true) => {
Err(Undetermined) => indeterminate = true,
Err(Determined) => {
self.update_resolution(directive.parent, target, ns, |_, resolution| {
resolution.single_imports.directive_failed()
});
Expand Down