Skip to content

Commit 4695ddf

Browse files
committed
privacy: Support #![rustc_effective_visibility] on the crate root
1 parent bf57e8a commit 4695ddf

File tree

3 files changed

+38
-24
lines changed

3 files changed

+38
-24
lines changed

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,7 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
21492149

21502150
let mut check_visitor =
21512151
TestReachabilityVisitor { tcx, effective_visibilities: &visitor.effective_visibilities };
2152+
check_visitor.effective_visibility_diagnostic(CRATE_DEF_ID);
21522153
tcx.hir().visit_all_item_likes_in_crate(&mut check_visitor);
21532154

21542155
tcx.arena.alloc(visitor.effective_visibilities)

tests/ui/privacy/effective_visibilities.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![rustc_effective_visibility] //~ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
12
#![feature(rustc_attrs)]
23

34
#[rustc_effective_visibility]
Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,152 @@
1+
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
2+
--> $DIR/effective_visibilities.rs:1:1
3+
|
4+
LL | / #![rustc_effective_visibility]
5+
LL | | #![feature(rustc_attrs)]
6+
LL | |
7+
LL | | #[rustc_effective_visibility]
8+
... |
9+
LL | |
10+
LL | | fn main() {}
11+
| |____________^
12+
113
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
2-
--> $DIR/effective_visibilities.rs:4:1
14+
--> $DIR/effective_visibilities.rs:5:1
315
|
416
LL | mod outer {
517
| ^^^^^^^^^
618

719
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
8-
--> $DIR/effective_visibilities.rs:6:5
20+
--> $DIR/effective_visibilities.rs:7:5
921
|
1022
LL | pub mod inner1 {
1123
| ^^^^^^^^^^^^^^
1224

1325
error: not in the table
14-
--> $DIR/effective_visibilities.rs:9:9
26+
--> $DIR/effective_visibilities.rs:10:9
1527
|
1628
LL | extern "C" {}
1729
| ^^^^^^^^^^^^^
1830

1931
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
20-
--> $DIR/effective_visibilities.rs:12:9
32+
--> $DIR/effective_visibilities.rs:13:9
2133
|
2234
LL | pub trait PubTrait {
2335
| ^^^^^^^^^^^^^^^^^^
2436

2537
error: Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
26-
--> $DIR/effective_visibilities.rs:20:9
38+
--> $DIR/effective_visibilities.rs:21:9
2739
|
2840
LL | struct PrivStruct;
2941
| ^^^^^^^^^^^^^^^^^
3042

3143
error: Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
32-
--> $DIR/effective_visibilities.rs:20:9
44+
--> $DIR/effective_visibilities.rs:21:9
3345
|
3446
LL | struct PrivStruct;
3547
| ^^^^^^^^^^^^^^^^^
3648

3749
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
38-
--> $DIR/effective_visibilities.rs:24:9
50+
--> $DIR/effective_visibilities.rs:25:9
3951
|
4052
LL | pub union PubUnion {
4153
| ^^^^^^^^^^^^^^^^^^
4254

4355
error: Direct: pub(self), Reexported: pub(self), Reachable: pub(self), ReachableThroughImplTrait: pub(self)
44-
--> $DIR/effective_visibilities.rs:26:13
56+
--> $DIR/effective_visibilities.rs:27:13
4557
|
4658
LL | a: u8,
4759
| ^^^^^
4860

4961
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
50-
--> $DIR/effective_visibilities.rs:28:13
62+
--> $DIR/effective_visibilities.rs:29:13
5163
|
5264
LL | pub b: u8,
5365
| ^^^^^^^^^
5466

5567
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
56-
--> $DIR/effective_visibilities.rs:32:9
68+
--> $DIR/effective_visibilities.rs:33:9
5769
|
5870
LL | pub enum Enum {
5971
| ^^^^^^^^^^^^^
6072

6173
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
62-
--> $DIR/effective_visibilities.rs:34:13
74+
--> $DIR/effective_visibilities.rs:35:13
6375
|
6476
LL | A(
6577
| ^
6678

6779
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
68-
--> $DIR/effective_visibilities.rs:34:13
80+
--> $DIR/effective_visibilities.rs:35:13
6981
|
7082
LL | A(
7183
| ^
7284

7385
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
74-
--> $DIR/effective_visibilities.rs:37:17
86+
--> $DIR/effective_visibilities.rs:38:17
7587
|
7688
LL | PubUnion,
7789
| ^^^^^^^^
7890

7991
error: not in the table
80-
--> $DIR/effective_visibilities.rs:43:5
92+
--> $DIR/effective_visibilities.rs:44:5
8193
|
8294
LL | macro_rules! none_macro {
8395
| ^^^^^^^^^^^^^^^^^^^^^^^
8496

8597
error: Direct: pub(self), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
86-
--> $DIR/effective_visibilities.rs:49:5
98+
--> $DIR/effective_visibilities.rs:50:5
8799
|
88100
LL | macro_rules! public_macro {
89101
| ^^^^^^^^^^^^^^^^^^^^^^^^^
90102

91103
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
92-
--> $DIR/effective_visibilities.rs:54:5
104+
--> $DIR/effective_visibilities.rs:55:5
93105
|
94106
LL | pub struct ReachableStruct {
95107
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
96108

97109
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
98-
--> $DIR/effective_visibilities.rs:56:9
110+
--> $DIR/effective_visibilities.rs:57:9
99111
|
100112
LL | pub a: u8,
101113
| ^^^^^^^^^
102114

103115
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
104-
--> $DIR/effective_visibilities.rs:61:9
116+
--> $DIR/effective_visibilities.rs:62:9
105117
|
106118
LL | pub use outer::inner1;
107119
| ^^^^^^^^^^^^^
108120

109121
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
110-
--> $DIR/effective_visibilities.rs:67:5
122+
--> $DIR/effective_visibilities.rs:68:5
111123
|
112124
LL | pub type HalfPublicImport = u8;
113125
| ^^^^^^^^^^^^^^^^^^^^^^^^^
114126

115127
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
116-
--> $DIR/effective_visibilities.rs:70:5
128+
--> $DIR/effective_visibilities.rs:71:5
117129
|
118130
LL | pub(crate) const HalfPublicImport: u8 = 0;
119131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120132

121133
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
122-
--> $DIR/effective_visibilities.rs:74:9
134+
--> $DIR/effective_visibilities.rs:75:9
123135
|
124136
LL | pub use half_public_import::HalfPublicImport;
125137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126138

127139
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
128-
--> $DIR/effective_visibilities.rs:14:13
140+
--> $DIR/effective_visibilities.rs:15:13
129141
|
130142
LL | const A: i32;
131143
| ^^^^^^^^^^^^
132144

133145
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
134-
--> $DIR/effective_visibilities.rs:16:13
146+
--> $DIR/effective_visibilities.rs:17:13
135147
|
136148
LL | type B;
137149
| ^^^^^^
138150

139-
error: aborting due to 23 previous errors
151+
error: aborting due to 24 previous errors
140152

0 commit comments

Comments
 (0)