Skip to content

tests: cover more exported_private_dependencies cases #144082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/ui/privacy/pub-priv-dep/auxiliary/priv_dep.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub struct OtherType;
pub trait OtherTrait {}
impl OtherTrait for OtherType {}

#[macro_export]
macro_rules! m {
Expand All @@ -9,3 +10,9 @@ macro_rules! m {
pub enum E {
V1
}

struct PrivType;

pub type Unit = ();
pub type PubPub = OtherType;
pub type PubPriv = PrivType;
76 changes: 75 additions & 1 deletion tests/ui/privacy/pub-priv-dep/pub-priv1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ pub struct PublicType {
pub other_field: PubType, // Type from public dependency - this is fine
}

pub struct PublicTuple(
pub OtherType,
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies]
OtherType,
PubType,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for symmetry with the struct, should this field be pub?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed.

);

pub enum PublicEnum {
OtherType,
ActualOtherType(OtherType, PubType),
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies]
ActualOtherTypeStruct {
field: OtherType,
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface [exported_private_dependencies]
pub other_field: PubType,
},
}

pub struct PublicGenericType<T, U>(pub T, U);
pub type ReexportedPublicGeneric = PublicGenericType<OtherType, ()>;
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
pub type ReexportedPrivateGeneric = PublicGenericType<(), OtherType>;
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface

pub struct PublicGenericBoundedType<T: OtherTrait>(T);
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

impl PublicType {
pub fn pub_fn_param(param: OtherType) {}
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
Expand All @@ -44,8 +71,21 @@ impl PublicType {

pub trait MyPubTrait {
type Foo: OtherTrait;
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

fn required_impl_trait() -> impl OtherTrait;
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

fn provided_impl_trait() -> impl OtherTrait { OtherType }
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
//~| ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

fn required_concrete() -> OtherType;
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface

fn provided_concrete() -> OtherType { OtherType }
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
}
//~^^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

pub trait WithSuperTrait: OtherTrait {}
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
Expand All @@ -63,6 +103,12 @@ impl PubLocalTraitWithAssoc for PrivateAssoc {
pub fn in_bounds<T: OtherTrait>(x: T) { unimplemented!() }
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

pub fn private_return_impl_trait() -> impl OtherTrait { OtherType }
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

pub fn private_return() -> OtherType { OtherType }
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface

pub fn private_in_generic() -> std::num::Saturating<OtherType> { unimplemented!() }
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface

Expand All @@ -75,6 +121,9 @@ pub const CONST: OtherType = OtherType;
pub type Alias = OtherType;
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface

pub type AliasOfAlias = priv_dep::PubPub;
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface

pub struct PublicWithPrivateImpl;

impl OtherTrait for PublicWithPrivateImpl {}
Expand All @@ -86,6 +135,22 @@ impl PubTraitOnPrivate for OtherType {}
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface

pub struct PublicWithStdImpl;

impl From<OtherType> for PublicWithStdImpl {
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
fn from(val: OtherType) -> Self { Self }
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
}

impl From<PublicWithStdImpl> for OtherType {
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
fn from(val: PublicWithStdImpl) -> Self { Self }
//~^ ERROR type `OtherType` from private dependency 'priv_dep' in public interface
//~| ERROR type `OtherType` from private dependency 'priv_dep' in public interface
}

pub struct AllowedPrivType {
#[allow(exported_private_dependencies)]
pub allowed: OtherType,
Expand All @@ -103,4 +168,13 @@ pub use pm::pm_attr;
pub use priv_dep::E::V1;
//~^ ERROR variant `V1` from private dependency 'priv_dep' is re-exported

pub use priv_dep::Unit;
//~^ ERROR type alias `Unit` from private dependency 'priv_dep' is re-exported
pub use priv_dep::PubPub;
//~^ ERROR type alias `PubPub` from private dependency 'priv_dep' is re-exported
pub use priv_dep::PubPriv;
//~^ ERROR type alias `PubPriv` from private dependency 'priv_dep' is re-exported
pub use priv_dep::OtherType as Renamed;
//~^ ERROR struct `Renamed` from private dependency 'priv_dep' is re-exported

fn main() {}
Loading
Loading