-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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-field.cc: Improve check of respecification of fields gcc/testsuite/ChangeLog: * rust/compile/repeated_constructor_fields.r: Added case with fields in constructor repeated Signed-off-by: Robert Goss <[email protected]>
- Loading branch information
1 parent
6d85a80
commit 8330e3c
Showing
3 changed files
with
74 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
struct Foo { | ||
Check failure on line 1 in gcc/testsuite/rust/compile/repeated_constructor_fields.rs GitHub Actions / build-and-check-ubuntu-32bitTest failure (FAIL)
|
||
x: i32, | ||
} | ||
|
||
fn main() { | ||
let x = Foo { | ||
x: 0, | ||
x: 0, // { dg-error "field 'x' specified more than once" } | ||
}; | ||
} |