Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a1f5a6d

Browse files
committed
Perform check_private_in_public by module.
1 parent a2320b2 commit a1f5a6d

File tree

5 files changed

+59
-54
lines changed

5 files changed

+59
-54
lines changed

‎compiler/rustc_interface/src/passes.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,9 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
11471147

11481148
parallel!(
11491149
{
1150-
tcx.ensure_ok().check_private_in_public(());
1150+
tcx.par_hir_for_each_module(|module| {
1151+
tcx.ensure_ok().check_private_in_public(module)
1152+
})
11511153
},
11521154
{
11531155
tcx.par_hir_for_each_module(|module| {

‎compiler/rustc_middle/src/query/mod.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,8 +1390,11 @@ rustc_queries! {
13901390
eval_always
13911391
desc { "checking effective visibilities" }
13921392
}
1393-
query check_private_in_public(_: ()) {
1394-
desc { "checking for private elements in public interfaces" }
1393+
query check_private_in_public(module_def_id: LocalModDefId) {
1394+
desc { |tcx|
1395+
"checking for private elements in public interfaces for {}",
1396+
describe_as_module(module_def_id, tcx)
1397+
}
13951398
}
13961399

13971400
query reachable_set(_: ()) -> &'tcx LocalDefIdSet {

‎compiler/rustc_privacy/src/lib.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,12 +1854,12 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
18541854
tcx.arena.alloc(visitor.effective_visibilities)
18551855
}
18561856

1857-
fn check_private_in_public(tcx: TyCtxt<'_>, ():()) {
1857+
fn check_private_in_public(tcx: TyCtxt<'_>, module_def_id:LocalModDefId) {
18581858
let effective_visibilities = tcx.effective_visibilities(());
18591859
// Check for private types in public interfaces.
18601860
let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities };
18611861

1862-
let crate_items = tcx.hir_crate_items(());
1862+
let crate_items = tcx.hir_module_items(module_def_id);
18631863
for id in crate_items.free_items() {
18641864
checker.check_item(id);
18651865
}

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

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,42 @@ LL | struct Priv;
9393
LL | type Alias = Priv;
9494
| ^^^^^^^^^^ can't leak private type
9595

96+
error: type `types::Priv` is more private than the item `types::ES`
97+
--> $DIR/private-in-public-warn.rs:27:9
98+
|
99+
LL | pub static ES: Priv;
100+
| ^^^^^^^^^^^^^^^^^^^ static `types::ES` is reachable at visibility `pub(crate)`
101+
|
102+
note: but type `types::Priv` is only usable at visibility `pub(self)`
103+
--> $DIR/private-in-public-warn.rs:9:5
104+
|
105+
LL | struct Priv;
106+
| ^^^^^^^^^^^
107+
108+
error: type `types::Priv` is more private than the item `types::ef1`
109+
--> $DIR/private-in-public-warn.rs:28:9
110+
|
111+
LL | pub fn ef1(arg: Priv);
112+
| ^^^^^^^^^^^^^^^^^^^^^^ function `types::ef1` is reachable at visibility `pub(crate)`
113+
|
114+
note: but type `types::Priv` is only usable at visibility `pub(self)`
115+
--> $DIR/private-in-public-warn.rs:9:5
116+
|
117+
LL | struct Priv;
118+
| ^^^^^^^^^^^
119+
120+
error: type `types::Priv` is more private than the item `types::ef2`
121+
--> $DIR/private-in-public-warn.rs:29:9
122+
|
123+
LL | pub fn ef2() -> Priv;
124+
| ^^^^^^^^^^^^^^^^^^^^^ function `types::ef2` is reachable at visibility `pub(crate)`
125+
|
126+
note: but type `types::Priv` is only usable at visibility `pub(self)`
127+
--> $DIR/private-in-public-warn.rs:9:5
128+
|
129+
LL | struct Priv;
130+
| ^^^^^^^^^^^
131+
96132
error: trait `traits::PrivTr` is more private than the item `traits::Alias`
97133
--> $DIR/private-in-public-warn.rs:42:5
98134
|
@@ -359,42 +395,6 @@ note: but type `Priv2` is only usable at visibility `pub(self)`
359395
LL | struct Priv2;
360396
| ^^^^^^^^^^^^
361397

362-
error: type `types::Priv` is more private than the item `types::ES`
363-
--> $DIR/private-in-public-warn.rs:27:9
364-
|
365-
LL | pub static ES: Priv;
366-
| ^^^^^^^^^^^^^^^^^^^ static `types::ES` is reachable at visibility `pub(crate)`
367-
|
368-
note: but type `types::Priv` is only usable at visibility `pub(self)`
369-
--> $DIR/private-in-public-warn.rs:9:5
370-
|
371-
LL | struct Priv;
372-
| ^^^^^^^^^^^
373-
374-
error: type `types::Priv` is more private than the item `types::ef1`
375-
--> $DIR/private-in-public-warn.rs:28:9
376-
|
377-
LL | pub fn ef1(arg: Priv);
378-
| ^^^^^^^^^^^^^^^^^^^^^^ function `types::ef1` is reachable at visibility `pub(crate)`
379-
|
380-
note: but type `types::Priv` is only usable at visibility `pub(self)`
381-
--> $DIR/private-in-public-warn.rs:9:5
382-
|
383-
LL | struct Priv;
384-
| ^^^^^^^^^^^
385-
386-
error: type `types::Priv` is more private than the item `types::ef2`
387-
--> $DIR/private-in-public-warn.rs:29:9
388-
|
389-
LL | pub fn ef2() -> Priv;
390-
| ^^^^^^^^^^^^^^^^^^^^^ function `types::ef2` is reachable at visibility `pub(crate)`
391-
|
392-
note: but type `types::Priv` is only usable at visibility `pub(self)`
393-
--> $DIR/private-in-public-warn.rs:9:5
394-
|
395-
LL | struct Priv;
396-
| ^^^^^^^^^^^
397-
398398
warning: bounds on generic parameters in type aliases are not enforced
399399
--> $DIR/private-in-public-warn.rs:42:23
400400
|

‎tests/ui/privacy/projections.stderr‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
warning: type `Priv` is more private than the item `Leak`
2-
--> $DIR/projections.rs:3:5
3-
|
4-
LL | pub type Leak = Priv;
5-
| ^^^^^^^^^^^^^ type alias `Leak` is reachable at visibility `pub(crate)`
6-
|
7-
note: but type `Priv` is only usable at visibility `pub(self)`
8-
--> $DIR/projections.rs:2:5
9-
|
10-
LL | struct Priv;
11-
| ^^^^^^^^^^^
12-
= note: `#[warn(private_interfaces)]` on by default
13-
141
error[E0446]: private type `Priv` in public interface
152
--> $DIR/projections.rs:24:5
163
|
@@ -29,6 +16,19 @@ LL | struct Priv;
2916
LL | type A<T: Trait> = T::A<m::Leak>;
3017
| ^^^^^^^^^^^^^^^^ can't leak private type
3118

19+
warning: type `Priv` is more private than the item `Leak`
20+
--> $DIR/projections.rs:3:5
21+
|
22+
LL | pub type Leak = Priv;
23+
| ^^^^^^^^^^^^^ type alias `Leak` is reachable at visibility `pub(crate)`
24+
|
25+
note: but type `Priv` is only usable at visibility `pub(self)`
26+
--> $DIR/projections.rs:2:5
27+
|
28+
LL | struct Priv;
29+
| ^^^^^^^^^^^
30+
= note: `#[warn(private_interfaces)]` on by default
31+
3232
error: type `Priv` is private
3333
--> $DIR/projections.rs:14:15
3434
|

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /