mir: fix array indexing, enum lowering
@@ -78,6 +78,10 @@ pub fn lower_expr_to_mir_rvalue<'gcx>(
match builder.cx.hir_of(binding)? {
HirNode::VarDecl(decl) => Ok(builder.build(ty, RvalueKind::Var(decl.id))),
HirNode::Port(port) => Ok(builder.build(ty, RvalueKind::Port(port.id))),
+ HirNode::EnumVariant(..) => {
+ let k = builder.cx.constant_value_of(expr_id, env)?;
+ Ok(builder.build(k.ty, RvalueKind::Const(k)))
+ }
x => {
builder.cx.emit(
DiagBuilder2::error(format!(
@@ -224,8 +228,12 @@ pub fn lower_expr_to_mir_rvalue<'gcx>(
}
};
- // Cast the indexed array to a simple bit vector type.
+ // Cast the target to a simple bit vector type if needed.
let target_ty = cx.type_of(target, env)?;
+ let target = if target_ty.is_array() {
+ // No need to cast arrays.
+ lower_expr_to_mir_rvalue(cx, target, env)
+ } else {
let sbvt = match map_to_simple_bit_vector_type(cx, target_ty, env) {
Some(ty) => ty,
None => {
@@ -244,7 +252,8 @@ pub fn lower_expr_to_mir_rvalue<'gcx>(
return Ok(builder.error());
}
};
- let target = lower_expr_and_cast(cx, target, env, sbvt);
+ lower_expr_and_cast(cx, target, env, sbvt)
+ };
// Build the cast rvalue.
Ok(builder.build(
