Skip to content

Commit c004a96

Browse files
committed
Do not check privacy for RPITIT.
1 parent 247d4f4 commit c004a96

File tree

5 files changed

+56
-179
lines changed

5 files changed

+56
-179
lines changed

compiler/rustc_privacy/src/lib.rs

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

16261626
for assoc_item in tcx.associated_items(id.owner_id).in_definition_order() {
1627+
if assoc_item.is_impl_trait_in_trait() {
1628+
continue;
1629+
}
1630+
16271631
self.check_assoc_item(assoc_item, item_visibility, effective_vis);
16281632

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

17381742
for assoc_item in tcx.associated_items(id.owner_id).in_definition_order() {
1743+
if assoc_item.is_impl_trait_in_trait() {
1744+
continue;
1745+
}
1746+
17391747
let impl_item_vis = if !of_trait {
17401748
min(tcx.local_visibility(assoc_item.def_id.expect_local()), impl_vis, tcx)
17411749
} else {

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ 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}`
5352
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}`
5653
}
5754
impl<T: PrivTr> Pub<T> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
5855
impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
@@ -92,13 +89,7 @@ mod generics {
9289

9390
pub trait Tr5 {
9491
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}`
9792
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}`
10293
}
10394
}
10495

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

Lines changed: 32 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -194,41 +194,8 @@ 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-
230197
error: trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
231-
--> $DIR/private-in-public-warn.rs:57:5
198+
--> $DIR/private-in-public-warn.rs:54:5
232199
|
233200
LL | impl<T: PrivTr> Pub<T> {}
234201
| ^^^^^^^^^^^^^^^^^^^^^^ implementation `traits::Pub<T>` is reachable at visibility `pub(crate)`
@@ -240,169 +207,103 @@ LL | trait PrivTr {}
240207
| ^^^^^^^^^^^^
241208

242209
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Alias`
243-
--> $DIR/private-in-public-warn.rs:66:5
210+
--> $DIR/private-in-public-warn.rs:63:5
244211
|
245212
LL | pub type Alias<T> where T: PrivTr = T;
246213
| ^^^^^^^^^^^^^^^^^ type alias `traits_where::Alias` is reachable at visibility `pub(crate)`
247214
|
248215
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
249-
--> $DIR/private-in-public-warn.rs:62:5
216+
--> $DIR/private-in-public-warn.rs:59:5
250217
|
251218
LL | trait PrivTr {}
252219
| ^^^^^^^^^^^^
253220

254221
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2`
255-
--> $DIR/private-in-public-warn.rs:69:5
222+
--> $DIR/private-in-public-warn.rs:66:5
256223
|
257224
LL | pub trait Tr2<T> where T: PrivTr {}
258225
| ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)`
259226
|
260227
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
261-
--> $DIR/private-in-public-warn.rs:62:5
228+
--> $DIR/private-in-public-warn.rs:59:5
262229
|
263230
LL | trait PrivTr {}
264231
| ^^^^^^^^^^^^
265232

266233
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr3::f`
267-
--> $DIR/private-in-public-warn.rs:72:9
234+
--> $DIR/private-in-public-warn.rs:69:9
268235
|
269236
LL | fn f<T>(arg: T) where T: PrivTr {}
270237
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated function `traits_where::Tr3::f` is reachable at visibility `pub(crate)`
271238
|
272239
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
273-
--> $DIR/private-in-public-warn.rs:62:5
240+
--> $DIR/private-in-public-warn.rs:59:5
274241
|
275242
LL | trait PrivTr {}
276243
| ^^^^^^^^^^^^
277244

278245
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
279-
--> $DIR/private-in-public-warn.rs:75:5
246+
--> $DIR/private-in-public-warn.rs:72:5
280247
|
281248
LL | impl<T> Pub<T> where T: PrivTr {}
282249
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)`
283250
|
284251
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
285-
--> $DIR/private-in-public-warn.rs:62:5
252+
--> $DIR/private-in-public-warn.rs:59:5
286253
|
287254
LL | trait PrivTr {}
288255
| ^^^^^^^^^^^^
289256

290257
error: trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
291-
--> $DIR/private-in-public-warn.rs:87:5
258+
--> $DIR/private-in-public-warn.rs:84:5
292259
|
293260
LL | pub trait Tr1: PrivTr<Pub> {}
294261
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)`
295262
|
296263
note: but trait `generics::PrivTr<generics::Pub>` is only usable at visibility `pub(self)`
297-
--> $DIR/private-in-public-warn.rs:83:5
264+
--> $DIR/private-in-public-warn.rs:80:5
298265
|
299266
LL | trait PrivTr<T> {}
300267
| ^^^^^^^^^^^^^^^
301268

302269
error: type `generics::Priv` is more private than the item `generics::Tr2`
303-
--> $DIR/private-in-public-warn.rs:89:5
270+
--> $DIR/private-in-public-warn.rs:86:5
304271
|
305272
LL | pub trait Tr2: PubTr<Priv> {}
306273
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr2` is reachable at visibility `pub(crate)`
307274
|
308275
note: but type `generics::Priv` is only usable at visibility `pub(self)`
309-
--> $DIR/private-in-public-warn.rs:81:5
276+
--> $DIR/private-in-public-warn.rs:78:5
310277
|
311278
LL | struct Priv<T = u8>(T);
312279
| ^^^^^^^^^^^^^^^^^^^
313280

314281
error: type `generics::Priv` is more private than the item `generics::Tr3`
315-
--> $DIR/private-in-public-warn.rs:90:5
282+
--> $DIR/private-in-public-warn.rs:87:5
316283
|
317284
LL | pub trait Tr3: PubTr<[Priv; 1]> {}
318285
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr3` is reachable at visibility `pub(crate)`
319286
|
320287
note: but type `generics::Priv` is only usable at visibility `pub(self)`
321-
--> $DIR/private-in-public-warn.rs:81:5
288+
--> $DIR/private-in-public-warn.rs:78:5
322289
|
323290
LL | struct Priv<T = u8>(T);
324291
| ^^^^^^^^^^^^^^^^^^^
325292

326293
error: type `generics::Priv` is more private than the item `Tr4`
327-
--> $DIR/private-in-public-warn.rs:91:5
294+
--> $DIR/private-in-public-warn.rs:88:5
328295
|
329296
LL | pub trait Tr4: PubTr<Pub<Priv>> {}
330297
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `Tr4` is reachable at visibility `pub(crate)`
331298
|
332299
note: but type `generics::Priv` is only usable at visibility `pub(self)`
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
300+
--> $DIR/private-in-public-warn.rs:78:5
400301
|
401302
LL | struct Priv<T = u8>(T);
402303
| ^^^^^^^^^^^^^^^^^^^
403304

404305
error[E0446]: private type `impls::Priv` in public interface
405-
--> $DIR/private-in-public-warn.rs:128:9
306+
--> $DIR/private-in-public-warn.rs:119:9
406307
|
407308
LL | struct Priv;
408309
| ----------- `impls::Priv` declared as private
@@ -411,19 +312,19 @@ LL | type Alias = Priv;
411312
| ^^^^^^^^^^ can't leak private type
412313

413314
error: type `aliases_pub::Priv` is more private than the item `aliases_pub::<impl Pub2>::f`
414-
--> $DIR/private-in-public-warn.rs:199:9
315+
--> $DIR/private-in-public-warn.rs:190:9
415316
|
416317
LL | pub fn f(arg: Priv) {}
417318
| ^^^^^^^^^^^^^^^^^^^ associated function `aliases_pub::<impl Pub2>::f` is reachable at visibility `pub(crate)`
418319
|
419320
note: but type `aliases_pub::Priv` is only usable at visibility `pub(self)`
420-
--> $DIR/private-in-public-warn.rs:172:5
321+
--> $DIR/private-in-public-warn.rs:163:5
421322
|
422323
LL | struct Priv;
423324
| ^^^^^^^^^^^
424325

425326
error[E0446]: private type `aliases_pub::Priv` in public interface
426-
--> $DIR/private-in-public-warn.rs:202:9
327+
--> $DIR/private-in-public-warn.rs:193:9
427328
|
428329
LL | struct Priv;
429330
| ----------- `aliases_pub::Priv` declared as private
@@ -432,7 +333,7 @@ LL | type Check = Priv;
432333
| ^^^^^^^^^^ can't leak private type
433334

434335
error[E0446]: private type `aliases_pub::Priv` in public interface
435-
--> $DIR/private-in-public-warn.rs:205:9
336+
--> $DIR/private-in-public-warn.rs:196:9
436337
|
437338
LL | struct Priv;
438339
| ----------- `aliases_pub::Priv` declared as private
@@ -441,7 +342,7 @@ LL | type Check = Priv;
441342
| ^^^^^^^^^^ can't leak private type
442343

443344
error[E0446]: private type `aliases_pub::Priv` in public interface
444-
--> $DIR/private-in-public-warn.rs:208:9
345+
--> $DIR/private-in-public-warn.rs:199:9
445346
|
446347
LL | struct Priv;
447348
| ----------- `aliases_pub::Priv` declared as private
@@ -450,7 +351,7 @@ LL | type Check = Priv;
450351
| ^^^^^^^^^^ can't leak private type
451352

452353
error[E0446]: private type `aliases_pub::Priv` in public interface
453-
--> $DIR/private-in-public-warn.rs:211:9
354+
--> $DIR/private-in-public-warn.rs:202:9
454355
|
455356
LL | struct Priv;
456357
| ----------- `aliases_pub::Priv` declared as private
@@ -459,37 +360,37 @@ LL | type Check = Priv;
459360
| ^^^^^^^^^^ can't leak private type
460361

461362
error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1`
462-
--> $DIR/private-in-public-warn.rs:241:5
363+
--> $DIR/private-in-public-warn.rs:232:5
463364
|
464365
LL | pub trait Tr1: PrivUseAliasTr {}
465366
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr1` is reachable at visibility `pub(crate)`
466367
|
467368
note: but trait `PrivTr1` is only usable at visibility `pub(self)`
468-
--> $DIR/private-in-public-warn.rs:227:5
369+
--> $DIR/private-in-public-warn.rs:218:5
469370
|
470371
LL | trait PrivTr1<T = u8> {
471372
| ^^^^^^^^^^^^^^^^^^^^^
472373

473374
error: trait `PrivTr1<Priv2>` is more private than the item `aliases_priv::Tr2`
474-
--> $DIR/private-in-public-warn.rs:243:5
375+
--> $DIR/private-in-public-warn.rs:234:5
475376
|
476377
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
477378
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
478379
|
479380
note: but trait `PrivTr1<Priv2>` is only usable at visibility `pub(self)`
480-
--> $DIR/private-in-public-warn.rs:227:5
381+
--> $DIR/private-in-public-warn.rs:218:5
481382
|
482383
LL | trait PrivTr1<T = u8> {
483384
| ^^^^^^^^^^^^^^^^^^^^^
484385

485386
error: type `Priv2` is more private than the item `aliases_priv::Tr2`
486-
--> $DIR/private-in-public-warn.rs:243:5
387+
--> $DIR/private-in-public-warn.rs:234:5
487388
|
488389
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
489390
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
490391
|
491392
note: but type `Priv2` is only usable at visibility `pub(self)`
492-
--> $DIR/private-in-public-warn.rs:225:5
393+
--> $DIR/private-in-public-warn.rs:216:5
493394
|
494395
LL | struct Priv2;
495396
| ^^^^^^^^^^^^
@@ -509,7 +410,7 @@ LL | pub type Alias<T: PrivTr> = T;
509410
= note: `#[warn(type_alias_bounds)]` on by default
510411

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

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

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

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

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

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

5251
fn provided() -> impl OtherTrait { OtherType }
53-
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
54-
//~| ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
5552
}
5653

5754
pub trait WithSuperTrait: OtherTrait {}

0 commit comments

Comments
 (0)