resolve (cleanup): Get rid of Option in PerNS
This commit is contained in:
parent
17841cc97a
commit
428ef191e0
2 changed files with 15 additions and 14 deletions
|
|
@ -17,7 +17,7 @@ use macros::{InvocationData, LegacyScope};
|
|||
use resolve_imports::ImportDirective;
|
||||
use resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
|
||||
use {Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, ToNameBinding};
|
||||
use {Resolver, ResolverArenas};
|
||||
use {PerNS, Resolver, ResolverArenas};
|
||||
use Namespace::{self, TypeNS, ValueNS, MacroNS};
|
||||
use {resolve_error, resolve_struct_error, ResolutionError};
|
||||
|
||||
|
|
@ -175,7 +175,11 @@ impl<'a> Resolver<'a> {
|
|||
let subclass = SingleImport {
|
||||
target: ident,
|
||||
source,
|
||||
result: self.per_ns(|_, _| Cell::new(Err(Undetermined))),
|
||||
result: PerNS {
|
||||
type_ns: Cell::new(Err(Undetermined)),
|
||||
value_ns: Cell::new(Err(Undetermined)),
|
||||
macro_ns: Cell::new(Err(Undetermined)),
|
||||
},
|
||||
type_ns_only,
|
||||
};
|
||||
self.add_import_directive(
|
||||
|
|
|
|||
|
|
@ -700,7 +700,7 @@ pub enum Namespace {
|
|||
pub struct PerNS<T> {
|
||||
value_ns: T,
|
||||
type_ns: T,
|
||||
macro_ns: Option<T>,
|
||||
macro_ns: T,
|
||||
}
|
||||
|
||||
impl<T> ::std::ops::Index<Namespace> for PerNS<T> {
|
||||
|
|
@ -709,7 +709,7 @@ impl<T> ::std::ops::Index<Namespace> for PerNS<T> {
|
|||
match ns {
|
||||
ValueNS => &self.value_ns,
|
||||
TypeNS => &self.type_ns,
|
||||
MacroNS => self.macro_ns.as_ref().unwrap(),
|
||||
MacroNS => &self.macro_ns,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -719,7 +719,7 @@ impl<T> ::std::ops::IndexMut<Namespace> for PerNS<T> {
|
|||
match ns {
|
||||
ValueNS => &mut self.value_ns,
|
||||
TypeNS => &mut self.type_ns,
|
||||
MacroNS => self.macro_ns.as_mut().unwrap(),
|
||||
MacroNS => &mut self.macro_ns,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1726,7 +1726,7 @@ impl<'a> Resolver<'a> {
|
|||
ribs: PerNS {
|
||||
value_ns: vec![Rib::new(ModuleRibKind(graph_root))],
|
||||
type_ns: vec![Rib::new(ModuleRibKind(graph_root))],
|
||||
macro_ns: Some(vec![Rib::new(ModuleRibKind(graph_root))]),
|
||||
macro_ns: vec![Rib::new(ModuleRibKind(graph_root))],
|
||||
},
|
||||
label_ribs: Vec::new(),
|
||||
|
||||
|
|
@ -1806,14 +1806,11 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
/// Runs the function on each namespace.
|
||||
fn per_ns<T, F: FnMut(&mut Self, Namespace) -> T>(&mut self, mut f: F) -> PerNS<T> {
|
||||
PerNS {
|
||||
type_ns: f(self, TypeNS),
|
||||
value_ns: f(self, ValueNS),
|
||||
macro_ns: match self.use_extern_macros {
|
||||
true => Some(f(self, MacroNS)),
|
||||
false => None,
|
||||
},
|
||||
fn per_ns<F: FnMut(&mut Self, Namespace)>(&mut self, mut f: F) {
|
||||
f(self, TypeNS);
|
||||
f(self, ValueNS);
|
||||
if self.use_extern_macros {
|
||||
f(self, MacroNS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue