summaryrefslogtreecommitdiff
path: root/src/hir/from_ast_expr.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-11-01 20:46:36 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-11-01 20:46:36 +0800
commitcb271f8ea98d1a5c65a5e636a0e73a85710027b4 (patch)
tree9694427c074c0e0d581cde6e01b6167016e0f844 /src/hir/from_ast_expr.cpp
parent8306f43ccdf0414b48891aa5eb04d8901899c052 (diff)
downloadmrust-cb271f8ea98d1a5c65a5e636a0e73a85710027b4.tar.gz
HIR - Refactor enums to only embed a single field (and give variants types)
Diffstat (limited to 'src/hir/from_ast_expr.cpp')
-rw-r--r--src/hir/from_ast_expr.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/hir/from_ast_expr.cpp b/src/hir/from_ast_expr.cpp
index a98140d7..ef20f08d 100644
--- a/src/hir/from_ast_expr.cpp
+++ b/src/hir/from_ast_expr.cpp
@@ -629,14 +629,19 @@ struct LowerHIR_ExprNode_Visitor:
else
{
const auto& enm = *e.hir;
- auto it = ::std::find_if(enm.m_variants.begin(), enm.m_variants.end(), [&](const auto& x){ return x.first == var_name; });
- assert(it != enm.m_variants.end());
+ auto idx = enm.find_variant(var_name);
+ assert(idx != SIZE_MAX);
- var_idx = static_cast<unsigned int>(it - enm.m_variants.begin());
- if( it->second.is_Struct() ) {
- ERROR(v.span(), E0000, "Named value referring to an enum that isn't tuple-like or unit-like - " << v.m_path);
+ var_idx = idx;
+ if( const auto* ee = enm.m_data.opt_Data() )
+ {
+ if( ee->at(idx).type == ::HIR::TypeRef::new_unit() ) {
+ }
+ // TODO: Assert that it's not a struct-like
+ else {
+ is_tuple_constructor = true;
+ }
}
- is_tuple_constructor = it->second.is_Tuple();
}
(void)var_idx; // TODO: Save time later by saving this.
if( is_tuple_constructor ) {