Skip to content

Add a visibility suggestion in private-in-public errors #113983

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added suggestion instead of help
  • Loading branch information
aryan-debug authored and nyurik committed May 2, 2024
commit 89085967938feaddc3346958b17a950bd02a6b45
3 changes: 1 addition & 2 deletions compiler/rustc_privacy/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +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}
.help = - Either remove the `pub` from the function
- Or add `pub` to `{$descr}`
.suggestion = consider adding `pub` in front of it

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 @@ -59,6 +59,8 @@ pub struct InPublicInterface<'a> {
pub descr: DiagArgFromDisplay<'a>,
#[label(privacy_visibility_label)]
pub vis_span: Span,
#[suggestion(code="", applicability = "maybe-incorrect")]
pub suggestion: Span,
}

#[derive(Diagnostic)]
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 1 previous error

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 @@ -15,7 +15,10 @@ error[E0446]: private type `m2::Priv` in public interface
--> $DIR/issue-30079.rs:17: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 @@ -24,7 +27,10 @@ error[E0446]: private type `m3::Priv` in public interface
--> $DIR/issue-30079.rs:34: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 @@ -48,7 +51,10 @@ error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:31: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 @@ -57,7 +63,10 @@ error[E0446]: private type `Priv` in public interface
--> $DIR/private-in-public-assoc-ty.rs:38: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
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 @@ -55,7 +55,10 @@ error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public-warn.rs:22: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 @@ -124,7 +127,10 @@ error[E0446]: private type `types::Priv` in public interface
--> $DIR/private-in-public-warn.rs:32: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 @@ -306,7 +312,10 @@ error[E0446]: private type `impls::Priv` in public interface
--> $DIR/private-in-public-warn.rs:109: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 @@ -327,7 +336,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:183: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 @@ -336,7 +348,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:186: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 @@ -345,7 +360,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:189: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 @@ -354,7 +372,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:192: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
10 changes: 8 additions & 2 deletions tests/ui/privacy/private-inferred-type.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-inferred-type.rs:61:36
|
LL | struct Priv;
| ----------- `Priv` declared as private
| -----------
| |
| `Priv` declared as private
| help: consider adding `pub` in front of it
...
LL | impl TraitWithAssocTy for u8 { type AssocTy = Priv; }
| ^^^^^^^^^^^^ can't leak private type
Expand All @@ -11,7 +14,10 @@ error[E0446]: private type `S2` in public interface
--> $DIR/private-inferred-type.rs:83:9
|
LL | struct S2;
| --------- `S2` declared as private
| ---------
| |
| `S2` declared as private
| help: consider adding `pub` in front of it
...
LL | type Target = S2Alias;
| ^^^^^^^^^^^ can't leak private type
Expand Down