summaryrefslogtreecommitdiff
path: root/src/hir_expand
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-01-14 09:02:10 +0800
committerJohn Hodge <tpg@mutabah.net>2017-01-14 09:02:10 +0800
commitdb01a8a8ae3dab9888d7a734dc07ca513b6f86bc (patch)
tree2f3a75549eee5378b7ec9aa712f8f26aec9d77b4 /src/hir_expand
parent27be955d74e03e5db1c549367f3f784ec535f509 (diff)
downloadmrust-db01a8a8ae3dab9888d7a734dc07ca513b6f86bc.tar.gz
HIR - Clean up some manual item searching
Diffstat (limited to 'src/hir_expand')
-rw-r--r--src/hir_expand/const_eval_full.cpp34
1 files changed, 5 insertions, 29 deletions
diff --git a/src/hir_expand/const_eval_full.cpp b/src/hir_expand/const_eval_full.cpp
index 102bb84c..35ddcb66 100644
--- a/src/hir_expand/const_eval_full.cpp
+++ b/src/hir_expand/const_eval_full.cpp
@@ -127,37 +127,13 @@ namespace {
};
EntPtr get_ent_simplepath(const Span& sp, const ::HIR::Crate& crate, const ::HIR::SimplePath& path, EntNS ns)
{
- const ::HIR::Module* mod;
- if( path.m_crate_name != crate.m_crate_name ) {
- ASSERT_BUG(sp, crate.m_ext_crates.count(path.m_crate_name) > 0, "Crate '" << path.m_crate_name << "' not loaded");
- mod = &crate.m_ext_crates.at(path.m_crate_name).m_data->m_root_module;
- }
- else {
- mod = &crate.m_root_module;
- }
-
- for( unsigned int i = 0; i < path.m_components.size() - 1; i ++ )
- {
- const auto& pc = path.m_components[i];
- auto it = mod->m_mod_items.find( pc );
- if( it == mod->m_mod_items.end() ) {
- BUG(sp, "Couldn't find component " << i << " of " << path);
- }
- TU_MATCH_DEF( ::HIR::TypeItem, (it->second->ent), (e2),
- (
- BUG(sp, "Node " << i << " of path " << path << " wasn't a module");
- ),
- (Module,
- mod = &e2;
- )
- )
- }
+ const ::HIR::Module& mod = crate.get_mod_by_path(sp, path, /*ignore_last_node=*/true);
switch( ns )
{
case EntNS::Value: {
- auto it = mod->m_value_items.find( path.m_components.back() );
- if( it == mod->m_value_items.end() ) {
+ auto it = mod.m_value_items.find( path.m_components.back() );
+ if( it == mod.m_value_items.end() ) {
return EntPtr {};
}
@@ -181,8 +157,8 @@ namespace {
BUG(sp, "Path " << path << " pointed to a invalid item - " << it->second->ent.tag_str());
} break;
case EntNS::Type: {
- auto it = mod->m_mod_items.find( path.m_components.back() );
- if( it == mod->m_mod_items.end() ) {
+ auto it = mod.m_mod_items.find( path.m_components.back() );
+ if( it == mod.m_mod_items.end() ) {
return EntPtr {};
}