Skip to content

Do not lint private-in-public for RPITIT #144098

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,10 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
self.check(def_id, item_visibility, effective_vis).generics().predicates();

for assoc_item in tcx.associated_items(id.owner_id).in_definition_order() {
if assoc_item.is_impl_trait_in_trait() {
continue;
}

self.check_assoc_item(assoc_item, item_visibility, effective_vis);

if assoc_item.is_type() {
Expand Down Expand Up @@ -1736,6 +1740,10 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
check.ty().trait_ref();

for assoc_item in tcx.associated_items(id.owner_id).in_definition_order() {
if assoc_item.is_impl_trait_in_trait() {
continue;
}

let impl_item_vis = if !of_trait {
min(tcx.local_visibility(assoc_item.def_id.expect_local()), impl_vis, tcx)
} else {
Expand Down
12 changes: 11 additions & 1 deletion tests/ui/privacy/private-in-public-warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod types {

mod traits {
trait PrivTr {}
impl PrivTr for () {}
pub struct Pub<T>(T);
pub trait PubTr {}

Expand All @@ -45,7 +46,10 @@ mod traits {
pub trait Tr3 {
type Alias: PrivTr;
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias`
fn f<T: PrivTr>(arg: T) {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
fn f<T: PrivTr>(arg: T) {}
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
fn g() -> impl PrivTr;
fn h() -> impl PrivTr {}
}
impl<T: PrivTr> Pub<T> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
Expand Down Expand Up @@ -75,12 +79,18 @@ mod generics {
pub struct Pub<T = u8>(T);
trait PrivTr<T> {}
pub trait PubTr<T> {}
impl PrivTr<Priv<()>> for () {}

pub trait Tr1: PrivTr<Pub> {}
//~^ ERROR trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
pub trait Tr2: PubTr<Priv> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr2`
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr3`
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR type `generics::Priv` is more private than the item `Tr4`

pub trait Tr5 {
fn required() -> impl PrivTr<Priv<()>>;
fn provided() -> impl PrivTr<Priv<()>> {}
}
}

mod impls {
Expand Down
74 changes: 37 additions & 37 deletions tests/ui/privacy/private-in-public-warn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type

error: trait `traits::PrivTr` is more private than the item `traits::Alias`
--> $DIR/private-in-public-warn.rs:41:5
--> $DIR/private-in-public-warn.rs:42:5
|
LL | pub type Alias<T: PrivTr> = T;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ type alias `traits::Alias` is reachable at visibility `pub(crate)`
Expand All @@ -147,7 +147,7 @@ LL | #![deny(private_interfaces, private_bounds)]
| ^^^^^^^^^^^^^^

error: trait `traits::PrivTr` is more private than the item `traits::Tr1`
--> $DIR/private-in-public-warn.rs:43:5
--> $DIR/private-in-public-warn.rs:44:5
|
LL | pub trait Tr1: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr1` is reachable at visibility `pub(crate)`
Expand All @@ -159,7 +159,7 @@ LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits::PrivTr` is more private than the item `traits::Tr2`
--> $DIR/private-in-public-warn.rs:44:5
--> $DIR/private-in-public-warn.rs:45:5
|
LL | pub trait Tr2<T: PrivTr> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ trait `traits::Tr2` is reachable at visibility `pub(crate)`
Expand All @@ -171,7 +171,7 @@ LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias`
--> $DIR/private-in-public-warn.rs:46:9
--> $DIR/private-in-public-warn.rs:47:9
|
LL | type Alias: PrivTr;
| ^^^^^^^^^^^^^^^^^^ associated type `traits::Tr3::Alias` is reachable at visibility `pub(crate)`
Expand All @@ -183,7 +183,7 @@ LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
--> $DIR/private-in-public-warn.rs:48:9
--> $DIR/private-in-public-warn.rs:49:9
|
LL | fn f<T: PrivTr>(arg: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits::Tr3::f` is reachable at visibility `pub(crate)`
Expand All @@ -195,7 +195,7 @@ LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
--> $DIR/private-in-public-warn.rs:50:5
--> $DIR/private-in-public-warn.rs:54:5
|
LL | impl<T: PrivTr> Pub<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)`
Expand All @@ -207,103 +207,103 @@ LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits_where::PrivTr` is more private than the item `traits_where::Alias`
--> $DIR/private-in-public-warn.rs:59:5
--> $DIR/private-in-public-warn.rs:63:5
|
LL | pub type Alias<T> where T: PrivTr = T;
| ^^^^^^^^^^^^^^^^^ type alias `traits_where::Alias` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
--> $DIR/private-in-public-warn.rs:59:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2`
--> $DIR/private-in-public-warn.rs:62:5
--> $DIR/private-in-public-warn.rs:66:5
|
LL | pub trait Tr2<T> where T: PrivTr {}
| ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
--> $DIR/private-in-public-warn.rs:59:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f`
--> $DIR/private-in-public-warn.rs:65:9
--> $DIR/private-in-public-warn.rs:69:9
|
LL | fn f<T>(arg: T) where T: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Tr3::f` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
--> $DIR/private-in-public-warn.rs:59:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
--> $DIR/private-in-public-warn.rs:68:5
--> $DIR/private-in-public-warn.rs:72:5
|
LL | impl<T> Pub<T> where T: PrivTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)`
|
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:55:5
--> $DIR/private-in-public-warn.rs:59:5
|
LL | trait PrivTr {}
| ^^^^^^^^^^^^

error: trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
--> $DIR/private-in-public-warn.rs:79:5
--> $DIR/private-in-public-warn.rs:84:5
|
LL | pub trait Tr1: PrivTr<Pub> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)`
|
note: but trait `generics::PrivTr<generics::Pub>` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:76:5
--> $DIR/private-in-public-warn.rs:80:5
|
LL | trait PrivTr<T> {}
| ^^^^^^^^^^^^^^^

error: type `generics::Priv` is more private than the item `generics::Tr2`
--> $DIR/private-in-public-warn.rs:81:5
--> $DIR/private-in-public-warn.rs:86:5
|
LL | pub trait Tr2: PubTr<Priv> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr2` is reachable at visibility `pub(crate)`
|
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:74:5
--> $DIR/private-in-public-warn.rs:78:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^

error: type `generics::Priv` is more private than the item `generics::Tr3`
--> $DIR/private-in-public-warn.rs:82:5
--> $DIR/private-in-public-warn.rs:87:5
|
LL | pub trait Tr3: PubTr<[Priv; 1]> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr3` is reachable at visibility `pub(crate)`
|
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:74:5
--> $DIR/private-in-public-warn.rs:78:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^

error: type `generics::Priv` is more private than the item `Tr4`
--> $DIR/private-in-public-warn.rs:83:5
--> $DIR/private-in-public-warn.rs:88:5
|
LL | pub trait Tr4: PubTr<Pub<Priv>> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `Tr4` is reachable at visibility `pub(crate)`
|
note: but type `generics::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:74:5
--> $DIR/private-in-public-warn.rs:78:5
|
LL | struct Priv<T = u8>(T);
| ^^^^^^^^^^^^^^^^^^^

error[E0446]: private type `impls::Priv` in public interface
--> $DIR/private-in-public-warn.rs:109:9
--> $DIR/private-in-public-warn.rs:119:9
|
LL | struct Priv;
| ----------- `impls::Priv` declared as private
Expand All @@ -312,19 +312,19 @@ LL | type Alias = Priv;
| ^^^^^^^^^^ can't leak private type

error: type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f`
--> $DIR/private-in-public-warn.rs:180:9
--> $DIR/private-in-public-warn.rs:190:9
|
LL | pub fn f(arg: Priv) {}
| ^^^^^^^^^^^^^^^^^^^ associated function `aliases_pub::<impl Pub2>::f` is reachable at visibility `pub(crate)`
|
note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:153:5
--> $DIR/private-in-public-warn.rs:163:5
|
LL | struct Priv;
| ^^^^^^^^^^^

error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:183:9
--> $DIR/private-in-public-warn.rs:193:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
Expand All @@ -333,7 +333,7 @@ LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type

error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:186:9
--> $DIR/private-in-public-warn.rs:196:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
Expand All @@ -342,7 +342,7 @@ LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type

error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:189:9
--> $DIR/private-in-public-warn.rs:199:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
Expand All @@ -351,7 +351,7 @@ LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type

error[E0446]: private type `aliases_pub::Priv` in public interface
--> $DIR/private-in-public-warn.rs:192:9
--> $DIR/private-in-public-warn.rs:202:9
|
LL | struct Priv;
| ----------- `aliases_pub::Priv` declared as private
Expand All @@ -360,43 +360,43 @@ LL | type Check = Priv;
| ^^^^^^^^^^ can't leak private type

error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1`
--> $DIR/private-in-public-warn.rs:222:5
--> $DIR/private-in-public-warn.rs:232:5
|
LL | pub trait Tr1: PrivUseAliasTr {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr1` is reachable at visibility `pub(crate)`
|
note: but trait `PrivTr1` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:208:5
--> $DIR/private-in-public-warn.rs:218:5
|
LL | trait PrivTr1<T = u8> {
| ^^^^^^^^^^^^^^^^^^^^^

error: trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2`
--> $DIR/private-in-public-warn.rs:224:5
--> $DIR/private-in-public-warn.rs:234:5
|
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
|
note: but trait `PrivTr1<Priv2>` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:208:5
--> $DIR/private-in-public-warn.rs:218:5
|
LL | trait PrivTr1<T = u8> {
| ^^^^^^^^^^^^^^^^^^^^^

error: type `Priv2` is more private than the item `aliases_priv::Tr2`
--> $DIR/private-in-public-warn.rs:224:5
--> $DIR/private-in-public-warn.rs:234:5
|
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
|
note: but type `Priv2` is only usable at visibility `pub(self)`
--> $DIR/private-in-public-warn.rs:206:5
--> $DIR/private-in-public-warn.rs:216:5
|
LL | struct Priv2;
| ^^^^^^^^^^^^

warning: bounds on generic parameters in type aliases are not enforced
--> $DIR/private-in-public-warn.rs:41:23
--> $DIR/private-in-public-warn.rs:42:23
|
LL | pub type Alias<T: PrivTr> = T;
| --^^^^^^
Expand All @@ -410,7 +410,7 @@ LL | pub type Alias<T: PrivTr> = T;
= note: `#[warn(type_alias_bounds)]` on by default

warning: where clauses on type aliases are not enforced
--> $DIR/private-in-public-warn.rs:59:29
--> $DIR/private-in-public-warn.rs:63:29
|
LL | pub type Alias<T> where T: PrivTr = T;
| ------^^^^^^^^^
Expand Down
1 change: 1 addition & 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 Down
6 changes: 5 additions & 1 deletion tests/ui/privacy/pub-priv-dep/pub-priv1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ impl PublicType {

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

fn required() -> impl OtherTrait;

fn provided() -> impl OtherTrait { OtherType }
}
//~^^ 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 Down
Loading
Loading