diff --git a/gcc/rust/typecheck/rust-tyty-util.cc b/gcc/rust/typecheck/rust-tyty-util.cc index c6c740b2cba..72761d9842b 100644 --- a/gcc/rust/typecheck/rust-tyty-util.cc +++ b/gcc/rust/typecheck/rust-tyty-util.cc @@ -30,7 +30,8 @@ TyVar::TyVar (HirId ref) : ref (ref) auto context = Resolver::TypeCheckContext::get (); BaseType *lookup = nullptr; bool ok = context->lookup_type (ref, &lookup); - rust_assert (ok); + if (!ok || lookup == nullptr || lookup->get_kind () == TypeKind::ERROR) + return; } BaseType * @@ -39,7 +40,8 @@ TyVar::get_tyty () const auto context = Resolver::TypeCheckContext::get (); BaseType *lookup = nullptr; bool ok = context->lookup_type (ref, &lookup); - rust_assert (ok); + if (!ok || lookup == nullptr) + return nullptr; return lookup; } @@ -95,7 +97,10 @@ TyVar::subst_covariant_var (TyTy::BaseType *orig, TyTy::BaseType *subst) TyVar TyVar::clone () const { - TyTy::BaseType *c = get_tyty ()->clone (); + TyTy::BaseType *base = get_tyty (); + if (base == nullptr || base->get_kind () == TypeKind::ERROR) + return TyVar::get_implicit_infer_var (UNKNOWN_LOCATION); + TyTy::BaseType *c = base->clone (); return TyVar (c->get_ref ()); } @@ -105,6 +110,10 @@ TyVar::monomorphized_clone () const auto &mappings = Analysis::Mappings::get (); auto context = Resolver::TypeCheckContext::get (); + TyTy::BaseType *base = get_tyty (); + if (base == nullptr || base->get_kind () == TypeKind::ERROR) + return TyVar::get_implicit_infer_var (UNKNOWN_LOCATION); + // this needs a new hirid TyTy::BaseType *c = get_tyty ()->monomorphized_clone (); c->set_ref (mappings.get_next_hir_id ()); diff --git a/gcc/testsuite/rust/compile/issue-3556.rs b/gcc/testsuite/rust/compile/issue-3556.rs new file mode 100644 index 00000000000..be7d85a93b5 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3556.rs @@ -0,0 +1,4 @@ +fn main() { + let ref mut a @ (ref mut b,); + // { dg-error "expected T\\?, found tuple" "" { target *-*-* } .-1 } +} \ No newline at end of file