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

Better error message when struct construction field name is left "implicit" #4909

Closed
jdm opened this issue Feb 13, 2013 · 10 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-frontend Area: Compiler frontend (errors, parsing and HIR) P-low Low priority

Comments

@jdm
Copy link
Contributor

jdm commented Feb 13, 2013

(Updated with concrete example:)

struct Foo {
    A: int,
    B: int
}

fn main() {
    let B = 3i;
    let x = Foo{A:1,B};
}

yields (live playpen: http://is.gd/GDjwLK)

<anon>:8:22: 8:23 error: expected `:` but found `}`
<anon>:8     let x = Foo{A:1,B};
                              ^

This feels like something we should be able to better report (possibly as a note suggestion).

Original bug report follows:

/run/media/jdm/ssd/servo/src/servo/dom/bindings/ClientRectBinding.rs:254:61: 254:62 error: expected `;` but found `{`
/run/media/jdm/ssd/servo/src/servo/dom/bindings/ClientRectBinding.rs:254 const NativeHooks: NativePropertyHooks = 
                 NativePropertyHooks { 0 as *u8, ResolveProperty, 0 as *u8, EnumerateProperties, 0 as *NativePropertyHooks };

This feels like something we should be able to better report (possibly as a note suggestion).

@catamorphism
Copy link
Contributor

Not critical for 0.7. Nominating for milestone 5, production-ready

@graydon
Copy link
Contributor

graydon commented May 2, 2013

accepted for production ready

@graydon
Copy link
Contributor

graydon commented Jul 18, 2013

Still present, still just about as unpleasant an error message.

@pnkfelix
Copy link
Member

assigning P-low.

@eminence
Copy link
Contributor

In the latest master (e2273d9), this looks to be fixed:

struct Foo {
    A: int,
    B: int
}

fn main() {
    let x = Foo{A:1};
}
test.rs:7:13: 7:21 error: missing field: `B` [E0063]
test.rs:7     let x = Foo{A:1};
                      ^~~~~~~~

@pnkfelix
Copy link
Member

@eminence your example does not reflect what the bug report is asking about.

Here is variant of your example that illustrates the problem in the description (which I will also add to the bug description after I finish typing this comment): http://is.gd/GDjwLK

(also updated title to better reflect the description)

@pnkfelix pnkfelix changed the title Better error message when struct field names are missing Better error message when struct construction field name is left "implicit" Aug 14, 2014
@eminence
Copy link
Contributor

ah, my apologies -- I did not properly understand the reported issue. thanks for the clarification.

@frewsxcv
Copy link
Member

visiting for triage

The error message has not changed for the original code example, so this issue is still valid

@birkenfeld
Copy link
Contributor

Current message:

<anon>:8:22: 8:23 error: expected `:`, found `}`
<anon>:8     let x = Foo{A:1,B};
                              ^
<anon>:8:13: 8:23 error: missing field `B` in initializer of `Foo` [E0063]
<anon>:8     let x = Foo{A:1,B};
                     ^~~~~~~~~~
<anon>:8:13: 8:23 help: see the detailed explanation for E0063

Are these two together clear enough?

@jdm
Copy link
Contributor Author

jdm commented Sep 25, 2016

That seems like a good enough improvement to me.

@jdm jdm closed this as completed Sep 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-frontend Area: Compiler frontend (errors, parsing and HIR) P-low Low priority
Projects
None yet
Development

No branches or pull requests

7 participants