Skip to content

Commit

Permalink
Added suggestion instead of help
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan-debug authored and nyurik committed Nov 2, 2023
1 parent 3a7f798 commit 81bfab7
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 18 deletions.
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
3 changes: 2 additions & 1 deletion compiler/rustc_privacy/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub struct UnnamedItemIsPrivate {
}

#[derive(Diagnostic)]
#[help]
#[diag(privacy_in_public_interface, code = "E0446")]
pub struct InPublicInterface<'a> {
#[primary_span]
Expand All @@ -59,6 +58,8 @@ pub struct InPublicInterface<'a> {
pub descr: DiagnosticArgFromDisplay<'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 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

0 comments on commit 81bfab7

Please sign in to comment.