]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Add improved error when a field is redefined in a struct constructor
authorRobert Goss <goss.robert@gmail.com>
Tue, 16 Jan 2024 22:50:51 +0000 (22:50 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 30 Jan 2024 11:36:51 +0000 (12:36 +0100)
commit88a27c3bc0f1ecf91699b0dbc38bd00dc87a47a4
treeef6cfa7faddc642bf1665d618e741cc690ef4149
parent7a0c487d2c54b3cf3a83563add89a87220a109c2
gccrs: Add improved error when a field is redefined in a struct constructor

Fixes #2381

If a struct type is initialized with one of it's fields repeated it will currently issue an error at the use site. However we would like to give the rust error code and (like rustc) show both the specifications for the field to help the user diagnose the issue.

We move the check after the index for the field has been established so we can look up if the field has already been defined and get it's location.

We update the visit method to return if it has handled an error otherwise we then output a second fatal error as not all the field in the specification have been processed.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct-field.h: Allow visit to return a bool
* typecheck/rust-hir-type-check-struct.cc: Improve check of repeat fields

gcc/testsuite/ChangeLog:

* rust/compile/repeated_constructor_fields.rs: Added case with constructor field repeated

Signed-off-by: Robert Goss <goss.robert@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-struct-field.h
gcc/rust/typecheck/rust-hir-type-check-struct.cc
gcc/testsuite/rust/compile/repeated_constructor_fields.rs [new file with mode: 0644]