Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4b94717

Browse files
Rollup merge of #144098 - cjgillot:lint-rpitit, r=compiler-errors
Do not lint private-in-public for RPITIT Fixes the hard error introduced by #143357 Instead of trying to accept this hard error directly, this PR copies tests from #144020 and removes the error. If the behaviour is actually desirable, the second commit can be reverted with a proper crater run. cc #143531 for bookkeeping r? `@compiler-errors`
2 parents 870d429 + c004a96 commit 4b94717

File tree

6 files changed

+77
-54
lines changed

6 files changed

+77
-54
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mod types {
3535

3636
mod traits {
3737
trait PrivTr {}
38+
impl PrivTr for () {}
3839
pub struct Pub<T>(T);
3940
pub trait PubTr {}
4041

@@ -45,7 +46,10 @@ mod traits {
4546
pub trait Tr3 {
4647
type Alias: PrivTr;
4748
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::Alias`
48-
fn f<T: PrivTr>(arg: T) {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
49+
fn f<T: PrivTr>(arg: T) {}
50+
//~^ ERROR trait `traits::PrivTr` is more private than the item `traits::Tr3::f`
51+
fn g() -> impl PrivTr;
52+
fn h() -> impl PrivTr {}
4953
}
5054
impl<T: PrivTr> Pub<T> {} //~ ERROR trait `traits::PrivTr` is more private than the item `traits::Pub<T>`
5155
impl<T: PrivTr> PubTr for Pub<T> {} // OK, trait impl predicates
@@ -75,12 +79,18 @@ mod generics {
7579
pub struct Pub<T = u8>(T);
7680
trait PrivTr<T> {}
7781
pub trait PubTr<T> {}
82+
impl PrivTr<Priv<()>> for () {}
7883

7984
pub trait Tr1: PrivTr<Pub> {}
8085
//~^ ERROR trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
8186
pub trait Tr2: PubTr<Priv> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr2`
8287
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR type `generics::Priv` is more private than the item `generics::Tr3`
8388
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR type `generics::Priv` is more private than the item `Tr4`
89+
90+
pub trait Tr5 {
91+
fn required() -> impl PrivTr<Priv<()>>;
92+
fn provided() -> impl PrivTr<Priv<()>> {}
93+
}
8494
}
8595

8696
mod impls {

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

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ LL | type Alias = Priv;
130130
| ^^^^^^^^^^ can't leak private type
131131

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

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

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

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

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

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

209209
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Alias`
210-
--> $DIR/private-in-public-warn.rs:59:5
210+
--> $DIR/private-in-public-warn.rs:63:5
211211
|
212212
LL | pub type Alias<T> where T: PrivTr = T;
213213
| ^^^^^^^^^^^^^^^^^ type alias `traits_where::Alias` is reachable at visibility `pub(crate)`
214214
|
215215
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
216-
--> $DIR/private-in-public-warn.rs:55:5
216+
--> $DIR/private-in-public-warn.rs:59:5
217217
|
218218
LL | trait PrivTr {}
219219
| ^^^^^^^^^^^^
220220

221221
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Tr2`
222-
--> $DIR/private-in-public-warn.rs:62:5
222+
--> $DIR/private-in-public-warn.rs:66:5
223223
|
224224
LL | pub trait Tr2<T> where T: PrivTr {}
225225
| ^^^^^^^^^^^^^^^^ trait `traits_where::Tr2` is reachable at visibility `pub(crate)`
226226
|
227227
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
228-
--> $DIR/private-in-public-warn.rs:55:5
228+
--> $DIR/private-in-public-warn.rs:59:5
229229
|
230230
LL | trait PrivTr {}
231231
| ^^^^^^^^^^^^
232232

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

245245
error: trait `traits_where::PrivTr` is more private than the item `traits_where::Pub<T>`
246-
--> $DIR/private-in-public-warn.rs:68:5
246+
--> $DIR/private-in-public-warn.rs:72:5
247247
|
248248
LL | impl<T> Pub<T> where T: PrivTr {}
249249
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation `traits_where::Pub<T>` is reachable at visibility `pub(crate)`
250250
|
251251
note: but trait `traits_where::PrivTr` is only usable at visibility `pub(self)`
252-
--> $DIR/private-in-public-warn.rs:55:5
252+
--> $DIR/private-in-public-warn.rs:59:5
253253
|
254254
LL | trait PrivTr {}
255255
| ^^^^^^^^^^^^
256256

257257
error: trait `generics::PrivTr<generics::Pub>` is more private than the item `generics::Tr1`
258-
--> $DIR/private-in-public-warn.rs:79:5
258+
--> $DIR/private-in-public-warn.rs:84:5
259259
|
260260
LL | pub trait Tr1: PrivTr<Pub> {}
261261
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `generics::Tr1` is reachable at visibility `pub(crate)`
262262
|
263263
note: but trait `generics::PrivTr<generics::Pub>` is only usable at visibility `pub(self)`
264-
--> $DIR/private-in-public-warn.rs:76:5
264+
--> $DIR/private-in-public-warn.rs:80:5
265265
|
266266
LL | trait PrivTr<T> {}
267267
| ^^^^^^^^^^^^^^^
268268

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

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

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

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

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

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

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

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

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

362362
error: trait `PrivTr1` is more private than the item `aliases_priv::Tr1`
363-
--> $DIR/private-in-public-warn.rs:222:5
363+
--> $DIR/private-in-public-warn.rs:232:5
364364
|
365365
LL | pub trait Tr1: PrivUseAliasTr {}
366366
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr1` is reachable at visibility `pub(crate)`
367367
|
368368
note: but trait `PrivTr1` is only usable at visibility `pub(self)`
369-
--> $DIR/private-in-public-warn.rs:208:5
369+
--> $DIR/private-in-public-warn.rs:218:5
370370
|
371371
LL | trait PrivTr1<T = u8> {
372372
| ^^^^^^^^^^^^^^^^^^^^^
373373

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

386386
error: type `Priv2` is more private than the item `aliases_priv::Tr2`
387-
--> $DIR/private-in-public-warn.rs:224:5
387+
--> $DIR/private-in-public-warn.rs:234:5
388388
|
389389
LL | pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
390390
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait `aliases_priv::Tr2` is reachable at visibility `pub(crate)`
391391
|
392392
note: but type `Priv2` is only usable at visibility `pub(self)`
393-
--> $DIR/private-in-public-warn.rs:206:5
393+
--> $DIR/private-in-public-warn.rs:216:5
394394
|
395395
LL | struct Priv2;
396396
| ^^^^^^^^^^^^
397397

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

412412
warning: where clauses on type aliases are not enforced
413-
--> $DIR/private-in-public-warn.rs:59:29
413+
--> $DIR/private-in-public-warn.rs:63:29
414414
|
415415
LL | pub type Alias<T> where T: PrivTr = T;
416416
| ------^^^^^^^^^

‎tests/ui/privacy/pub-priv-dep/auxiliary/priv_dep.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub struct OtherType;
22
pub trait OtherTrait {}
3+
impl OtherTrait for OtherType {}
34

45
#[macro_export]
56
macro_rules! m {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ impl PublicType {
4444

4545
pub trait MyPubTrait {
4646
type Foo: OtherTrait;
47+
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
48+
49+
fn required() -> impl OtherTrait;
50+
51+
fn provided() -> impl OtherTrait { OtherType }
4752
}
48-
//~^^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface
4953

5054
pub trait WithSuperTrait: OtherTrait {}
5155
//~^ ERROR trait `OtherTrait` from private dependency 'priv_dep' in public interface

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /