[gcc r15-8323] gccrs: Attempted to access a nonexistent field [E0609]
Arthur Cohen
cohenarthur@gcc.gnu.org
Wed Mar 19 14:39:02 GMT 2025
https://gcc.gnu.org/g:bc2331a565d8005b91495df627f3fa72870770cc
commit r15-8323-gbc2331a565d8005b91495df627f3fa72870770cc
Author: Muhammad Mahad <mahadtxt@gmail.com>
Date: Thu Aug 15 16:44:55 2024 +0000
gccrs: Attempted to access a nonexistent field [E0609]
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Add error code and update error message
gcc/testsuite/ChangeLog:
* rust/compile/nonexistent-field.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Diff:
---
gcc/rust/typecheck/rust-hir-type-check-expr.cc | 7 +++++--
gcc/testsuite/rust/compile/nonexistent-field.rs | 14 ++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 0e897813d8f0..81d829525504 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -85,7 +85,9 @@ TypeCheckExpr::visit (HIR::TupleIndexExpr &expr)
TupleIndex index = expr.get_tuple_index ();
if ((size_t) index >= tuple->num_fields ())
{
- rust_error_at (expr.get_locus (), "unknown field at index %i", index);
+ rust_error_at (expr.get_locus (), ErrorCode::E0609,
+ "no field %qi on type %qs", index,
+ resolved->get_name ().c_str ());
return;
}
@@ -1078,7 +1080,8 @@ TypeCheckExpr::visit (HIR::FieldAccessExpr &expr)
&lookup, nullptr);
if (!found)
{
- rust_error_at (expr.get_locus (), "unknown field [%s] for type [%s]",
+ rust_error_at (expr.get_locus (), ErrorCode::E0609,
+ "no field %qs on type %qs",
expr.get_field_name ().as_string ().c_str (),
adt->as_string ().c_str ());
return;
diff --git a/gcc/testsuite/rust/compile/nonexistent-field.rs b/gcc/testsuite/rust/compile/nonexistent-field.rs
new file mode 100644
index 000000000000..e20c49d3ebf4
--- /dev/null
+++ b/gcc/testsuite/rust/compile/nonexistent-field.rs
@@ -0,0 +1,14 @@
+#![allow(unused)]
+fn main() {
+ struct StructWithFields {
+ x: u32,
+ }
+
+ let s = StructWithFields { x: 0 };
+ s.foo;
+ // { dg-error "no field .foo. on type .StructWithFields.StructWithFields .x.u32... .E0609." "" { target *-*-* } .-1 }
+
+ let numbers = (1, 2, 3);
+ numbers.3;
+ // { dg-error "no field .3. on type ..<integer>, <integer>, <integer>.. .E0609." "" { target *-*-* } .-1 }
+}
More information about the Gcc-cvs
mailing list