1
Fork 0

privacy: Print effective visibilities of constructors

This commit is contained in:
Vadim Petrochenkov 2022-11-04 16:28:03 +04:00
parent 24093fc6bd
commit bb401bd04d
3 changed files with 38 additions and 16 deletions

View file

@ -959,6 +959,10 @@ impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> {
for variant in def.variants.iter() { for variant in def.variants.iter() {
let variant_id = self.tcx.hir().local_def_id(variant.id); let variant_id = self.tcx.hir().local_def_id(variant.id);
self.effective_visibility_diagnostic(variant_id); self.effective_visibility_diagnostic(variant_id);
if let Some(ctor_hir_id) = variant.data.ctor_hir_id() {
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
self.effective_visibility_diagnostic(ctor_def_id);
}
for field in variant.data.fields() { for field in variant.data.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); let def_id = self.tcx.hir().local_def_id(field.hir_id);
self.effective_visibility_diagnostic(def_id); self.effective_visibility_diagnostic(def_id);
@ -966,6 +970,10 @@ impl<'tcx, 'a> Visitor<'tcx> for TestReachabilityVisitor<'tcx, 'a> {
} }
} }
hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => { hir::ItemKind::Struct(ref def, _) | hir::ItemKind::Union(ref def, _) => {
if let Some(ctor_hir_id) = def.ctor_hir_id() {
let ctor_def_id = self.tcx.hir().local_def_id(ctor_hir_id);
self.effective_visibility_diagnostic(ctor_def_id);
}
for field in def.fields() { for field in def.fields() {
let def_id = self.tcx.hir().local_def_id(field.hir_id); let def_id = self.tcx.hir().local_def_id(field.hir_id);
self.effective_visibility_diagnostic(def_id); self.effective_visibility_diagnostic(def_id);

View file

@ -18,6 +18,7 @@ mod outer { //~ ERROR Direct: pub(crate), Reexported: pub(crate), Reachable: pub
#[rustc_effective_visibility] #[rustc_effective_visibility]
struct PrivStruct; //~ ERROR not in the table struct PrivStruct; //~ ERROR not in the table
//~| ERROR not in the table
#[rustc_effective_visibility] #[rustc_effective_visibility]
pub union PubUnion { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub 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
pub enum Enum { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub pub enum Enum { //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
#[rustc_effective_visibility] #[rustc_effective_visibility]
A( //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub A( //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
//~| ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
#[rustc_effective_visibility] #[rustc_effective_visibility]
PubUnion, //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub PubUnion, //~ ERROR Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
), ),

View file

@ -28,92 +28,104 @@ error: not in the table
LL | struct PrivStruct; LL | struct PrivStruct;
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: not in the table
--> $DIR/effective_visibilities.rs:20:9
|
LL | struct PrivStruct;
| ^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:23:9 --> $DIR/effective_visibilities.rs:24:9
| |
LL | pub union PubUnion { LL | pub union PubUnion {
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: not in the table error: not in the table
--> $DIR/effective_visibilities.rs:25:13 --> $DIR/effective_visibilities.rs:26:13
| |
LL | a: u8, LL | a: u8,
| ^^^^^ | ^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:27:13 --> $DIR/effective_visibilities.rs:28:13
| |
LL | pub b: u8, LL | pub b: u8,
| ^^^^^^^^^ | ^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:31:9 --> $DIR/effective_visibilities.rs:32:9
| |
LL | pub enum Enum { LL | pub enum Enum {
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:33:13 --> $DIR/effective_visibilities.rs:34:13
| |
LL | A( LL | A(
| ^ | ^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:35:17 --> $DIR/effective_visibilities.rs:34:13
|
LL | A(
| ^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:37:17
| |
LL | PubUnion, LL | PubUnion,
| ^^^^^^^^ | ^^^^^^^^
error: not in the table error: not in the table
--> $DIR/effective_visibilities.rs:41:5 --> $DIR/effective_visibilities.rs:43:5
| |
LL | macro_rules! none_macro { LL | macro_rules! none_macro {
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(self), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(self), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:47:5 --> $DIR/effective_visibilities.rs:49:5
| |
LL | macro_rules! public_macro { LL | macro_rules! public_macro {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:52:5 --> $DIR/effective_visibilities.rs:54:5
| |
LL | pub struct ReachableStruct { LL | pub struct ReachableStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:54:9 --> $DIR/effective_visibilities.rs:56:9
| |
LL | pub a: u8, LL | pub a: u8,
| ^^^^^^^^^ | ^^^^^^^^^
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:59:9 --> $DIR/effective_visibilities.rs:61:9
| |
LL | pub use outer::inner1; LL | pub use outer::inner1;
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:65:5 --> $DIR/effective_visibilities.rs:67:5
| |
LL | pub type HalfPublicImport = u8; LL | pub type HalfPublicImport = u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate) error: Direct: pub(crate), Reexported: pub(crate), Reachable: pub(crate), ReachableThroughImplTrait: pub(crate)
--> $DIR/effective_visibilities.rs:68:5 --> $DIR/effective_visibilities.rs:70:5
| |
LL | pub(crate) const HalfPublicImport: u8 = 0; LL | pub(crate) const HalfPublicImport: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:72:9 --> $DIR/effective_visibilities.rs:74:9
| |
LL | pub use half_public_import::HalfPublicImport; LL | pub use half_public_import::HalfPublicImport;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:72:9 --> $DIR/effective_visibilities.rs:74:9
| |
LL | pub use half_public_import::HalfPublicImport; LL | pub use half_public_import::HalfPublicImport;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -130,5 +142,5 @@ error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImpl
LL | type B; LL | type B;
| ^^^^^^ | ^^^^^^
error: aborting due to 22 previous errors error: aborting due to 24 previous errors