diff --git a/src/can/module.rs b/src/can/module.rs index 47658b7da0..1afcce7fb0 100644 --- a/src/can/module.rs +++ b/src/can/module.rs @@ -100,7 +100,7 @@ pub fn canonicalize_module_defs<'a>( } } - let (defs, populated_scope, output) = canonicalize_defs( + let (defs, scope, output) = canonicalize_defs( &mut env, Output::default(), var_store, @@ -155,13 +155,21 @@ pub fn canonicalize_module_defs<'a>( } } - for (symbol, _alias) in scope.aliases() { + let mut aliases = MutMap::default(); + + for (symbol, alias) in scope.into_aliases() { // Remove this from exposed_symbols, // so that at the end of the process, // we can see if there were any // exposed symbols which did not have // corresponding defs. - exposed_symbols.remove(symbol); + exposed_symbols.remove(&symbol); + + // TODO store aliases as a MutMap inside Scope + // (and manually remove them when exiting a scope) + // and we can use it directly instead of rebuilding it + // piece by piece like this. + aliases.insert(symbol, alias); } // By this point, all exposed symbols should have been removed from @@ -180,12 +188,6 @@ pub fn canonicalize_module_defs<'a>( references.insert(symbol); } - let mut aliases = MutMap::default(); - - for (symbol, alias) in populated_scope.aliases() { - aliases.insert(*symbol, alias.clone()); - } - Ok(ModuleOutput { aliases, declarations, diff --git a/src/can/scope.rs b/src/can/scope.rs index 063f0c290f..b7d4657af8 100644 --- a/src/can/scope.rs +++ b/src/can/scope.rs @@ -42,8 +42,8 @@ impl Scope { self.symbols.iter() } - pub fn aliases(&self) -> impl Iterator { - self.aliases.iter() + pub fn into_aliases(self) -> ImMap { + self.aliases } pub fn contains_ident(&self, ident: &Ident) -> bool {