Skip to content

Commit e117153

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 c90bcb9 + 598d6ad commit e117153

File tree

5 files changed

+194
-71
lines changed

5 files changed

+194
-71
lines changed

compiler/rustc_privacy/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,10 +1625,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
16251625
self.check(def_id, item_visibility, effective_vis).generics().predicates();
16261626

16271627
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-
16321628
self.check_assoc_item(assoc_item, item_visibility, effective_vis);
16331629

16341630
if assoc_item.is_type() {
@@ -1712,10 +1708,6 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
17121708
}
17131709

17141710
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-
17191711
let impl_item_vis = if !of_trait {
17201712
min(tcx.local_visibility(assoc_item.def_id.expect_local()), impl_vis, tcx)
17211713
} else {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ mod traits {
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

tests/ui/privacy/private-in-public-warn.stderr

Lines changed: 131 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,41 @@ note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
194194
LL | trait PrivTr {}
195195
| ^^^^^^^^^^^^
196196

197+
error: trait `traits::PrivTr` is more private than the item `traits::Tr3::g::{anon_assoc#0}`
198+
--> $DIR/private-in-public-warn.rs:51:19
199+
|
200+
LL | fn g() -> impl PrivTr;
201+
| ^^^^^^^^^^^ opaque type `traits::Tr3::g::{anon_assoc#0}` is reachable at visibility `pub(crate)`
202+
|
203+
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
204+
--> $DIR/private-in-public-warn.rs:37:5
205+
|
206+
LL | trait PrivTr {}
207+
| ^^^^^^^^^^^^
208+
209+
error[E0446]: private trait `traits::PrivTr` in public interface
210+
--> $DIR/private-in-public-warn.rs:53:19
211+
|
212+
LL | trait PrivTr {}
213+
| ------------ `traits::PrivTr` declared as private
214+
...
215+
LL | fn h() -> impl PrivTr {}
216+
| ^^^^^^^^^^^ can't leak private trait
217+
218+
error: trait `traits::PrivTr` is more private than the item `traits::Tr3::h::{anon_assoc#0}`
219+
--> $DIR/private-in-public-warn.rs:53:19
220+
|
221+
LL | fn h() -> impl PrivTr {}
222+
| ^^^^^^^^^^^ opaque type `traits::Tr3::h::{anon_assoc#0}` is reachable at visibility `pub(crate)`
223+
|
224+
note: but trait `traits::PrivTr` is only usable at visibility `pub(self)`
225+
--> $DIR/private-in-public-warn.rs:37:5
226+
|
227+
LL | trait PrivTr {}
228+
| ^^^^^^^^^^^^
229+
197230
error: trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
198-
--> $DIR/private-in-public-warn.rs:54:5
231+
--> $DIR/private-in-public-warn.rs:57:5
199232
|
200233
LL | impl<T: PrivTr> Pub<T> {}
201234
| ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)`
@@ -207,103 +240,169 @@ LL | trait PrivTr {}
207240
| ^^^^^^^^^^^^
208241

209242
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Alias`
210-
--> $DIR/private-in-public-warn.rs:63:5
243+
--> $DIR/private-in-public-warn.rs:66:5
211244
|
212245
LL | pub type Alias<T> where T: PrivTr = T;
213246
| ^^^^^^^^^^^^^^^^^ type alias `traits_where::Alias` is reachable at visibility `pub(crate)`
214247
|
215248
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
216-
--> $DIR/private-in-public-warn.rs:59:5
249+
--> $DIR/private-in-public-warn.rs:62:5
217250
|
218251
LL | trait PrivTr {}
219252
| ^^^^^^^^^^^^
220253

221254
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2`
222-
--> $DIR/private-in-public-warn.rs:66:5
255+
--> $DIR/private-in-public-warn.rs:69:5
223256
|
224257
LL | pub trait Tr2<T> where T: PrivTr {}
225258
| ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)`
226259
|
227260
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
228-
--> $DIR/private-in-public-warn.rs:59:5
261+
--> $DIR/private-in-public-warn.rs:62:5
229262
|
230263
LL | trait PrivTr {}
231264
| ^^^^^^^^^^^^
232265

233266
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f`
234-
--> $DIR/private-in-public-warn.rs:69:9
267+
--> $DIR/private-in-public-warn.rs:72:9
235268
|
236269
LL | fn f<T>(arg: T) where T: PrivTr {}
237270
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Tr3::f` is reachable at visibility `pub(crate)`
238271
|
239272
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
240-
--> $DIR/private-in-public-warn.rs:59:5
273+
--> $DIR/private-in-public-warn.rs:62:5
241274
|
242275
LL | trait PrivTr {}
243276
| ^^^^^^^^^^^^
244277

245278
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
246-
--> $DIR/private-in-public-warn.rs:72:5
279+
--> $DIR/private-in-public-warn.rs:75:5
247280
|
248281
LL | impl<T> Pub<T> where T: PrivTr {}
249282
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)`
250283
|
251284
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
252-
--> $DIR/private-in-public-warn.rs:59:5
285+
--> $DIR/private-in-public-warn.rs:62:5
253286
|
254287
LL | trait PrivTr {}
255288
| ^^^^^^^^^^^^
256289

257290
error: trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
258-
--> $DIR/private-in-public-warn.rs:84:5
291+
--> $DIR/private-in-public-warn.rs:87:5
259292
|
260293
LL | pub trait Tr1: PrivTr<Pub> {}
261294
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)`
262295
|
263296
note: but trait `generics::PrivTr<generics::Pub>` is only usable at visibility `pub(self)`
264-
--> $DIR/private-in-public-warn.rs:80:5
297+
--> $DIR/private-in-public-warn.rs:83:5
265298
|
266299
LL | trait PrivTr<T> {}
267300
| ^^^^^^^^^^^^^^^
268301

269302
error: type `generics::Priv` is more private than the item `generics::Tr2`
270-
--> $DIR/private-in-public-warn.rs:86:5
303+
--> $DIR/private-in-public-warn.rs:89:5
271304
|
272305
LL | pub trait Tr2: PubTr<Priv> {}
273306
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr2` is reachable at visibility `pub(crate)`
274307
|
275308
note: but type `generics::Priv` is only usable at visibility `pub(self)`
276-
--> $DIR/private-in-public-warn.rs:78:5
309+
--> $DIR/private-in-public-warn.rs:81:5
277310
|
278311
LL | struct Priv<T = u8>(T);
279312
| ^^^^^^^^^^^^^^^^^^^
280313

281314
error: type `generics::Priv` is more private than the item `generics::Tr3`
282-
--> $DIR/private-in-public-warn.rs:87:5
315+
--> $DIR/private-in-public-warn.rs:90:5
283316
|
284317
LL | pub trait Tr3: PubTr<[Priv; 1]> {}
285318
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr3` is reachable at visibility `pub(crate)`
286319
|
287320
note: but type `generics::Priv` is only usable at visibility `pub(self)`
288-
--> $DIR/private-in-public-warn.rs:78:5
321+
--> $DIR/private-in-public-warn.rs:81:5
289322
|
290323
LL | struct Priv<T = u8>(T);
291324
| ^^^^^^^^^^^^^^^^^^^
292325

293326
error: type `generics::Priv` is more private than the item `Tr4`
294-
--> $DIR/private-in-public-warn.rs:88:5
327+
--> $DIR/private-in-public-warn.rs:91:5
295328
|
296329
LL | pub trait Tr4: PubTr<Pub<Priv>> {}
297330
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `Tr4` is reachable at visibility `pub(crate)`
298331
|
299332
note: but type `generics::Priv` is only usable at visibility `pub(self)`
300-
--> $DIR/private-in-public-warn.rs:78:5
333+
--> $DIR/private-in-public-warn.rs:81:5
334+
|
335+
LL | struct Priv<T = u8>(T);
336+
| ^^^^^^^^^^^^^^^^^^^
337+
338+
error: trait `generics::PrivTr<generics::Priv<()>>` is more private than the item `Tr5::required::{anon_assoc#0}`
339+
--> $DIR/private-in-public-warn.rs:94:26
340+
|
341+
LL | fn required() -> impl PrivTr<Priv<()>>;
342+
| ^^^^^^^^^^^^^^^^^^^^^ opaque type `Tr5::required::{anon_assoc#0}` is reachable at visibility `pub(crate)`
343+
|
344+
note: but trait `generics::PrivTr<generics::Priv<()>>` is only usable at visibility `pub(self)`
345+
--> $DIR/private-in-public-warn.rs:83:5
346+
|
347+
LL | trait PrivTr<T> {}
348+
| ^^^^^^^^^^^^^^^
349+
350+
error: type `generics::Priv<()>` is more private than the item `Tr5::required::{anon_assoc#0}`
351+
--> $DIR/private-in-public-warn.rs:94:26
352+
|
353+
LL | fn required() -> impl PrivTr<Priv<()>>;
354+
| ^^^^^^^^^^^^^^^^^^^^^ opaque type `Tr5::required::{anon_assoc#0}` is reachable at visibility `pub(crate)`
355+
|
356+
note: but type `generics::Priv<()>` is only usable at visibility `pub(self)`
357+
--> $DIR/private-in-public-warn.rs:81:5
358+
|
359+
LL | struct Priv<T = u8>(T);
360+
| ^^^^^^^^^^^^^^^^^^^
361+
362+
error[E0446]: private trait `generics::PrivTr<generics::Priv<()>>` in public interface
363+
--> $DIR/private-in-public-warn.rs:97:26
364+
|
365+
LL | trait PrivTr<T> {}
366+
| --------------- `generics::PrivTr<generics::Priv<()>>` declared as private
367+
...
368+
LL | fn provided() -> impl PrivTr<Priv<()>> {}
369+
| ^^^^^^^^^^^^^^^^^^^^^ can't leak private trait
370+
371+
error[E0446]: private type `generics::Priv<()>` in public interface
372+
--> $DIR/private-in-public-warn.rs:97:26
373+
|
374+
LL | struct Priv<T = u8>(T);
375+
| ------------------- `generics::Priv<()>` declared as private
376+
...
377+
LL | fn provided() -> impl PrivTr<Priv<()>> {}
378+
| ^^^^^^^^^^^^^^^^^^^^^ can't leak private type
379+
380+
error: trait `generics::PrivTr<generics::Priv<()>>` is more private than the item `Tr5::provided::{anon_assoc#0}`
381+
--> $DIR/private-in-public-warn.rs:97:26
382+
|
383+
LL | fn provided() -> impl PrivTr<Priv<()>> {}
384+
| ^^^^^^^^^^^^^^^^^^^^^ opaque type `Tr5::provided::{anon_assoc#0}` is reachable at visibility `pub(crate)`
385+
|
386+
note: but trait `generics::PrivTr<generics::Priv<()>>` is only usable at visibility `pub(self)`
387+
--> $DIR/private-in-public-warn.rs:83:5
388+
|
389+
LL | trait PrivTr<T> {}
390+
| ^^^^^^^^^^^^^^^
391+
392+
error: type `generics::Priv<()>` is more private than the item `Tr5::provided::{anon_assoc#0}`
393+
--> $DIR/private-in-public-warn.rs:97:26
394+
|
395+
LL | fn provided() -> impl PrivTr<Priv<()>> {}
396+
| ^^^^^^^^^^^^^^^^^^^^^ opaque type `Tr5::provided::{anon_assoc#0}` is reachable at visibility `pub(crate)`
397+
|
398+
note: but type `generics::Priv<()>` is only usable at visibility `pub(self)`
399+
--> $DIR/private-in-public-warn.rs:81:5
301400
|
302401
LL | struct Priv<T = u8>(T);
303402
| ^^^^^^^^^^^^^^^^^^^
304403

305404
error[E0446]: private type `impls::Priv` in public interface
306-
--> $DIR/private-in-public-warn.rs:119:9
405+
--> $DIR/private-in-public-warn.rs:128:9
307406
|
308407
LL | struct Priv;
309408
| ----------- `impls::Priv` declared as private
@@ -312,19 +411,19 @@ LL | type Alias = Priv;
312411
| ^^^^^^^^^^ can't leak private type
313412

314413
error: type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f`
315-
--> $DIR/private-in-public-warn.rs:190:9
414+
--> $DIR/private-in-public-warn.rs:199:9
316415
|
317416
LL | pub fn f(arg: Priv) {}
318417
| ^^^^^^^^^^^^^^^^^^^ associated function `aliases_pub::<impl Pub2>::f` is reachable at visibility `pub(crate)`
319418
|
320419
note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)`
321-
--> $DIR/private-in-public-warn.rs:163:5
420+
--> $DIR/private-in-public-warn.rs:172:5
322421
|
323422
LL | struct Priv;
324423
| ^^^^^^^^^^^
325424

326425
error[E0446]: private type `aliases_pub::Priv` in public interface
327-
--> $DIR/private-in-public-warn.rs:193:9
426+
--> $DIR/private-in-public-warn.rs:202:9
328427
|
329428
LL | struct Priv;
330429
| ----------- `aliases_pub::Priv` declared as private
@@ -333,7 +432,7 @@ LL | type Check = Priv;
333432
| ^^^^^^^^^^ can't leak private type
334433

335434
error[E0446]: private type `aliases_pub::Priv` in public interface
336-
--> $DIR/private-in-public-warn.rs:196:9
435+
--> $DIR/private-in-public-warn.rs:205:9
337436
|
338437
LL | struct Priv;
339438
| ----------- `aliases_pub::Priv` declared as private
@@ -342,7 +441,7 @@ LL | type Check = Priv;
342441
| ^^^^^^^^^^ can't leak private type
343442

344443
error[E0446]: private type `aliases_pub::Priv` in public interface
345-
--> $DIR/private-in-public-warn.rs:199:9
444+
--> $DIR/private-in-public-warn.rs:208:9
346445
|
347446
LL | struct Priv;
348447
| ----------- `aliases_pub::Priv` declared as private
@@ -351,7 +450,7 @@ LL | type Check = Priv;
351450
| ^^^^^^^^^^ can't leak private type
352451

353452
error[E0446]: private type `aliases_pub::Priv` in public interface
354-
--> $DIR/private-in-public-warn.rs:202:9
453+
--> $DIR/private-in-public-warn.rs:211:9
355454
|
356455
LL | struct Priv;
357456
| ----------- `aliases_pub::Priv` declared as private
@@ -360,37 +459,37 @@ LL | type Check = Priv;
360459
| ^^^^^^^^^^ can't leak private type
361460

362461
error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1`
363-
--> $DIR/private-in-public-warn.rs:232:5
462+
--> $DIR/private-in-public-warn.rs:241:5
364463
|
365464
LL | pub trait Tr1: PrivUseAliasTr {}
366465
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr1` is reachable at visibility `pub(crate)`
367466
|
368467
note: but trait `PrivTr1` is only usable at visibility `pub(self)`
369-
--> $DIR/private-in-public-warn.rs:218:5
468+
--> $DIR/private-in-public-warn.rs:227:5
370469
|
371470
LL | trait PrivTr1<T = u8> {
372471
| ^^^^^^^^^^^^^^^^^^^^^
373472

374473
error: trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2`
375-
--> $DIR/private-in-public-warn.rs:234:5
474+
--> $DIR/private-in-public-warn.rs:243:5
376475
|
377476
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
378477
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
379478
|
380479
note: but trait `PrivTr1<Priv2>` is only usable at visibility `pub(self)`
381-
--> $DIR/private-in-public-warn.rs:218:5
480+
--> $DIR/private-in-public-warn.rs:227:5
382481
|
383482
LL | trait PrivTr1<T = u8> {
384483
| ^^^^^^^^^^^^^^^^^^^^^
385484

386485
error: type `Priv2` is more private than the item `aliases_priv::Tr2`
387-
--> $DIR/private-in-public-warn.rs:234:5
486+
--> $DIR/private-in-public-warn.rs:243:5
388487
|
389488
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
390489
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
391490
|
392491
note: but type `Priv2` is only usable at visibility `pub(self)`
393-
--> $DIR/private-in-public-warn.rs:216:5
492+
--> $DIR/private-in-public-warn.rs:225:5
394493
|
395494
LL | struct Priv2;
396495
| ^^^^^^^^^^^^
@@ -410,7 +509,7 @@ LL | pub type Alias<T: PrivTr> = T;
410509
= note: `#[warn(type_alias_bounds)]` on by default
411510

412511
warning: where clauses on type aliases are not enforced
413-
--> $DIR/private-in-public-warn.rs:63:29
512+
--> $DIR/private-in-public-warn.rs:66:29
414513
|
415514
LL | pub type Alias<T> where T: PrivTr = T;
416515
| ------^^^^^^^^^
@@ -422,6 +521,6 @@ LL | pub type Alias<T> where T: PrivTr = T;
422521
see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
423522
= help: add `#![feature(lazy_type_alias)]` to the crate attributes to enable the desired semantics
424523

425-
error: aborting due to 34 previous errors; 2 warnings emitted
524+
error: aborting due to 43 previous errors; 2 warnings emitted
426525

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

tests/ui/privacy/pub-priv-dep/pub-priv1.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,11 @@ pub trait MyPubTrait {
7474
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
7575

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

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

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

0 commit comments

Comments
 (0)