File tree Expand file tree Collapse file tree 7 files changed +39
-7
lines changed Expand file tree Collapse file tree 7 files changed +39
-7
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ privacy_from_private_dep_in_public_interface =
88privacy_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- .suggestion = consider adding `pub ` in front of it
11+ .suggestion = consider adding `{ $vis_sugg } ` in front of it
1212
1313privacy_item_is_private = { $kind } `{ $descr } ` is private
1414 .label = private { $kind }
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ pub struct InPublicInterface<'a> {
5555 pub span : Span ,
5656 pub vis_descr : & ' static str ,
5757 pub kind : & ' a str ,
58+ pub vis_sugg : & ' static str ,
5859 pub descr : DiagnosticArgFromDisplay < ' a > ,
5960 #[ label( privacy_visibility_label) ]
6061 pub vis_span : Span ,
Original file line number Diff line number Diff line change @@ -1475,12 +1475,31 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
14751475 }
14761476 } ;
14771477
1478+ // FIXME: this code was adapted from the above `vis_descr` computation,
1479+ // but it's not clear if it's correct.
1480+ let vis_sugg = match self . required_visibility {
1481+ ty:: Visibility :: Public => "pub" ,
1482+ ty:: Visibility :: Restricted ( vis_def_id) => {
1483+ if vis_def_id
1484+ == self . tcx . parent_module_from_def_id ( local_def_id) . to_local_def_id ( )
1485+ {
1486+ "???FIXME???"
1487+ } else if vis_def_id. is_top_level_module ( ) {
1488+ "pub(crate)"
1489+ } else {
1490+ "???FIXME???"
1491+ }
1492+ }
1493+ } ;
1494+
14781495 self . tcx . sess . emit_err ( InPublicInterface {
14791496 span,
14801497 vis_descr,
14811498 kind,
1499+ vis_sugg,
14821500 descr : descr. into ( ) ,
14831501 vis_span,
1502+ suggestion : vis_span,
14841503 } ) ;
14851504 return false ;
14861505 }
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ error[E0446]: private type `Bar` in public interface
22 --> $DIR/E0446.rs:10:5
33 |
44LL | struct Bar;
5- | ---------- `Bar` declared as private
5+ | ----------
6+ | |
7+ | `Bar` declared as private
8+ | help: consider adding `pub` in front of it
69...
710LL | type Alias1 = Bar;
811 | ^^^^^^^^^^^ can't leak private type
@@ -11,7 +14,10 @@ error[E0446]: private trait `PrivTr` in public interface
1114 --> $DIR/E0446.rs:11:5
1215 |
1316LL | trait PrivTr {}
14- | ------------ `PrivTr` declared as private
17+ | ------------
18+ | |
19+ | `PrivTr` declared as private
20+ | help: consider adding `pub` in front of it
1521...
1622LL | type Alias2 = Box<dyn PrivTr>;
1723 | ^^^^^^^^^^^ can't leak private trait
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ LL | struct Priv;
1818 | -----------
1919 | |
2020 | `m2::Priv` declared as private
21- | help: consider adding `pub` in front of it
21+ | help: consider adding `pub(crate) ` in front of it
2222LL | impl ::std::ops::Deref for ::SemiPriv {
2323LL | type Target = Priv;
2424 | ^^^^^^^^^^^ can't leak private type
@@ -30,7 +30,7 @@ LL | struct Priv;
3030 | -----------
3131 | |
3232 | `m3::Priv` declared as private
33- | help: consider adding `pub` in front of it
33+ | help: consider adding `pub(crate) ` in front of it
3434LL | impl ::SemiPrivTrait for () {
3535LL | type Assoc = Priv;
3636 | ^^^^^^^^^^ can't leak private type
Original file line number Diff line number Diff line change @@ -75,7 +75,10 @@ error[E0446]: private trait `PrivTr` in public interface
7575 --> $DIR/private-in-public-assoc-ty.rs:41:9
7676 |
7777LL | trait PrivTr {}
78- | ------------ `PrivTr` declared as private
78+ | ------------
79+ | |
80+ | `PrivTr` declared as private
81+ | help: consider adding `pub` in front of it
7982...
8083LL | type Exist = impl PrivTr;
8184 | ^^^^^^^^^^ can't leak private trait
Original file line number Diff line number Diff line change @@ -75,7 +75,10 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>;
7575 | ^^^^^^^^^^^^ can't leak private type
7676...
7777LL | const fn my_const_fn(val: u8) -> u8 {
78- | ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
78+ | -----------------------------------
79+ | |
80+ | `fn(u8) -> u8 {my_const_fn}` declared as private
81+ | help: consider adding `pub` in front of it
7982
8083error: aborting due to previous error; 5 warnings emitted
8184
You can’t perform that action at this time.
0 commit comments