gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc
(check_match_scrutinee): Add assertion.
* backend/rust-compile-pattern.cc
(CompilePatternCheckExpr::visit):
Handle HIR::PathInExpression matching a non-enum.
gcc/testsuite/ChangeLog:
* rust/compile/match-struct-path.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (scrutinee_expr_tyty);
if (adt->is_enum ())
rust_assert (adt->number_of_variants () > 0);
+ else
+ rust_assert (adt->number_of_variants () == 1);
}
else if (scrutinee_kind == TyTy::TypeKind::FLOAT)
{
&lookup);
rust_assert (ok);
- // this must be an enum
- // TODO: might not be
+ // must be an ADT (?)
rust_assert (lookup->get_kind () == TyTy::TypeKind::ADT);
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (lookup);
- rust_assert (adt->is_enum ());
+
+ // if this isn't an enum, always succeed
+ if (!adt->is_enum ())
+ {
+ check_expr = boolean_true_node;
+ return;
+ }
// lookup the variant
HirId variant_id;
--- /dev/null
+pub struct S;
+
+pub fn foo(v: S) {
+ match v {
+ S => ()
+ }
+}