Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E0124] field x is already declared in struct #2397

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

MahadMuhammad
Copy link
Contributor

@MahadMuhammad MahadMuhammad commented Jul 10, 2023

A struct was declared with two fields having the same name - E0124


Code tested from E0124:

// https://doc.rust-lang.org/error_codes/E0124.html
fn main() {
    struct Foo {
        field1: i32, // { dg-error "field .field1. is already declared" }
        field1: i32, // { dg-error "field .field1. is already declared" }
        field1: i32, // { dg-error "field .field1. is already declared" }
    }
}

Output:

➜  gccrs-build gcc/crab1 /home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/execute/same_field_name.rs
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/execute/same_field_name.rs:5:9: error: field ‘field1’ is already declared [E0124]
    4 |         field1: i32, // { dg-error "field .field1. is already declared" }
      |         ~~~~~~
    5 |         field1: i32, // { dg-error "field .field1. is already declared" }
      |         ^~~~~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 phase setup                        :   0.00 (  0%)   0.00 (  0%)   0.01 (100%)   138k ( 95%)
 TOTAL                              :   0.00          0.00          0.01          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (struct_field_name_exists): called error function.

gcc/testsuite/ChangeLog:

* rust/execute/same_field_name.rs: New test.

Refactored error message for more
than one duplicate fields.

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-base.cc (struct_field_name_exists):
	called error function.

gcc/testsuite/ChangeLog:

	* rust/compile/bad_pub_enumitems.rs: changed comment to pass test cases.
	* rust/compile/dup_fields.rs: likewise.
	* rust/execute/same_field_name.rs: New test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philberty philberty added the diagnostic diagnostic static analysis label Jul 11, 2023
@philberty philberty added this to the GCC 14 Stage 3 milestone Jul 11, 2023
@philberty philberty added this pull request to the merge queue Jul 11, 2023
Merged via the queue into Rust-GCC:master with commit 1827610 Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants