-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Bad diagnostic: "error: struct literal body without path" #82051
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
Comments
How are you trying this exactly? Your link doesn't generate the error you showed, it only generates the last error:
I tried with both stable and nightly channels of the playground link. Still, the error message is much better when using |
Oops, it looks like I messed things up while trying to clean things up. That error message was generated with a comma, here: if Example { a: one(), }.is_pos() {
^ The code with the comma removed produces that shorter (still bad) error message! I'm going to edit the initial post to avoid confusing anyone else trying to reproduce it. |
I don't know how to improve this error but let me explain the problem, perhaps someone else can figure it out. When parsing an Then, after a long chain of calls, we see a path (
With fn is_certainly_not_a_block(&self) -> bool {
self.look_ahead(1, |t| t.is_ident())
&& (
// `{ ident, ` cannot start a block.
self.look_ahead(2, |t| t == &token::Comma)
|| (self.look_ahead(2, |t| t == &token::Colon)
&& (
// `{ ident: token, ` cannot start a block.
self.look_ahead(4, |t| t == &token::Comma) ||
// `{ ident: ` cannot start a block unless it's a type ascription `ident: Type`.
self.look_ahead(3, |t| !t.can_begin_type())
))
)
} The difference is As a result, (I don't know how exactly One thing I tried is to use accurate struct parsing instead of |
@rustbot label +D-confusing +D-incorrect +D-invalid-suggestion +D-newcomer-roadblock |
|
Detect struct literal needing parentheses Fix rust-lang#82051.
I tried to use a struct literal as part of a condition, and got a bad error message. Here's a reduced version that fails:
Playground link.
This gives these rather poor error messages which don't align with the actual problem:
(If you remove the trailing comma inside the struct literal, it only produces the second of these two errors.)
If I change the
one()
to a literal1
, then it gives a much more useful error message:So something about having a function call in the struct initializer breaks the diagnostic.
Meta
Tested against the
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: