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

Fatal Error: used more than once - [E0062] #2381

Closed
MahadMuhammad opened this issue Jul 5, 2023 · 1 comment · Fixed by #2797
Closed

Fatal Error: used more than once - [E0062] #2381

MahadMuhammad opened this issue Jul 5, 2023 · 1 comment · Fixed by #2797
Labels

Comments

@MahadMuhammad
Copy link
Contributor

MahadMuhammad commented Jul 5, 2023

Fatal Error - used more than once

  • Fixing this error will improve gccrs to emit error codes similiar to rustc.
  • You can view the same on compiler-explorer

I tried this code from E0062:

struct Foo {
    x: i32,
}

fn main() {
    let x = Foo {
                x: 0,
                x: 0, // error: field `x` specified more than once
            };
}

I expected to see this happen:

  • Give error like rustc
error[E0062]: field `x` specified more than once
 --> <source>:8:17
  |
7 |                 x: 0,
  |                 ---- first use of `x`
8 |                 x: 0, // error: field `x` specified more than once
  |                 ^ used more than once

error: aborting due to previous error

For more information about this error, try `rustc --explain E0062`.
Compiler returned: 1

Instead, this happened:

  • It gives fatal error
<source>:8:17: fatal error: used more than once
    8 |                 x: 0, // error: field `x` specified more than once
      |                 ^
compilation terminated.
Compiler returned: 1

Meta

  • What version of Rust GCC were you using, git sha 5406b63.
  • Godbolt version : gccrs (Compiler-Explorer-Build-gcc-2f91d511200bf85558c9013b09a458c06edd1e02-binutils-2.40) 13.0.1 20230417 (experimental)

@robertgoss
Copy link
Contributor

Would it be ok for me to pick this up?

robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#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 <goss.robert@gmail.com>
robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#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 <goss.robert@gmail.com>
robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#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 <goss.robert@gmail.com>
robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#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.rs: Added case with fields in constructor repeated

Signed-off-by: Robert Goss <goss.robert@gmail.com>
robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#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:

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

gcc/testsuite/ChangeLog:
	* rust/compile/repeated_constructor_fields.rs: Added case with fields in constructor repeated

Signed-off-by: Robert Goss <goss.robert@gmail.com>
robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#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:

	* gcc/rust/typecheck/rust-hir-type-check-struct-field.h: Allow visit to return a bool
	* gcc/rust/typecheck/rust-hir-type-check-struct-field.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>
robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#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>
robertgoss added a commit to robertgoss/gccrs that referenced this issue Jan 17, 2024
Fixes Rust-GCC#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>
github-merge-queue bot pushed a commit that referenced this issue Jan 18, 2024
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>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 26, 2024
Fixes Rust-GCC#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>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 26, 2024
…ructor

Fixes Rust-GCC#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>
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Feb 5, 2024
…ructor

Fixes Rust-GCC#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants