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

propagate the error from parsing enum variant to the parser and emit out #105098

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

lyming2007
Copy link

@lyming2007 lyming2007 commented Nov 30, 2022

While parsing enum variant, the error message always disappear
Because the error message that emit out is from main error of parser
The information of enum variant disappears while parsing enum variant with error
We only check the syntax of expecting token, i.e, in case #103869
It will error it without telling the message that this error is from pasring enum variant.
Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err
Check the sub-error before emitting the main error of parser and attach it.
Fix #103869

@rustbot
Copy link
Collaborator

rustbot commented Nov 30, 2022

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eholk (or someone else) soon.

Please see the contribution instructions for more information.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 30, 2022
@@ -1414,7 +1414,10 @@ impl<'a> Parser<'a> {

Ok((Some(vr), TrailingToken::MaybeComma))
},
)
).map_err(|mut err|{
err.help("enum variants can be `Variant` or `Variant = <integer>` or `Variant(Type)` or `Variant { field: Type }`");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
err.help("enum variants can be `Variant` or `Variant = <integer>` or `Variant(Type)` or `Variant { field: Type }`");
err.help("enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type)`, or `Variant { field: Type }`");

I wonder if we should write Variant(Type) as Variant(Type, ...) or Variant(Type1, ..., TypeN), and similarly for the struct case? Or maybe Variant(Types) and Variant { fields: types }. Basically, I wonder if it's worth trying to also show that enum variants can have multiple fields or is showing one enough?

src/test/ui/structs/struct-fn-in-definition.stderr Outdated Show resolved Hide resolved
@eholk
Copy link
Contributor

eholk commented Dec 2, 2022

Thanks for the contribution! Overall, this looks pretty good. I posted a couple of questions about minor tweaks to the hint message, but I think this is a big improvement.

One suggestion I'd add for future PRs. In the commit description, rather than just saying "fix #103869," it'd be helpful if you could include a brief summary of the bug you're fixing (just a sentence or two and maybe a short code example if it makes sense) and how your PR fixes it (this isn't always going to be that interesting, but especially if there's something subtle about the fix this can be really helpful). As a reviewer that helps a lot because it saves me a step in having to pull up the issue and read the description first.

Thanks again! I'll give you a little time in case you want to respond to any of my review comments, but I don't think I'd consider any of them blockers.

Because the error message that emit out is from main error of parser
The information of enum variant disappears while parsing enum variant with error
We only check the syntax of expecting token, i.e, in case rust-lang#103869
It will error it without telling the message that this error is from pasring enum variant.
Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err
Check the sub-error before emitting the main error of parser and attach it.
Fix rust-lang#103869
@lyming2007
Copy link
Author

Thanks for the contribution! Overall, this looks pretty good. I posted a couple of questions about minor tweaks to the hint message, but I think this is a big improvement.

One suggestion I'd add for future PRs. In the commit description, rather than just saying "fix #103869," it'd be helpful if you could include a brief summary of the bug you're fixing (just a sentence or two and maybe a short code example if it makes sense) and how your PR fixes it (this isn't always going to be that interesting, but especially if there's something subtle about the fix this can be really helpful). As a reviewer that helps a lot because it saves me a step in having to pull up the issue and read the description first.

Thanks again! I'll give you a little time in case you want to respond to any of my review comments, but I don't think I'd consider any of them blockers.
Thank you Eric for the feedback! I've updated the commit description. Here is it:
While parsing enum variant, the error message always disappear
Because the error message that emit out is from main error of parser
The information of enum variant disappears while parsing enum variant with error
We only check the syntax of expecting token, i.e, in case #103869
It will error it without telling the message that this error is from pasring enum variant.
Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err
Check the sub-error before emitting the main error of parser and attach it.
Fix #103869

@eholk
Copy link
Contributor

eholk commented Dec 6, 2022

Thanks, looks good!

@bors r+

@bors
Copy link
Contributor

bors commented Dec 6, 2022

📌 Commit 0e19fb9 has been approved by eholk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 6, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 6, 2022
propagate the error from parsing enum variant to the parser and emit out

While parsing enum variant, the error message always disappear
Because the error message that emit out is from main error of parser
The information of enum variant disappears while parsing enum variant with error
We only check the syntax of expecting token, i.e, in case rust-lang#103869
It will error it without telling the message that this error is from pasring enum variant.
Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err
Check the sub-error before emitting the main error of parser and attach it.
Fix rust-lang#103869
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 6, 2022
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#104439 (Add prototype to generate `COPYRIGHT` from REUSE metadata)
 - rust-lang#105005 (On E0195 point at where clause lifetime bounds)
 - rust-lang#105098 (propagate the error from parsing enum variant to the parser and emit out)
 - rust-lang#105243 (remove no-op 'let _ = ')
 - rust-lang#105254 (Recurse into nested impl-trait when computing variance.)
 - rust-lang#105287 (Synthesize substitutions for bad auto traits in dyn types)
 - rust-lang#105310 (Be more careful about unresolved exprs in suggestion)
 - rust-lang#105318 (Make `get_impl_future_output_ty` work with AFIT)
 - rust-lang#105339 (support `ConstKind::Expr` in `is_const_evaluatable` and `WfPredicates::compute`)
 - rust-lang#105340 (Avoid ICE by accounting for missing type)
 - rust-lang#105342 (Make `note_obligation_cause_code`  take a `impl ToPredicate` for predicate)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 48172ff into rust-lang:master Dec 6, 2022
@rustbot rustbot added this to the 1.67.0 milestone Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message when defining enum using struct syntax
6 participants