Skip to content

Commit

Permalink
Add type Determinacy.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Aug 18, 2016
1 parent 951d3d6 commit a6e8f3b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/librustc_resolve/resolve_imports.rs
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

0 comments on commit a6e8f3b

Please sign in to comment.