Skip to content

Commit bb401bd

Browse files
committed
privacy: Print effective visibilities of constructors
1 parent 24093fc commit bb401bd

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

compiler/rustc_privacy/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -959,13 +959,21 @@ impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> {
959959
for variant in def.variants.iter() {
960960
let variant_id = self.tcx.hir().local_def_id(variant.id);
961961
self.effective_visibility_diagnostic(variant_id);
962+
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
963+
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
964+
self.effective_visibility_diagnostic(ctor_def_id);
965+
}
962966
for field in variant.data.fields() {
963967
let def_id = self.tcx.hir().local_def_id(field.hir_id);
964968
self.effective_visibility_diagnostic(def_id);
965969
}
966970
}
967971
}
968972
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
973+
if let Some(ctor_hir_id) = def.ctor_hir_id() {
974+
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
975+
self.effective_visibility_diagnostic(ctor_def_id);
976+
}
969977
for field in def.fields() {
970978
let def_id = self.tcx.hir().local_def_id(field.hir_id);
971979
self.effective_visibility_diagnostic(def_id);

src/test/ui/privacy/effective_visibilities.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub
1818

1919
#[rustc_effective_visibility]
2020
struct PrivStruct; //~ ERROR not in the table
21+
//~| ERROR not in the table
2122

2223
#[rustc_effective_visibility]
2324
pub union PubUnion { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
@@ -31,6 +32,7 @@ mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub
3132
pub enum Enum { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
3233
#[rustc_effective_visibility]
3334
A( //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
35+
//~| ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
3436
#[rustc_effective_visibility]
3537
PubUnion, //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
3638
),

src/test/ui/privacy/effective_visibilities.stderr

+28-16
Original file line numberDiff line numberDiff line change
@@ -28,92 +28,104 @@ error: not in the table
2828
LL | struct PrivStruct;
2929
| ^^^^^^^^^^^^^^^^^
3030

31+
error: not in the table
32+
--> $DIR/effective_visibilities.rs:20:9
33+
|
34+
LL | struct PrivStruct;
35+
| ^^^^^^^^^^^^^^^^^
36+
3137
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
32-
--> $DIR/effective_visibilities.rs:23:9
38+
--> $DIR/effective_visibilities.rs:24:9
3339
|
3440
LL | pub union PubUnion {
3541
| ^^^^^^^^^^^^^^^^^^
3642

3743
error: not in the table
38-
--> $DIR/effective_visibilities.rs:25:13
44+
--> $DIR/effective_visibilities.rs:26:13
3945
|
4046
LL | a: u8,
4147
| ^^^^^
4248

4349
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
44-
--> $DIR/effective_visibilities.rs:27:13
50+
--> $DIR/effective_visibilities.rs:28:13
4551
|
4652
LL | pub b: u8,
4753
| ^^^^^^^^^
4854

4955
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
50-
--> $DIR/effective_visibilities.rs:31:9
56+
--> $DIR/effective_visibilities.rs:32:9
5157
|
5258
LL | pub enum Enum {
5359
| ^^^^^^^^^^^^^
5460

5561
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
56-
--> $DIR/effective_visibilities.rs:33:13
62+
--> $DIR/effective_visibilities.rs:34:13
63+
|
64+
LL | A(
65+
| ^
66+
67+
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
68+
--> $DIR/effective_visibilities.rs:34:13
5769
|
5870
LL | A(
5971
| ^
6072

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

6779
error: not in the table
68-
--> $DIR/effective_visibilities.rs:41:5
80+
--> $DIR/effective_visibilities.rs:43:5
6981
|
7082
LL | macro_rules! none_macro {
7183
| ^^^^^^^^^^^^^^^^^^^^^^^
7284

7385
error: Direct: pub(self), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
74-
--> $DIR/effective_visibilities.rs:47:5
86+
--> $DIR/effective_visibilities.rs:49:5
7587
|
7688
LL | macro_rules! public_macro {
7789
| ^^^^^^^^^^^^^^^^^^^^^^^^^
7890

7991
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
80-
--> $DIR/effective_visibilities.rs:52:5
92+
--> $DIR/effective_visibilities.rs:54:5
8193
|
8294
LL | pub struct ReachableStruct {
8395
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
8496

8597
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
86-
--> $DIR/effective_visibilities.rs:54:9
98+
--> $DIR/effective_visibilities.rs:56:9
8799
|
88100
LL | pub a: u8,
89101
| ^^^^^^^^^
90102

91103
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
92-
--> $DIR/effective_visibilities.rs:59:9
104+
--> $DIR/effective_visibilities.rs:61:9
93105
|
94106
LL | pub use outer::inner1;
95107
| ^^^^^^^^^^^^^
96108

97109
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
98-
--> $DIR/effective_visibilities.rs:65:5
110+
--> $DIR/effective_visibilities.rs:67:5
99111
|
100112
LL | pub type HalfPublicImport = u8;
101113
| ^^^^^^^^^^^^^^^^^^^^^^^^^
102114

103115
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
104-
--> $DIR/effective_visibilities.rs:68:5
116+
--> $DIR/effective_visibilities.rs:70:5
105117
|
106118
LL | pub(crate) const HalfPublicImport: u8 = 0;
107119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108120

109121
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
110-
--> $DIR/effective_visibilities.rs:72:9
122+
--> $DIR/effective_visibilities.rs:74:9
111123
|
112124
LL | pub use half_public_import::HalfPublicImport;
113125
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114126

115127
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
116-
--> $DIR/effective_visibilities.rs:72:9
128+
--> $DIR/effective_visibilities.rs:74:9
117129
|
118130
LL | pub use half_public_import::HalfPublicImport;
119131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -130,5 +142,5 @@ error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImpl
130142
LL | type B;
131143
| ^^^^^^
132144

133-
error: aborting due to 22 previous errors
145+
error: aborting due to 24 previous errors
134146

0 commit comments

Comments
 (0)