Skip to content

Conversation

MahadMuhammad
Copy link
Contributor

Constructor is missing fields - E0063

Added error code for Missing Field in
struct or struct-like enum variant.


Tested Code From E0063

// https://doc.rust-lang.org/error_codes/E0063.html
struct Foo {
    x: i32,
    y: i32,
    z: i32,
}

fn main() {
    let x = Foo { x: 0 , y:1 }; // { dg-error "constructor is missing fields" }
}

Output:

➜  gccrs-build gcc/crab1 /home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/missing_constructor_fields.rs
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/missing_constructor_fields.rs:9:13: error: constructor is missing fields [E0063]
    9 |     let x = Foo { x: 0 , y:1 }; // { dg-error "constructor is missing fields" }
      |             ^~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): called error function.

gcc/testsuite/ChangeLog:

* rust/compile/missing_constructor_fields.rs: New test.

Added error code for Missing Field in
struct or struct-like enum variant.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve):
	called error function.

gcc/testsuite/ChangeLog:

	* rust/compile/missing_constructor_fields.rs: New test.

Signed-off-by: Muhammad Mahad <[email protected]>
{
rust_error_at (struct_expr.get_locus (),
rust_error_at (struct_expr.get_locus (), ErrorCode ("E0063"),
"constructor is missing fields");
Copy link
Contributor Author

@MahadMuhammad MahadMuhammad Jul 6, 2023

Choose a reason for hiding this comment

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

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 this pull request to the merge queue Jul 6, 2023
Merged via the queue into Rust-GCC:master with commit 0aa7ed7 Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants