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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_privacy/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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


privacy_item_is_private = {$kind} `{$descr}` is private
.label = private {$kind}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_privacy/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

pub suggestion: Span,
}

#[derive(Diagnostic)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
kind,
descr: descr.into(),
vis_span,
suggestion: vis_span,
});
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>;
| ^^^^^^^^^^^^ can't leak private type
...
LL | const fn my_const_fn(val: u8) -> u8 {
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
| -----------------------------------
| |
| `fn(u8) -> u8 {my_const_fn}` declared as private
| help: consider adding `pub` in front of it

error: aborting due to previous error

Expand Down
5 changes: 4 additions & 1 deletion tests/ui/error-codes/E0446.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ error[E0446]: private type `Bar` in public interface
--> $DIR/E0446.rs:4:5
|
LL | struct Bar(u32);
| ---------- `Bar` declared as private
| ----------
| |
| `Bar` declared as private
| help: consider adding `pub` in front of it
LL |
LL | pub fn bar() -> Bar {
| ^^^^^^^^^^^^^^^^^^^ can't leak private type
Expand Down
10 changes: 8 additions & 2 deletions tests/ui/privacy/issue-30079.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ error[E0446]: private type `m2::Priv` in public interface
--> $DIR/issue-30079.rs:18:9
|
LL | struct Priv;
| ----------- `m2::Priv` declared as private
| -----------
| |
| `m2::Priv` declared as private
| help: consider adding `pub` in front of it
LL | impl ::std::ops::Deref for ::SemiPriv {
LL | type Target = Priv;
| ^^^^^^^^^^^ can't leak private type
Expand All @@ -21,7 +24,10 @@ error[E0446]: private type `m3::Priv` in public interface
--> $DIR/issue-30079.rs:35:9
|
LL | struct Priv;
| ----------- `m3::Priv` declared as private
| -----------
| |
| `m3::Priv` declared as private
| help: consider adding `pub` in front of it
LL | impl ::SemiPrivTrait for () {
LL | type Assoc = Priv;
| ^^^^^^^^^^ can't leak private type
Expand Down
15 changes: 12 additions & 3 deletions tests/ui/privacy/private-in-public-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:17:9
|
LL | struct Priv;
| ----------- `Priv` declared as private
| -----------
| |
| `Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type A = Priv;
| ^^^^^^ can't leak private type
Expand Down Expand Up @@ -39,7 +42,10 @@ error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:34:9
|
LL | struct Priv;
| ----------- `Priv` declared as private
| -----------
| |
| `Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Alias4 = Priv;
| ^^^^^^^^^^^ can't leak private type
Expand All @@ -48,7 +54,10 @@ error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:41:9
|
LL | struct Priv;
| ----------- `Priv` declared as private
| -----------
| |
| `Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Alias1 = Priv;
| ^^^^^^^^^^^ can't leak private type
Expand Down
10 changes: 8 additions & 2 deletions tests/ui/privacy/private-in-public-lint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ error[E0446]: private type `m1::Priv` in public interface
--> $DIR/private-in-public-lint.rs:6:9
|
LL | struct Priv;
| ----------- `m1::Priv` declared as private
| -----------
| |
| `m1::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | pub fn f() -> Priv {Priv}
| ^^^^^^^^^^^^^^^^^^ can't leak private type
Expand All @@ -11,7 +14,10 @@ error[E0446]: private type `m2::Priv` in public interface
--> $DIR/private-in-public-lint.rs:15:9
|
LL | struct Priv;
| ----------- `m2::Priv` declared as private
| -----------
| |
| `m2::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | pub fn f() -> Priv {Priv}
| ^^^^^^^^^^^^^^^^^^ can't leak private type
Expand Down
35 changes: 28 additions & 7 deletions tests/ui/privacy/private-in-public-warn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public-warn.rs:26:9
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
| -----------
| |
| `types::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type
Expand Down Expand Up @@ -97,7 +100,10 @@ error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public-warn.rs:41:9
|
LL | struct Priv;
| ----------- `types::Priv` declared as private
| -----------
| |
| `types::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type
Expand Down Expand Up @@ -232,7 +238,10 @@ error[E0446]: private type `impls::Priv` in public interface
--> $DIR/private-in-public-warn.rs:132:9
|
LL | struct Priv;
| ----------- `impls::Priv` declared as private
| -----------
| |
| `impls::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type
Expand All @@ -250,7 +259,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:207:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
| -----------
| |
| `aliases_pub::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
Expand All @@ -259,7 +271,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:210:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
| -----------
| |
| `aliases_pub::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
Expand All @@ -268,7 +283,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:213:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
| -----------
| |
| `aliases_pub::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
Expand All @@ -277,7 +295,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:216:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
| -----------
| |
| `aliases_pub::Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type
Expand Down
Loading