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

initializer & field location info missing in Error message #2388

Open
MahadMuhammad opened this issue Jul 6, 2023 · 1 comment
Open

initializer & field location info missing in Error message #2388

MahadMuhammad opened this issue Jul 6, 2023 · 1 comment
Labels

Comments

@MahadMuhammad
Copy link
Contributor

Improving Error Constructor is missing fields - E0063


I tried this 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" }
}

I expected to see this happen:

  • Emit error message, similiar to rustc .i.e.,
    • emit the name of initializer & field
  • Error message emitted by rustc:
error[E0063]: missing field `y` in initializer of `Foo`
 --> <source>:7:13
  |
7 |     let x = Foo {  x:0}; // error: missing field: `y`
  |             ^^^ missing `y`

error: aborting due to previous error

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

Instead, this happened:

  • No initializer & field information in error messge.
  • This is the output of gccrs:
- missing field `y` in initializer of `Foo` // rustc output
+ error: constructor is missing fields [E0063] // gccrs 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.

Meta

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

@MahadMuhammad
Copy link
Contributor Author

I tried to fix this issue by changes these lines of code by :

else if (!struct_expr.has_struct_base ())
{
rust_error_at (struct_expr.get_locus (),
"constructor is missing fields");
return;
}

  • To this :
rust_error_at (struct_expr.get_locus (), 
-  	      "constructor is missing fields");
+             "missing field %qs in initializer of %qs",
+              variant->get_fields ().at (0)->get_name ().c_str (), // This need to be changed
+              struct_path_resolved->get_name ().c_str ()); // This is giving right struct name
  • But @CohenArthur said, we need some more changes to do this....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant