aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-04-17 13:50:55 +0100
committerPhilip Herron <philip.herron@embecosm.com>2025-04-18 14:01:15 +0000
commitf81ec04bfde4e771998b44dd5c685069d1229652 (patch)
tree9a976c3a47b4164cf555245a95577eb7c6c33bde /gcc/rust
parent0a34f7bb91855ac95c51219c89d4049c4d69f7b3 (diff)
downloadgcc-f81ec04bfde4e771998b44dd5c685069d1229652.zip
gcc-f81ec04bfde4e771998b44dd5c685069d1229652.tar.gz
gcc-f81ec04bfde4e771998b44dd5c685069d1229652.tar.bz2
gccrs: Fix ICE when handling case of unknown field in HIR::FieldAccess
We were wrongly adding the assertion that this must not be an enum but this is a pointless assertion we only care that there are variant in the ADT and if the field exists in the first variant. Fixes Rust-GCC#3581 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bad assertion gcc/testsuite/ChangeLog: * rust/compile/nonexistent-field.rs: fix bad error message * rust/compile/issue-3581-1.rs: New test. * rust/compile/issue-3581-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-expr.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index b960e73..115aba7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1142,27 +1142,25 @@ TypeCheckExpr::visit (HIR::FieldAccessExpr &expr)
bool is_valid_type = struct_base->get_kind () == TyTy::TypeKind::ADT;
if (!is_valid_type)
{
- rust_error_at (expr.get_locus (),
- "expected algebraic data type got: [%s]",
- struct_base->as_string ().c_str ());
+ rust_error_at (expr.get_locus (), "expected algebraic data type got %qs",
+ struct_base->get_name ().c_str ());
return;
}
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (struct_base);
- rust_assert (!adt->is_enum ());
- rust_assert (adt->number_of_variants () == 1);
-
+ rust_assert (adt->number_of_variants () > 0);
TyTy::VariantDef *vaiant = adt->get_variants ().at (0);
TyTy::StructFieldType *lookup = nullptr;
bool found = vaiant->lookup_field (expr.get_field_name ().as_string (),
&lookup, nullptr);
- if (!found)
+ if (!found || adt->is_enum ())
{
- rust_error_at (expr.get_locus (), ErrorCode::E0609,
- "no field %qs on type %qs",
+ rich_location r (line_table, expr.get_locus ());
+ r.add_range (expr.get_field_name ().get_locus ());
+ rust_error_at (r, ErrorCode::E0609, "no field %qs on type %qs",
expr.get_field_name ().as_string ().c_str (),
- adt->as_string ().c_str ());
+ adt->get_name ().c_str ());
return;
}