diff options
author | John Hodge <tpg@mutabah.net> | 2016-08-14 15:38:36 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-08-14 15:38:36 +0800 |
commit | 31b18e35522708cac4345f1817c07f9784d175df (patch) | |
tree | bb003d3d747183be9fda0c0b9d5a3a6cfc12c5c7 | |
parent | 12f1926f483d5b48ae38704e7bd1296db3d524c5 (diff) | |
download | mrust-31b18e35522708cac4345f1817c07f9784d175df.tar.gz |
HIR Expand - Partial _Index expansion, requires extra annotation
-rw-r--r-- | src/hir_expand/ufcs_everything.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/hir_expand/ufcs_everything.cpp b/src/hir_expand/ufcs_everything.cpp index 7f1268d8..670d493d 100644 --- a/src/hir_expand/ufcs_everything.cpp +++ b/src/hir_expand/ufcs_everything.cpp @@ -518,6 +518,39 @@ namespace { arg_types.push_back( ty_val.clone() ); arg_types.push_back( m_replacement->m_res_type.clone() ); } + + + void visit(::HIR::ExprNode_Index& node) override + { + const auto& sp = node.span(); + ::HIR::ExprVisitorDef::visit(node); + + const auto& ty_idx = node.m_index->m_res_type; + const auto& ty_val = node.m_value->m_res_type; + + TU_MATCH_DEF( ::HIR::TypeRef::Data, (ty_val.m_data), (val_te), + ( + // Unknown? fall down to the method call + ), + (Slice, + if( ty_idx == ::HIR::CoreType::Usize ) { + // Slices can be trivially indexed using usize + return ; + } + // Any other index type goes to the function call + ), + (Array, + if( ty_idx == ::HIR::CoreType::Usize ) { + // Arrays also can be trivially indexed using usize + return ; + } + // Any other index type goes to the function call + ) + ) + + // TODO: Which trait should be used? + TODO(sp, "Determine which trait should be used for index overload"); + } }; class OuterVisitor: public ::HIR::Visitor |