Skip to content

Commit a094043

Browse files
aryan-debugnyurik
authored andcommitted
Added suggestion instead of help
1 parent e7e1bfe commit a094043

16 files changed

+193
-51
lines changed

compiler/rustc_privacy/messages.ftl

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ privacy_from_private_dep_in_public_interface =
88
privacy_in_public_interface = {$vis_descr} {$kind} `{$descr}` in public interface
99
.label = can't leak {$vis_descr} {$kind}
1010
.visibility_label = `{$descr}` declared as {$vis_descr}
11-
.help = - Either remove the `pub` from the function
12-
- Or add `pub` to `{$descr}`
11+
.suggestion = consider adding `pub` in front of it
1312
1413
privacy_item_is_private = {$kind} `{$descr}` is private
1514
.label = private {$kind}

compiler/rustc_privacy/src/errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ pub struct InPublicInterfaceTraits<'a> {
6363

6464
// Duplicate of `InPublicInterfaceTraits` but with a different error code, shares the same slug.
6565
#[derive(Diagnostic)]
66-
#[help]
6766
#[diag(privacy_in_public_interface, code = "E0446")]
6867
pub struct InPublicInterface<'a> {
6968
#[primary_span]
@@ -74,6 +73,8 @@ pub struct InPublicInterface<'a> {
7473
pub descr: DiagnosticArgFromDisplay<'a>,
7574
#[label(privacy_visibility_label)]
7675
pub vis_span: Span,
76+
#[suggestion(code="", applicability = "maybe-incorrect")]
77+
pub suggestion: Span,
7778
}
7879

7980
#[derive(Diagnostic)]

compiler/rustc_privacy/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
16341634
}
16351635
if found_pub_static {
16361636
intravisit::walk_generics(self, &impl_.generics)
1637-
}
1637+
}
16381638
}
16391639
return;
16401640
}
@@ -1829,6 +1829,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
18291829
kind,
18301830
descr: descr.into(),
18311831
vis_span,
1832+
suggestion: vis_span,
18321833
});
18331834
}
18341835
} else {

tests/ui/const-generics/generic_const_exprs/eval-privacy.stderr

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>;
55
| ^^^^^^^^^^^^ can't leak private type
66
...
77
LL | const fn my_const_fn(val: u8) -> u8 {
8-
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
8+
| -----------------------------------
9+
| |
10+
| `fn(u8) -> u8 {my_const_fn}` declared as private
11+
| help: consider adding `pub` in front of it
912

1013
warning: type `fn(u8) -> u8 {my_const_fn}` is more private than the item `<Const<U> as Trait>::AssocTy`
1114
--> $DIR/eval-privacy.rs:22:5

tests/ui/error-codes/E0446.stderr

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error[E0446]: private type `Bar` in public interface
22
--> $DIR/E0446.rs:4:5
33
|
44
LL | struct Bar(u32);
5-
| ---------- `Bar` declared as private
5+
| ----------
6+
| |
7+
| `Bar` declared as private
8+
| help: consider adding `pub` in front of it
69
LL |
710
LL | pub fn bar() -> Bar {
811
| ^^^^^^^^^^^^^^^^^^^ can't leak private type

tests/ui/privacy/issue-30079.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ error[E0446]: private type `m2::Priv` in public interface
1212
--> $DIR/issue-30079.rs:18:9
1313
|
1414
LL | struct Priv;
15-
| ----------- `m2::Priv` declared as private
15+
| -----------
16+
| |
17+
| `m2::Priv` declared as private
18+
| help: consider adding `pub` in front of it
1619
LL | impl ::std::ops::Deref for ::SemiPriv {
1720
LL | type Target = Priv;
1821
| ^^^^^^^^^^^ can't leak private type
@@ -21,7 +24,10 @@ error[E0446]: private type `m3::Priv` in public interface
2124
--> $DIR/issue-30079.rs:35:9
2225
|
2326
LL | struct Priv;
24-
| ----------- `m3::Priv` declared as private
27+
| -----------
28+
| |
29+
| `m3::Priv` declared as private
30+
| help: consider adding `pub` in front of it
2531
LL | impl ::SemiPrivTrait for () {
2632
LL | type Assoc = Priv;
2733
| ^^^^^^^^^^ can't leak private type

tests/ui/privacy/private-in-public-assoc-ty.stderr

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error[E0446]: private type `Priv` in public interface
22
--> $DIR/private-in-public-assoc-ty.rs:17:9
33
|
44
LL | struct Priv;
5-
| ----------- `Priv` declared as private
5+
| -----------
6+
| |
7+
| `Priv` declared as private
8+
| help: consider adding `pub` in front of it
69
...
710
LL | type A = Priv;
811
| ^^^^^^ can't leak private type
@@ -39,7 +42,10 @@ error[E0446]: private type `Priv` in public interface
3942
--> $DIR/private-in-public-assoc-ty.rs:34:9
4043
|
4144
LL | struct Priv;
42-
| ----------- `Priv` declared as private
45+
| -----------
46+
| |
47+
| `Priv` declared as private
48+
| help: consider adding `pub` in front of it
4349
...
4450
LL | type Alias4 = Priv;
4551
| ^^^^^^^^^^^ can't leak private type
@@ -48,7 +54,10 @@ error[E0446]: private type `Priv` in public interface
4854
--> $DIR/private-in-public-assoc-ty.rs:41:9
4955
|
5056
LL | struct Priv;
51-
| ----------- `Priv` declared as private
57+
| -----------
58+
| |
59+
| `Priv` declared as private
60+
| help: consider adding `pub` in front of it
5261
...
5362
LL | type Alias1 = Priv;
5463
| ^^^^^^^^^^^ can't leak private type

tests/ui/privacy/private-in-public-lint.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error[E0446]: private type `m1::Priv` in public interface
22
--> $DIR/private-in-public-lint.rs:6:9
33
|
44
LL | struct Priv;
5-
| ----------- `m1::Priv` declared as private
5+
| -----------
6+
| |
7+
| `m1::Priv` declared as private
8+
| help: consider adding `pub` in front of it
69
...
710
LL | pub fn f() -> Priv {Priv}
811
| ^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -11,7 +14,10 @@ error[E0446]: private type `m2::Priv` in public interface
1114
--> $DIR/private-in-public-lint.rs:15:9
1215
|
1316
LL | struct Priv;
14-
| ----------- `m2::Priv` declared as private
17+
| -----------
18+
| |
19+
| `m2::Priv` declared as private
20+
| help: consider adding `pub` in front of it
1521
...
1622
LL | pub fn f() -> Priv {Priv}
1723
| ^^^^^^^^^^^^^^^^^^ can't leak private type

tests/ui/privacy/private-in-public-warn.stderr

+28-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ error[E0446]: private type `types::Priv` in public interface
4343
--> $DIR/private-in-public-warn.rs:26:9
4444
|
4545
LL | struct Priv;
46-
| ----------- `types::Priv` declared as private
46+
| -----------
47+
| |
48+
| `types::Priv` declared as private
49+
| help: consider adding `pub` in front of it
4750
...
4851
LL | type Alias = Priv;
4952
| ^^^^^^^^^^ can't leak private type
@@ -97,7 +100,10 @@ error[E0446]: private type `types::Priv` in public interface
97100
--> $DIR/private-in-public-warn.rs:41:9
98101
|
99102
LL | struct Priv;
100-
| ----------- `types::Priv` declared as private
103+
| -----------
104+
| |
105+
| `types::Priv` declared as private
106+
| help: consider adding `pub` in front of it
101107
...
102108
LL | type Alias = Priv;
103109
| ^^^^^^^^^^ can't leak private type
@@ -232,7 +238,10 @@ error[E0446]: private type `impls::Priv` in public interface
232238
--> $DIR/private-in-public-warn.rs:132:9
233239
|
234240
LL | struct Priv;
235-
| ----------- `impls::Priv` declared as private
241+
| -----------
242+
| |
243+
| `impls::Priv` declared as private
244+
| help: consider adding `pub` in front of it
236245
...
237246
LL | type Alias = Priv;
238247
| ^^^^^^^^^^ can't leak private type
@@ -250,7 +259,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
250259
--> $DIR/private-in-public-warn.rs:207:9
251260
|
252261
LL | struct Priv;
253-
| ----------- `aliases_pub::Priv` declared as private
262+
| -----------
263+
| |
264+
| `aliases_pub::Priv` declared as private
265+
| help: consider adding `pub` in front of it
254266
...
255267
LL | type Check = Priv;
256268
| ^^^^^^^^^^ can't leak private type
@@ -259,7 +271,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
259271
--> $DIR/private-in-public-warn.rs:210:9
260272
|
261273
LL | struct Priv;
262-
| ----------- `aliases_pub::Priv` declared as private
274+
| -----------
275+
| |
276+
| `aliases_pub::Priv` declared as private
277+
| help: consider adding `pub` in front of it
263278
...
264279
LL | type Check = Priv;
265280
| ^^^^^^^^^^ can't leak private type
@@ -268,7 +283,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
268283
--> $DIR/private-in-public-warn.rs:213:9
269284
|
270285
LL | struct Priv;
271-
| ----------- `aliases_pub::Priv` declared as private
286+
| -----------
287+
| |
288+
| `aliases_pub::Priv` declared as private
289+
| help: consider adding `pub` in front of it
272290
...
273291
LL | type Check = Priv;
274292
| ^^^^^^^^^^ can't leak private type
@@ -277,7 +295,10 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
277295
--> $DIR/private-in-public-warn.rs:216:9
278296
|
279297
LL | struct Priv;
280-
| ----------- `aliases_pub::Priv` declared as private
298+
| -----------
299+
| |
300+
| `aliases_pub::Priv` declared as private
301+
| help: consider adding `pub` in front of it
281302
...
282303
LL | type Check = Priv;
283304
| ^^^^^^^^^^ can't leak private type

0 commit comments

Comments
 (0)