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
Add a visibility suggestion in private-in-public errors #113983
base: master
Are you sure you want to change the base?
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
r? compiler-errors |
I don't think this change is still relevant after #113126. |
@petrochenkov thx for the heads up! I looked through that PR (even left a comment), but I'm not certain I understand if it will cover all cases? I see this change adds if self.in_assoc_ty && !vis.is_at_least(self.required_visibility, self.tcx) { |
r? petrochenkov |
This comment was marked as resolved.
This comment was marked as resolved.
@nyurik any updates? |
e9c1d6d
to
bb3e619
Compare
@Dylan-DPC thx for the ping, i have updated the PR, but it still has some outstanding questions that need some feedback. Thx! |
@petrochenkov hi, would you be the right person to review this? I would love to move forward, but it is a bit unclear. Plus @JohnCSimon was pinging the original author of this PR (before my refactoring). Hopefully the outstanding questions can be easily addressed. Thx!! |
Yes, but maybe a bit later, I'm busy this week. |
@@ -1475,12 +1475,31 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { | |||
} | |||
}; | |||
|
|||
// FIXME: this code was adapted from the above `vis_descr` computation, | |||
// but it's not clear if it's correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think fn vis_to_string
should be usable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure it will work. I tried to
- add
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
to Cargo.toml - use it with
let vis_sugg = rustc_ast_pretty::pprust::vis_to_string(&self.required_visibility);
But the ty::Visibility
that I have here -- enum { Default, Hidden, Protected }
is not the same as the one vis_to_string
expects -- a struct ast::Visibility
with kind/span/tokens
. Is there a way i can get the struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant ty::Visibility::to_string
, not vis_to_string
from rustc_ast_pretty, sorry.
ty::Visibility::to_string
was also called vis_to_string
when this comment was written, but it was renamed in #115993.
pub descr: DiagnosticArgFromDisplay<'a>, | ||
#[label(privacy_visibility_label)] | ||
pub vis_span: Span, | ||
#[suggestion(code = "", applicability = "maybe-incorrect")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suggested visibility should probably go to the code
here, rather than to the suggestion message.
This comment was marked as resolved.
This comment was marked as resolved.
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
7ebf1a8
to
95db42f
Compare
@nyurik any updates on replying to the changes requested in the review and implement them accordingly? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for the ping! I am still interested in this PR, but got a bit stuck on implementing it
@@ -1475,12 +1475,31 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { | |||
} | |||
}; | |||
|
|||
// FIXME: this code was adapted from the above `vis_descr` computation, | |||
// but it's not clear if it's correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure it will work. I tried to
- add
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
to Cargo.toml - use it with
let vis_sugg = rustc_ast_pretty::pprust::vis_to_string(&self.required_visibility);
But the ty::Visibility
that I have here -- enum { Default, Hidden, Protected }
is not the same as the one vis_to_string
expects -- a struct ast::Visibility
with kind/span/tokens
. Is there a way i can get the struct?
☔ The latest upstream changes (presumably #121489) made this pull request unmergeable. Please resolve the merge conflicts. |
This modifies the original #112540 by @aryan-debug to fix #112284
This PR introduces a new field
vis_sugg
to suggest the proper visibility for the error.TODO: What should the
TODO
values be here? Note that not a single test anywhere has used these???TODO???
values, so it is unclear how they can be generated. Maybe this whole match should be simplified to mapRestricted(_) => "pub(crate)"
?