File tree 8 files changed +30
-8
lines changed
transmutability/visibility
8 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ privacy_from_private_dep_in_public_interface =
8
8
privacy_in_public_interface = { $vis_descr } { $kind } `{ $descr } ` in public interface
9
9
.label = can't leak { $vis_descr } { $kind }
10
10
.visibility_label = `{ $descr } ` declared as { $vis_descr }
11
- .suggestion = consider adding `pub ` in front of it
11
+ .suggestion = consider adding `{ $vis_sugg } ` in front of it
12
12
13
13
privacy_item_is_private = { $kind } `{ $descr } ` is private
14
14
.label = private { $kind }
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ pub struct InPublicInterfaceTraits<'a> {
56
56
pub span : Span ,
57
57
pub vis_descr : & ' static str ,
58
58
pub kind : & ' a str ,
59
+ pub vis_sugg : & ' static str ,
59
60
pub descr : DiagnosticArgFromDisplay < ' a > ,
60
61
#[ label( privacy_visibility_label) ]
61
62
pub vis_span : Span ,
@@ -70,6 +71,7 @@ pub struct InPublicInterface<'a> {
70
71
pub span : Span ,
71
72
pub vis_descr : & ' static str ,
72
73
pub kind : & ' a str ,
74
+ pub vis_sugg : & ' static str ,
73
75
pub descr : DiagnosticArgFromDisplay < ' a > ,
74
76
#[ label( privacy_visibility_label) ]
75
77
pub vis_span : Span ,
Original file line number Diff line number Diff line change @@ -1814,11 +1814,27 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1814
1814
|| self . in_assoc_ty
1815
1815
|| self . tcx . resolutions ( ( ) ) . has_pub_restricted
1816
1816
{
1817
+ // FIXME: this code was adapted from the above `vis_descr` computation,
1818
+ // but it's not clear if it's correct.
1819
+ let vis_sugg = match self . required_visibility {
1820
+ ty:: Visibility :: Public => "pub" ,
1821
+ ty:: Visibility :: Restricted ( vis_def_id) => {
1822
+ if vis_def_id == self . tcx . parent_module ( hir_id) {
1823
+ "???FIXME???"
1824
+ } else if vis_def_id. is_top_level_module ( ) {
1825
+ "pub(crate)"
1826
+ } else {
1827
+ "???FIXME???"
1828
+ }
1829
+ }
1830
+ } ;
1831
+
1817
1832
if kind == "trait" {
1818
1833
self . tcx . sess . emit_err ( InPublicInterfaceTraits {
1819
1834
span,
1820
1835
vis_descr,
1821
1836
kind,
1837
+ vis_sugg,
1822
1838
descr : descr. into ( ) ,
1823
1839
vis_span,
1824
1840
} ) ;
@@ -1827,6 +1843,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1827
1843
span,
1828
1844
vis_descr,
1829
1845
kind,
1846
+ vis_sugg,
1830
1847
descr : descr. into ( ) ,
1831
1848
vis_span,
1832
1849
suggestion : vis_span,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ LL | struct Priv;
15
15
| -----------
16
16
| |
17
17
| `m2::Priv` declared as private
18
- | help: consider adding `pub` in front of it
18
+ | help: consider adding `pub(crate) ` in front of it
19
19
LL | impl ::std::ops::Deref for ::SemiPriv {
20
20
LL | type Target = Priv;
21
21
| ^^^^^^^^^^^ can't leak private type
@@ -27,7 +27,7 @@ LL | struct Priv;
27
27
| -----------
28
28
| |
29
29
| `m3::Priv` declared as private
30
- | help: consider adding `pub` in front of it
30
+ | help: consider adding `pub(crate) ` in front of it
31
31
LL | impl ::SemiPrivTrait for () {
32
32
LL | type Assoc = Priv;
33
33
| ^^^^^^^^^^ can't leak private type
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ LL | struct Priv;
5
5
| -----------
6
6
| |
7
7
| `Priv` declared as private
8
- | help: consider adding `pub` in front of it
8
+ | help: consider adding `pub(crate) ` in front of it
9
9
...
10
10
LL | pub(crate) fn g(_: Priv) {}
11
11
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
@@ -17,7 +17,7 @@ LL | struct Priv;
17
17
| -----------
18
18
| |
19
19
| `Priv` declared as private
20
- | help: consider adding `pub` in front of it
20
+ | help: consider adding `pub(crate) ` in front of it
21
21
...
22
22
LL | pub(crate) fn h(_: Priv) {}
23
23
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type
5
5
| --------------------
6
6
| |
7
7
| `dst::Zst` declared as private
8
- | help: consider adding `pub` in front of it
8
+ | help: consider adding `pub(crate) ` in front of it
9
9
...
10
10
LL | pub(in super) field: Zst,
11
11
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ LL | #[repr(C)] pub(self) struct Zst; // <- unreachable type
5
5
| --------------------
6
6
| |
7
7
| `src::Zst` declared as private
8
- | help: consider adding `pub` in front of it
8
+ | help: consider adding `pub(crate) ` in front of it
9
9
...
10
10
LL | pub(in super) field: Zst,
11
11
| ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ error[E0446]: private type alias `Foo` in public interface
2
2
--> $DIR/privacy.rs:4:1
3
3
|
4
4
LL | type Foo = (impl Sized, u8);
5
- | -------- `Foo` declared as private
5
+ | --------
6
+ | |
7
+ | `Foo` declared as private
8
+ | help: consider adding `pub` in front of it
6
9
LL | pub fn foo() -> Foo {
7
10
| ^^^^^^^^^^^^^^^^^^^ can't leak private type alias
8
11
You can’t perform that action at this time.
0 commit comments