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

Add a suggestion to add or remove pub on private-in-public error #112540

Closed
wants to merge 3 commits into from

Conversation

aryan-debug
Copy link

@aryan-debug aryan-debug commented Jun 12, 2023

Fixes #112284

@rustbot
Copy link
Collaborator

rustbot commented Jun 12, 2023

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

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Jun 12, 2023
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

  1. This could use a better PR title -- somethat that describes what it does, like "add a suggestion to add or remove pub on private-in-public error"
  2. this probably needs the UI tests blessed (./x.py test tests/ui --bless) or if no UI tests changed due to this modification, then it needs a new UI test demonstrating the changes.
  3. Should this be a suggestion instead of a help message? Ideally we'd be suggesting where to add the "pub".

compiler/rustc_privacy/messages.ftl Outdated Show resolved Hide resolved
compiler/rustc_privacy/messages.ftl Outdated Show resolved Hide resolved
@@ -8,6 +8,8 @@ privacy_from_private_dep_in_public_interface =
privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interface
.label = can't leak {$vis_descr} {$kind}
.visibility_label = `{$descr}` declared as {$vis_descr}
.help = - Either remove the `pub` from the function
Copy link
Member

Choose a reason for hiding this comment

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

This says "from the function" -- but this isn't always fired on a function, is it?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for reviewing my changes. I am not sure if it's always fired on a function, but you are most likely correct. In that case, what would be a better suggestion?

@aryan-debug aryan-debug changed the title Issue#112284 Add a suggestion to add or remove pub on private-in-public error - Issue#112284 Jun 12, 2023
@rust-log-analyzer

This comment has been minimized.

@compiler-errors compiler-errors changed the title Add a suggestion to add or remove pub on private-in-public error - Issue#112284 Add a suggestion to add or remove pub on private-in-public error Jun 12, 2023
@WaffleLapkin
Copy link
Member

r? compiler-errors

since they already left a review

@nyurik
Copy link
Contributor

nyurik commented Jun 12, 2023

I agree that the initially proposed help message does not conform to the same style as other help messages. We have a standard way of making code suggestions that modifies the original code in the needed way, which is better than a text-only help message. So if the original code says struct Foo(i32);, the error message should suggest pub struct Foo(i32); - with the pub shown as the addition (green i think, with some underlying?)

@aryan-debug
Copy link
Author

@nyurik Sure, we can do that, but I am not sure how, since this is my very first contribution to the rust compiler. So, can you guide me on how I would get the error message to suggest the fix with green underline?

@nyurik
Copy link
Contributor

nyurik commented Jun 14, 2023

@aryan-debug thx for contributing!

My understanding is that the usual process of a lint/error reporting is that you create one or more suggestions - a Vec<(Span, String)>, where the Span represents the original code you want to modify, and the String is the replacement, and pass them to the DiagnosticBuilder instance before you submit that diagnostic builder to the system.

I'm not even close to being an expert on the Rust compiler, so take with a grain of salt :)

@nyurik
Copy link
Contributor

nyurik commented Jun 14, 2023

P.S. Search *.rs files for "consider (with a space at the end) - there are quiet a few of the ones with suggestions.

@compiler-errors
Copy link
Member

Marking this as waiting on author, see this comment for instructions how to switch it back when ready to review: #112540 (comment)

@rustbot author

@rustbot rustbot 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 Jun 15, 2023
@aryan-debug
Copy link
Author

@rustbot review

@rustbot rustbot 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 Jun 19, 2023
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-14 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
4 LL | type Foo = (impl Sized, u8);
-    | -------- `Foo` declared as private
+    | --------
+    | |
+    | `Foo` declared as private
+    | help: consider adding `pub` in front of it
6 LL | pub fn foo() -> Foo {
7    | ^^^^^^^^^^^^^^^^^^^ can't leak private type alias


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/type-alias-impl-trait/privacy/privacy.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/type-alias-impl-trait/privacy/privacy.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args type-alias-impl-trait/privacy.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/type-alias-impl-trait/privacy.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--remap-path-prefix=/checkout/tests/ui=fake-test-src-base" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/type-alias-impl-trait/privacy" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/type-alias-impl-trait/privacy/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0446]: private type alias `Foo` in public interface
  --> fake-test-src-base/type-alias-impl-trait/privacy.rs:4:1
LL | type Foo = (impl Sized, u8);
   | --------
   | |
   | |
   | `Foo` declared as private
   | help: consider adding `pub` in front of it
LL | pub fn foo() -> Foo {
   | ^^^^^^^^^^^^^^^^^^^ can't leak private type alias
error: aborting due to previous error

For more information about this error, try `rustc --explain E0446`.
------------------------------------------

@compiler-errors
Copy link
Member

Still needs tests blessed 😅

@rustbot author

@rustbot rustbot 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 Jul 10, 2023
@compiler-errors
Copy link
Member

No idea how to fix your error without trying it locally, @aryan-debug. Try rebasing your code onto the latest master and blessing your tests again?

@@ -73,6 +73,8 @@ pub struct InPublicInterface<'a> {
pub descr: DiagnosticArgFromDisplay<'a>,
#[label(privacy_visibility_label)]
pub vis_span: Span,
#[suggestion(code = "", applicability = "maybe-incorrect")]
Copy link
Member

Choose a reason for hiding this comment

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

This suggestion isn't actually modifying anything

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure what it should modify and how to do it

@@ -8,6 +8,7 @@ privacy_from_private_dep_in_public_interface =
privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interface
.label = can't leak {$vis_descr} {$kind}
.visibility_label = `{$descr}` declared as {$vis_descr}
.suggestion = consider adding `pub` in front of it
Copy link
Member

Choose a reason for hiding this comment

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

this wording is a bit awkward, perhaps "consider making the{$descr} public" or something.

i also don't know if this will unilaterally be applicable. have you tested combinations of items that are already pub(crate) but being exported in pub signatures, for example?

Copy link
Author

Choose a reason for hiding this comment

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

I agree with you so I changed the message to what you suggested.

Also, I am not sure what you mean by that example, sorry

@nyurik
Copy link
Contributor

nyurik commented Jul 23, 2023

I made a few modifications to this PR in #113983 (since I cannot alter the original one), namely addressing @compiler-errors point about suggesting different visibility modifiers in the help message.

@bors
Copy link
Contributor

bors commented Sep 1, 2023

☔ The latest upstream changes (presumably #113126) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnCSimon
Copy link
Member

@aryan-debug
ping from triage - can you post your status on this PR? There hasn't been an update in a few months. Thanks!

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@nyurik
Copy link
Contributor

nyurik commented Nov 12, 2023

@JohnCSimon this PR was updated/refactored a bit in #113983

@Dylan-DPC
Copy link
Member

Superseded by #113983

@Dylan-DPC Dylan-DPC closed this Feb 10, 2024
@Dylan-DPC Dylan-DPC removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Suggest code correction for E0446 - private type in public interface
9 participants