]> git.lizzy.rs Git - rust.git/blob - tests/ui/privacy/where-priv-type.rs
Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, r=cuviper
[rust.git] / tests / ui / privacy / where-priv-type.rs
1 // priv-in-pub lint tests where the private type appears in the
2 // `where` clause of a public item
3
4 #![crate_type = "lib"]
5 #![feature(generic_const_exprs)]
6 #![allow(incomplete_features)]
7
8
9 struct PrivTy;
10 trait PrivTr {}
11 pub struct PubTy;
12 pub struct PubTyGeneric<T>(T);
13 pub trait PubTr {}
14 impl PubTr for PrivTy {}
15 pub trait PubTrWithAssocTy { type AssocTy; }
16 impl PubTrWithAssocTy for PrivTy { type AssocTy = PrivTy; }
17
18
19 pub struct S
20 //~^ WARNING private type `PrivTy` in public interface
21 //~| WARNING hard error
22 where
23     PrivTy:
24 {}
25
26
27 pub enum E
28 //~^ WARNING private type `PrivTy` in public interface
29 //~| WARNING hard error
30 where
31     PrivTy:
32 {}
33
34
35 pub fn f()
36 //~^ WARNING private type `PrivTy` in public interface
37 //~| WARNING hard error
38 where
39     PrivTy:
40 {}
41
42
43 impl S
44 //~^ ERROR private type `PrivTy` in public interface
45 where
46     PrivTy:
47 {
48     pub fn f()
49     //~^ WARNING private type `PrivTy` in public interface
50     //~| WARNING hard error
51     where
52         PrivTy:
53     {}
54 }
55
56
57 impl PubTr for PubTy
58 where
59     PrivTy:
60 {}
61
62
63 impl<T> PubTr for PubTyGeneric<T>
64 where
65     T: PubTrWithAssocTy<AssocTy=PrivTy>
66 {}
67
68
69 pub struct Const<const U: u8>;
70
71 pub trait Trait {
72     type AssocTy;
73     fn assoc_fn() -> Self::AssocTy;
74 }
75
76 impl<const U: u8> Trait for Const<U>
77 where
78     Const<{ my_const_fn(U) }>: ,
79 {
80     type AssocTy = Const<{ my_const_fn(U) }>;
81     //~^ ERROR private type
82     fn assoc_fn() -> Self::AssocTy {
83         Const
84     }
85 }
86
87 const fn my_const_fn(val: u8) -> u8 {
88     // body of this function doesn't matter
89     val
90 }