Skip to content

Commit 81ab7f2

Browse files
Auto merge of #146470 - mladedav:dm/reenable-private-in-public-rpitit-errors, r=<try>
Revert "Do not check privacy for RPITIT."
2 parents 377656d + 48f6655 commit 81ab7f2

File tree

7 files changed

+222
-118
lines changed

7 files changed

+222
-118
lines changed

‎compiler/rustc_privacy/src/lib.rs‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use rustc_middle::middle::privacy::{EffectiveVisibilities, EffectiveVisibility,
2929
use rustc_middle::query::Providers;
3030
use rustc_middle::ty::print::PrintTraitRefExt as _;
3131
use rustc_middle::ty::{
32-
self, Const, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
33-
TypeVisitor,
32+
self, AssocContainer, Const, GenericParamDefKind, TraitRef, Ty, TyCtxt, TypeSuperVisitable,
33+
TypeVisitable, TypeVisitor,
3434
};
3535
use rustc_middle::{bug, span_bug};
3636
use rustc_session::lint;
@@ -1594,6 +1594,9 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
15941594
if check_ty {
15951595
check.ty();
15961596
}
1597+
if is_assoc_ty && item.container == AssocContainer::Trait {
1598+
check.bounds();
1599+
}
15971600
}
15981601

15991602
fn get(&self, def_id: LocalDefId) -> Option<EffectiveVisibility> {
@@ -1625,20 +1628,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
16251628
self.check(def_id, item_visibility, effective_vis).generics().predicates();
16261629

16271630
for assoc_item in tcx.associated_items(id.owner_id).in_definition_order() {
1628-
if assoc_item.is_impl_trait_in_trait() {
1629-
continue;
1630-
}
1631-
16321631
self.check_assoc_item(assoc_item, item_visibility, effective_vis);
1633-
1634-
if assoc_item.is_type() {
1635-
self.check(
1636-
assoc_item.def_id.expect_local(),
1637-
item_visibility,
1638-
effective_vis,
1639-
)
1640-
.bounds();
1641-
}
16421632
}
16431633
}
16441634
DefKind::TraitAlias => {
@@ -1712,10 +1702,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
17121702
}
17131703

17141704
for assoc_item in tcx.associated_items(id.owner_id).in_definition_order() {
1715-
if assoc_item.is_impl_trait_in_trait() {
1716-
continue;
1717-
}
1718-
17191705
let impl_item_vis = if !of_trait {
17201706
min(tcx.local_visibility(assoc_item.def_id.expect_local()), impl_vis, tcx)
17211707
} else {

‎tests/ui/privacy/private-in-public-assoc-ty.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ mod m {
2222
// applies only to the aliased types, not bounds.
2323
pub trait PubTr {
2424
type Alias1: PrivTr;
25-
//~^ WARN trait `PrivTr` is more private than the item `PubTr::Alias1`
25+
//~^ ERROR private trait `PrivTr` in public interface
2626
type Alias2: PubTrAux1<Priv> = u8;
27-
//~^ WARN type `Priv` is more private than the item `PubTr::Alias2`
27+
//~^ ERROR private type `Priv` in public interface
2828
type Alias3: PubTrAux2<A = Priv> = u8;
29-
//~^ WARN type `Priv` is more private than the item `PubTr::Alias3`
29+
//~^ ERROR private type `Priv` in public interface
3030

3131
type Alias4 = Priv;
3232
//~^ ERROR private type `Priv` in public interface

‎tests/ui/privacy/private-in-public-assoc-ty.stderr‎

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,32 @@ LL | struct Priv;
77
LL | type A = Priv;
88
| ^^^^^^ can't leak private type
99

10-
warning: trait `PrivTr` is more private than the item `PubTr::Alias1`
10+
error[E0446]: private trait `PrivTr` in public interface
1111
--> $DIR/private-in-public-assoc-ty.rs:24:9
1212
|
13-
LL | type Alias1: PrivTr;
14-
| ^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias1` is reachable at visibility `pub(crate)`
15-
|
16-
note: but trait `PrivTr` is only usable at visibility `pub(self)`
17-
--> $DIR/private-in-public-assoc-ty.rs:9:5
18-
|
1913
LL | trait PrivTr {}
20-
| ^^^^^^^^^^^^
21-
= note: `#[warn(private_bounds)]` on by default
14+
| ------------ `PrivTr` declared as private
15+
...
16+
LL | type Alias1: PrivTr;
17+
| ^^^^^^^^^^^^^^^^^^^ can't leak private trait
2218

23-
warning: type `Priv` is more private than the item `PubTr::Alias2`
19+
error[E0446]: private type `Priv` in public interface
2420
--> $DIR/private-in-public-assoc-ty.rs:26:9
2521
|
26-
LL | type Alias2: PubTrAux1<Priv> = u8;
27-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias2` is reachable at visibility `pub(crate)`
28-
|
29-
note: but type `Priv` is only usable at visibility `pub(self)`
30-
--> $DIR/private-in-public-assoc-ty.rs:8:5
31-
|
3222
LL | struct Priv;
33-
| ^^^^^^^^^^^
23+
| ----------- `Priv` declared as private
24+
...
25+
LL | type Alias2: PubTrAux1<Priv> = u8;
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
3427

35-
warning: type `Priv` is more private than the item `PubTr::Alias3`
28+
error[E0446]: private type `Priv` in public interface
3629
--> $DIR/private-in-public-assoc-ty.rs:28:9
3730
|
38-
LL | type Alias3: PubTrAux2<A = Priv> = u8;
39-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `PubTr::Alias3` is reachable at visibility `pub(crate)`
40-
|
41-
note: but type `Priv` is only usable at visibility `pub(self)`
42-
--> $DIR/private-in-public-assoc-ty.rs:8:5
43-
|
4431
LL | struct Priv;
45-
| ^^^^^^^^^^^
32+
| ----------- `Priv` declared as private
33+
...
34+
LL | type Alias3: PubTrAux2<A = Priv> = u8;
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
4636

4737
error[E0446]: private type `Priv` in public interface
4838
--> $DIR/private-in-public-assoc-ty.rs:31:9
@@ -71,6 +61,6 @@ LL | trait PrivTr {}
7161
LL | type Exist = impl PrivTr;
7262
| ^^^^^^^^^^ can't leak private trait
7363

74-
error: aborting due to 4 previous errors; 3 warnings emitted
64+
error: aborting due to 7 previous errors
7565

7666
For more information about this error, try `rustc --explain E0446`.

‎tests/ui/privacy/private-in-public-warn.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ mod traits {
4545
pub trait Tr2<T: PrivTr> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr2`
4646
pub trait Tr3 {
4747
type Alias: PrivTr;
48-
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias`
48+
//~^ ERROR private trait `traits::PrivTr` in public interface
4949
fn f<T: PrivTr>(arg: T) {}
5050
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
5151
fn g() -> impl PrivTr;
52+
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::g::{anon_assoc#0}`
5253
fn h() -> impl PrivTr {}
54+
//~^ ERROR private trait `traits::PrivTr` in public interface
55+
//~| ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::h::{anon_assoc#0}`
5356
}
5457
impl<T: PrivTr> Pub<T> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
5558
impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
@@ -89,7 +92,13 @@ mod generics {
8992

9093
pub trait Tr5 {
9194
fn required() -> impl PrivTr<Priv<()>>;
95+
//~^ ERROR trait `generics::PrivTr<generics::Priv<()>>` is more private than the item `Tr5::required::{anon_assoc#0}`
96+
//~| ERROR type `generics::Priv<()>` is more private than the item `Tr5::required::{anon_assoc#0}`
9297
fn provided() -> impl PrivTr<Priv<()>> {}
98+
//~^ ERROR private trait `generics::PrivTr<generics::Priv<()>>` in public interface
99+
//~| ERROR private type `generics::Priv<()>` in public interface
100+
//~| ERROR trait `generics::PrivTr<generics::Priv<()>>` is more private than the item `Tr5::provided::{anon_assoc#0}`
101+
//~| ERROR type `generics::Priv<()>` is more private than the item `Tr5::provided::{anon_assoc#0}`
93102
}
94103
}
95104

0 commit comments

Comments
 (0)