File tree 7 files changed +39
-7
lines changed 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 =
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 InPublicInterface<'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 : DiagArgFromDisplay < ' a > ,
60
61
#[ label( privacy_visibility_label) ]
61
62
pub vis_span : Span ,
Original file line number Diff line number Diff line change @@ -1337,12 +1337,31 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
1337
1337
}
1338
1338
} ;
1339
1339
1340
+ // FIXME: this code was adapted from the above `vis_descr` computation,
1341
+ // but it's not clear if it's correct.
1342
+ let vis_sugg = match self . required_visibility {
1343
+ ty:: Visibility :: Public => "pub" ,
1344
+ ty:: Visibility :: Restricted ( vis_def_id) => {
1345
+ if vis_def_id
1346
+ == self . tcx . parent_module_from_def_id ( local_def_id) . to_local_def_id ( )
1347
+ {
1348
+ "???FIXME???"
1349
+ } else if vis_def_id. is_top_level_module ( ) {
1350
+ "pub(crate)"
1351
+ } else {
1352
+ "???FIXME???"
1353
+ }
1354
+ }
1355
+ } ;
1356
+
1340
1357
self . tcx . dcx ( ) . emit_err ( InPublicInterface {
1341
1358
span,
1342
1359
vis_descr,
1343
1360
kind,
1361
+ vis_sugg,
1344
1362
descr : descr. into ( ) ,
1345
1363
vis_span,
1364
+ suggestion : vis_span,
1346
1365
} ) ;
1347
1366
return false ;
1348
1367
}
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ error[E0446]: private type `Bar` in public interface
2
2
--> $DIR/E0446.rs:10:5
3
3
|
4
4
LL | struct Bar;
5
- | ---------- `Bar` declared as private
5
+ | ----------
6
+ | |
7
+ | `Bar` declared as private
8
+ | help: consider adding `pub` in front of it
6
9
...
7
10
LL | type Alias1 = Bar;
8
11
| ^^^^^^^^^^^ can't leak private type
@@ -11,7 +14,10 @@ error[E0446]: private trait `PrivTr` in public interface
11
14
--> $DIR/E0446.rs:11:5
12
15
|
13
16
LL | trait PrivTr {}
14
- | ------------ `PrivTr` declared as private
17
+ | ------------
18
+ | |
19
+ | `PrivTr` declared as private
20
+ | help: consider adding `pub` in front of it
15
21
...
16
22
LL | type Alias2 = Box<dyn PrivTr>;
17
23
| ^^^^^^^^^^^ can't leak private trait
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ LL | struct Priv;
18
18
| -----------
19
19
| |
20
20
| `m2::Priv` declared as private
21
- | help: consider adding `pub` in front of it
21
+ | help: consider adding `pub(crate) ` in front of it
22
22
LL | impl ::std::ops::Deref for ::SemiPriv {
23
23
LL | type Target = Priv;
24
24
| ^^^^^^^^^^^ can't leak private type
@@ -30,7 +30,7 @@ LL | struct Priv;
30
30
| -----------
31
31
| |
32
32
| `m3::Priv` declared as private
33
- | help: consider adding `pub` in front of it
33
+ | help: consider adding `pub(crate) ` in front of it
34
34
LL | impl ::SemiPrivTrait for () {
35
35
LL | type Assoc = Priv;
36
36
| ^^^^^^^^^^ 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
75
75
--> $DIR/private-in-public-assoc-ty.rs:41:9
76
76
|
77
77
LL | trait PrivTr {}
78
- | ------------ `PrivTr` declared as private
78
+ | ------------
79
+ | |
80
+ | `PrivTr` declared as private
81
+ | help: consider adding `pub` in front of it
79
82
...
80
83
LL | type Exist = impl PrivTr;
81
84
| ^^^^^^^^^^ 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) }>;
75
75
| ^^^^^^^^^^^^ can't leak private type
76
76
...
77
77
LL | 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
79
82
80
83
error: aborting due to 1 previous error; 5 warnings emitted
81
84
You can’t perform that action at this time.
0 commit comments