|| scrutinee_kind == TyTy::TypeKind::TUPLE
|| scrutinee_kind == TyTy::TypeKind::REF);
- if (scrutinee_kind == TyTy::TypeKind::ADT)
- {
- // this will need to change but for now the first pass implementation,
- // lets assert this is the case
- 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)
+ if (scrutinee_kind == TyTy::TypeKind::FLOAT)
{
// FIXME: CASE_LABEL_EXPR does not support floating point types.
// Find another way to compile these.
return;
}
+ // if the result of this expression is meant to be never type then we can
+ // optimise this away but there is the case where match arms resolve to !
+ // because of return statements we need to special case this
+ if (!expr.has_match_arms () && expr_tyty->is<TyTy::NeverType> ())
+ {
+ translated = unit_expression (expr.get_locus ());
+ return;
+ }
+
fncontext fnctx = ctx->peek_fn ();
Bvariable *tmp = NULL;
tree enclosing_scope = ctx->peek_enclosing_scope ();
check_match_usefulness (Resolver::TypeCheckContext *ctx,
TyTy::BaseType *scrutinee_ty, HIR::MatchExpr &expr)
{
+ if (!expr.has_match_arms ())
+ return;
+
// Lower the arms to a more convenient representation.
std::vector<MatrixRow> rows;
for (auto &arm : expr.get_match_cases ())
TyTy::BaseType *scrutinee_tyty
= TypeCheckExpr::Resolve (expr.get_scrutinee_expr ());
+ // https://github.com/Rust-GCC/gccrs/issues/3231#issuecomment-2462660048
+ // https://github.com/rust-lang/rust/blob/3d1dba830a564d1118361345d7ada47a05241f45/compiler/rustc_hir_typeck/src/_match.rs#L32-L36
+ if (!expr.has_match_arms ())
+ {
+ // this is a special case where rustc returns !
+ TyTy::BaseType *lookup = nullptr;
+ bool ok = context->lookup_builtin ("!", &lookup);
+ rust_assert (ok);
+ infered = lookup->clone ();
+ return;
+ }
+
bool saw_error = false;
std::vector<TyTy::BaseType *> kase_block_tys;
for (auto &kase : expr.get_match_cases ())