Skip to content

Give better diagnostic when using a private tuple struct constructor #76499

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

Merged
merged 1 commit into from
Sep 11, 2020

Conversation

guswynn
Copy link
Contributor

@guswynn guswynn commented Sep 8, 2020

Fixes #75907

Some notes:

  1. This required some deep changes, including removing a Copy impl for PatKind. If some tests fail, I would still appreciate review on the overall approach
  2. this only works with basic patterns (no wildcards for example), and fails if there is any problems getting the visibility of the fields (i am not sure what the failure that can happen in resolve_visibility_speculative, but we check the length of our fields in both cases against each other, so if anything goes wrong, we fall back to the worse error. This could be extended to more patterns
  3. this does not yet deal with [diagnostics] Attempting to initialize a private field in a public tuple struct yields confusing error message #75906, but I believe it will be similar
  4. let me know if you want more tests
  5. doesn't yet at the suggestion that @yoshuawuyts suggested at the end of their issue, but that could be added relatively easily (i believe)

@rust-highfive
Copy link
Contributor

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

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 8, 2020
@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 9, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 9, 2020

I'd be interested whether this affects perf.

@guswynn
Copy link
Contributor Author

guswynn commented Sep 9, 2020

@jyn514 I think the clones are the same as the original Copy's, but not sure, is there a way to queue a perf check?

@jyn514
Copy link
Member

jyn514 commented Sep 9, 2020

Yes, but I'd prefer not to until someone familiar with this part of the compiler agrees this is the right approach (the perf server has a tendency to fall behind master if you queue too many builds).

@Aaron1011
Copy link
Member

There's currently only one job in the perf queue, so I think it should be fine. Also, the total perf job running time was decreased last month in rust-lang/rustc-perf#740, and I haven't seen the perf queue growing out of control since them.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Collaborator

bors commented Sep 9, 2020

⌛ Trying commit b1075c6eae2da6f043d333bf99985120850efda0 with merge 1e1632e45f7c9ad03e2e1c4a32e81de6019cf26f...

@jyn514
Copy link
Member

jyn514 commented Sep 9, 2020

Oh nice, I didn't realize perf was no longer running script-servo :)

@bors
Copy link
Collaborator

bors commented Sep 9, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 1e1632e45f7c9ad03e2e1c4a32e81de6019cf26f (1e1632e45f7c9ad03e2e1c4a32e81de6019cf26f)

@rust-timer
Copy link
Collaborator

Queued 1e1632e45f7c9ad03e2e1c4a32e81de6019cf26f with parent 90782cb, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (1e1632e45f7c9ad03e2e1c4a32e81de6019cf26f): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@jyn514
Copy link
Member

jyn514 commented Sep 9, 2020

Perf results look like noise, it says max-rss went down but since you added more fields here that can't be right.

@petrochenkov
Copy link
Contributor

r? @petrochenkov

@petrochenkov
Copy link
Contributor

This PR hides the correct error that attempts to teach you the actual language rules ("private fields make the constructor private") and masks it with something plausibly looking, but not really correct.

@petrochenkov
Copy link
Contributor

petrochenkov commented Sep 9, 2020

It would be better to keep the current primary message and add a note to it with a multi-span pointing to those private fields that it mentions.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 9, 2020
@guswynn
Copy link
Contributor Author

guswynn commented Sep 9, 2020

Genuinely astounded that adding 'a: 'ast bounds in 3 places resolved the errors i got, that said, i suppose nothing lives longer than the ast

@guswynn guswynn force-pushed the priv_des branch 2 times, most recently from ba13651 to 433b50f Compare September 9, 2020 22:07
@guswynn
Copy link
Contributor Author

guswynn commented Sep 10, 2020

@estebank do you think it will be not too noisy to add a span_label for every private field? Other than question, your idea to make a multispan from the span's, label them, add a note, and set the span and then instead of set_primary_message, use span_note

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 10, 2020
@@ -796,6 +796,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
vis
};

let mut ret_fields = vec![];
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
let mut ret_fields = vec![];
let mut field_visibilities = Vec::with_capacity(vdata.fields().len());

Copy link
Contributor

Choose a reason for hiding this comment

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

Not addressed yet.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 10, 2020
@guswynn
Copy link
Contributor Author

guswynn commented Sep 10, 2020

This doesn't work cross-crate :((( I added a test that shows that

Not sure what I should do to resolve that

@petrochenkov
Copy link
Contributor

I'll try to check what can be done in the cross-crate case, but it's better done in a separate PR.
We should be able to decode fields and their visibilities from other crates if necessary for error reporting, but it should not be done on happy path (if no errors are reported).

@estebank
Copy link
Contributor

@guswynn I think that the new output looks reasonable and informative.

I'll try to check what can be done in the cross-crate case, but it's better done in a separate PR.

+100

@petrochenkov
Copy link
Contributor

r=me after addressing the remaining nits (#76499 (comment), #76499 (comment)) and squashing commits.

@guswynn
Copy link
Contributor Author

guswynn commented Sep 11, 2020

@petrochenkov thank you so much for the detailed review and help on the most complicated rust-lang/rust pr I have ever done!

@petrochenkov
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Sep 11, 2020

📌 Commit c63f634 has been approved by petrochenkov

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 11, 2020
@bors
Copy link
Collaborator

bors commented Sep 11, 2020

⌛ Testing commit c63f634 with merge bc57bd8...

@bors
Copy link
Collaborator

bors commented Sep 11, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: petrochenkov
Pushing bc57bd8 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 11, 2020
@bors bors merged commit bc57bd8 into rust-lang:master Sep 11, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 11, 2020
@guswynn guswynn deleted the priv_des branch September 15, 2020 15:29
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 merged-by-bors This PR was explicitly merged by bors. 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
10 participants