Skip to content

Commit 8ca5759

Browse files
committed
wip
1 parent c337e68 commit 8ca5759

File tree

9 files changed

+119
-81
lines changed

9 files changed

+119
-81
lines changed

compiler/rustc_privacy/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ pub struct InPublicInterface<'a> {
5656
pub span: Span,
5757
pub vis_descr: &'static str,
5858
pub kind: &'a str,
59-
pub vis_sugg: &'static str,
6059
pub descr: DiagArgFromDisplay<'a>,
6160
#[label(privacy_visibility_label)]
6261
pub vis_span: Span,
63-
#[suggestion(code = "", applicability = "maybe-incorrect")]
64-
pub suggestion: Span,
62+
#[suggestion(code = "{vis_sugg}", applicability = "maybe-incorrect", style = "verbose")]
63+
pub data: Span,
64+
pub vis_sugg: &'static str,
6565
}
6666

6767
#[derive(Diagnostic)]

compiler/rustc_privacy/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1358,10 +1358,10 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
13581358
span,
13591359
vis_descr,
13601360
kind,
1361-
vis_sugg,
13621361
descr: descr.into(),
13631362
vis_span,
1364-
suggestion: vis_span,
1363+
data: vis_span,
1364+
vis_sugg,
13651365
});
13661366
return false;
13671367
}

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ 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-
| -----------------------------------
9-
| |
10-
| `fn(u8) -> u8 {my_const_fn}` declared as private
11-
| help: consider adding `pub` in front of it
8+
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
9+
|
10+
help: consider adding `pub` in front of it
11+
|
12+
LL | pub {
13+
| ~~~
1214

1315
error: aborting due to 1 previous error
1416

tests/ui/error-codes/E0446.stderr

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@ error[E0446]: private type `Bar` in public interface
22
--> $DIR/E0446.rs:10:5
33
|
44
LL | struct Bar;
5-
| ----------
6-
| |
7-
| `Bar` declared as private
8-
| help: consider adding `pub` in front of it
5+
| ---------- `Bar` declared as private
96
...
107
LL | type Alias1 = Bar;
118
| ^^^^^^^^^^^ can't leak private type
9+
|
10+
help: consider adding `pub` in front of it
11+
|
12+
LL | pub;
13+
| ~~~
1214

1315
error[E0446]: private trait `PrivTr` in public interface
1416
--> $DIR/E0446.rs:11:5
1517
|
1618
LL | trait PrivTr {}
17-
| ------------
18-
| |
19-
| `PrivTr` declared as private
20-
| help: consider adding `pub` in front of it
19+
| ------------ `PrivTr` declared as private
2120
...
2221
LL | type Alias2 = Box<dyn PrivTr>;
2322
| ^^^^^^^^^^^ can't leak private trait
23+
|
24+
help: consider adding `pub` in front of it
25+
|
26+
LL | pub {}
27+
| ~~~
2428

2529
error: aborting due to 2 previous errors
2630

tests/ui/privacy/issue-30079.stderr

+12-8
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,29 @@ error[E0446]: private type `m2::Priv` in public interface
1515
--> $DIR/issue-30079.rs:17:9
1616
|
1717
LL | struct Priv;
18-
| -----------
19-
| |
20-
| `m2::Priv` declared as private
21-
| help: consider adding `pub(crate)` in front of it
18+
| ----------- `m2::Priv` declared as private
2219
LL | impl ::std::ops::Deref for ::SemiPriv {
2320
LL | type Target = Priv;
2421
| ^^^^^^^^^^^ can't leak private type
22+
|
23+
help: consider adding `pub(crate)` in front of it
24+
|
25+
LL | pub(crate);
26+
| ~~~~~~~~~~
2527

2628
error[E0446]: private type `m3::Priv` in public interface
2729
--> $DIR/issue-30079.rs:34:9
2830
|
2931
LL | struct Priv;
30-
| -----------
31-
| |
32-
| `m3::Priv` declared as private
33-
| help: consider adding `pub(crate)` in front of it
32+
| ----------- `m3::Priv` declared as private
3433
LL | impl ::SemiPrivTrait for () {
3534
LL | type Assoc = Priv;
3635
| ^^^^^^^^^^ can't leak private type
36+
|
37+
help: consider adding `pub(crate)` in front of it
38+
|
39+
LL | pub(crate);
40+
| ~~~~~~~~~~
3741

3842
error: aborting due to 2 previous errors; 1 warning emitted
3943

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

+24-16
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ error[E0446]: private type `Priv` in public interface
22
--> $DIR/private-in-public-assoc-ty.rs:17:9
33
|
44
LL | struct Priv;
5-
| -----------
6-
| |
7-
| `Priv` declared as private
8-
| help: consider adding `pub` in front of it
5+
| ----------- `Priv` declared as private
96
...
107
LL | type A = Priv;
118
| ^^^^^^ can't leak private type
9+
|
10+
help: consider adding `pub` in front of it
11+
|
12+
LL | pub;
13+
| ~~~
1214

1315
warning: trait `PrivTr` is more private than the item `PubTr::Alias1`
1416
--> $DIR/private-in-public-assoc-ty.rs:24:9
@@ -51,37 +53,43 @@ error[E0446]: private type `Priv` in public interface
5153
--> $DIR/private-in-public-assoc-ty.rs:31:9
5254
|
5355
LL | struct Priv;
54-
| -----------
55-
| |
56-
| `Priv` declared as private
57-
| help: consider adding `pub` in front of it
56+
| ----------- `Priv` declared as private
5857
...
5958
LL | type Alias4 = Priv;
6059
| ^^^^^^^^^^^ can't leak private type
60+
|
61+
help: consider adding `pub` in front of it
62+
|
63+
LL | pub;
64+
| ~~~
6165

6266
error[E0446]: private type `Priv` in public interface
6367
--> $DIR/private-in-public-assoc-ty.rs:38:9
6468
|
6569
LL | struct Priv;
66-
| -----------
67-
| |
68-
| `Priv` declared as private
69-
| help: consider adding `pub` in front of it
70+
| ----------- `Priv` declared as private
7071
...
7172
LL | type Alias1 = Priv;
7273
| ^^^^^^^^^^^ can't leak private type
74+
|
75+
help: consider adding `pub` in front of it
76+
|
77+
LL | pub;
78+
| ~~~
7379

7480
error[E0446]: private trait `PrivTr` in public interface
7581
--> $DIR/private-in-public-assoc-ty.rs:41:9
7682
|
7783
LL | trait PrivTr {}
78-
| ------------
79-
| |
80-
| `PrivTr` declared as private
81-
| help: consider adding `pub` in front of it
84+
| ------------ `PrivTr` declared as private
8285
...
8386
LL | type Exist = impl PrivTr;
8487
| ^^^^^^^^^^ can't leak private trait
88+
|
89+
help: consider adding `pub` in front of it
90+
|
91+
LL | pub {}
92+
| ~~~
8593

8694
error: aborting due to 4 previous errors; 3 warnings emitted
8795

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

+42-28
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ error[E0446]: private type `types::Priv` in public interface
5555
--> $DIR/private-in-public-warn.rs:22:9
5656
|
5757
LL | struct Priv;
58-
| -----------
59-
| |
60-
| `types::Priv` declared as private
61-
| help: consider adding `pub` in front of it
58+
| ----------- `types::Priv` declared as private
6259
...
6360
LL | type Alias = Priv;
6461
| ^^^^^^^^^^ can't leak private type
62+
|
63+
help: consider adding `pub` in front of it
64+
|
65+
LL | pub;
66+
| ~~~
6567

6668
error: type `types::Priv` is more private than the item `Tr::f1`
6769
--> $DIR/private-in-public-warn.rs:23:9
@@ -127,13 +129,15 @@ error[E0446]: private type `types::Priv` in public interface
127129
--> $DIR/private-in-public-warn.rs:32:9
128130
|
129131
LL | struct Priv;
130-
| -----------
131-
| |
132-
| `types::Priv` declared as private
133-
| help: consider adding `pub` in front of it
132+
| ----------- `types::Priv` declared as private
134133
...
135134
LL | type Alias = Priv;
136135
| ^^^^^^^^^^ can't leak private type
136+
|
137+
help: consider adding `pub` in front of it
138+
|
139+
LL | pub;
140+
| ~~~
137141

138142
error: trait `traits::PrivTr` is more private than the item `traits::Alias`
139143
--> $DIR/private-in-public-warn.rs:41:5
@@ -312,13 +316,15 @@ error[E0446]: private type `impls::Priv` in public interface
312316
--> $DIR/private-in-public-warn.rs:109:9
313317
|
314318
LL | struct Priv;
315-
| -----------
316-
| |
317-
| `impls::Priv` declared as private
318-
| help: consider adding `pub` in front of it
319+
| ----------- `impls::Priv` declared as private
319320
...
320321
LL | type Alias = Priv;
321322
| ^^^^^^^^^^ can't leak private type
323+
|
324+
help: consider adding `pub` in front of it
325+
|
326+
LL | pub;
327+
| ~~~
322328

323329
error: type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f`
324330
--> $DIR/private-in-public-warn.rs:180:9
@@ -336,49 +342,57 @@ error[E0446]: private type `aliases_pub::Priv` in public interface
336342
--> $DIR/private-in-public-warn.rs:183:9
337343
|
338344
LL | struct Priv;
339-
| -----------
340-
| |
341-
| `aliases_pub::Priv` declared as private
342-
| help: consider adding `pub` in front of it
345+
| ----------- `aliases_pub::Priv` declared as private
343346
...
344347
LL | type Check = Priv;
345348
| ^^^^^^^^^^ can't leak private type
349+
|
350+
help: consider adding `pub` in front of it
351+
|
352+
LL | pub;
353+
| ~~~
346354

347355
error[E0446]: private type `aliases_pub::Priv` in public interface
348356
--> $DIR/private-in-public-warn.rs:186:9
349357
|
350358
LL | struct Priv;
351-
| -----------
352-
| |
353-
| `aliases_pub::Priv` declared as private
354-
| help: consider adding `pub` in front of it
359+
| ----------- `aliases_pub::Priv` declared as private
355360
...
356361
LL | type Check = Priv;
357362
| ^^^^^^^^^^ can't leak private type
363+
|
364+
help: consider adding `pub` in front of it
365+
|
366+
LL | pub;
367+
| ~~~
358368

359369
error[E0446]: private type `aliases_pub::Priv` in public interface
360370
--> $DIR/private-in-public-warn.rs:189:9
361371
|
362372
LL | struct Priv;
363-
| -----------
364-
| |
365-
| `aliases_pub::Priv` declared as private
366-
| help: consider adding `pub` in front of it
373+
| ----------- `aliases_pub::Priv` declared as private
367374
...
368375
LL | type Check = Priv;
369376
| ^^^^^^^^^^ can't leak private type
377+
|
378+
help: consider adding `pub` in front of it
379+
|
380+
LL | pub;
381+
| ~~~
370382

371383
error[E0446]: private type `aliases_pub::Priv` in public interface
372384
--> $DIR/private-in-public-warn.rs:192:9
373385
|
374386
LL | struct Priv;
375-
| -----------
376-
| |
377-
| `aliases_pub::Priv` declared as private
378-
| help: consider adding `pub` in front of it
387+
| ----------- `aliases_pub::Priv` declared as private
379388
...
380389
LL | type Check = Priv;
381390
| ^^^^^^^^^^ can't leak private type
391+
|
392+
help: consider adding `pub` in front of it
393+
|
394+
LL | pub;
395+
| ~~~
382396

383397
error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1`
384398
--> $DIR/private-in-public-warn.rs:222:5

tests/ui/privacy/private-inferred-type.stderr

+12-8
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@ error[E0446]: private type `Priv` in public interface
22
--> $DIR/private-inferred-type.rs:61:36
33
|
44
LL | struct Priv;
5-
| -----------
6-
| |
7-
| `Priv` declared as private
8-
| help: consider adding `pub` in front of it
5+
| ----------- `Priv` declared as private
96
...
107
LL | impl TraitWithAssocTy for u8 { type AssocTy = Priv; }
118
| ^^^^^^^^^^^^ can't leak private type
9+
|
10+
help: consider adding `pub` in front of it
11+
|
12+
LL | pub;
13+
| ~~~
1214

1315
error[E0446]: private type `S2` in public interface
1416
--> $DIR/private-inferred-type.rs:83:9
1517
|
1618
LL | struct S2;
17-
| ---------
18-
| |
19-
| `S2` declared as private
20-
| help: consider adding `pub` in front of it
19+
| --------- `S2` declared as private
2120
...
2221
LL | type Target = S2Alias;
2322
| ^^^^^^^^^^^ can't leak private type
23+
|
24+
help: consider adding `pub` in front of it
25+
|
26+
LL | pub;
27+
| ~~~
2428

2529
error: type `Priv` is private
2630
--> $DIR/private-inferred-type.rs:97:9

tests/ui/privacy/where-priv-type.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ LL | type AssocTy = Const<{ my_const_fn(U) }>;
7575
| ^^^^^^^^^^^^ can't leak private type
7676
...
7777
LL | const fn my_const_fn(val: u8) -> u8 {
78-
| -----------------------------------
79-
| |
80-
| `fn(u8) -> u8 {my_const_fn}` declared as private
81-
| help: consider adding `pub` in front of it
78+
| ----------------------------------- `fn(u8) -> u8 {my_const_fn}` declared as private
79+
|
80+
help: consider adding `pub` in front of it
81+
|
82+
LL | pub {
83+
| ~~~
8284

8385
error: aborting due to 1 previous error; 5 warnings emitted
8486

0 commit comments

Comments
 (0)