]> git.lizzy.rs Git - rust.git/blob - src/test/ui/privacy/associated-item-privacy-trait.rs
Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup
[rust.git] / src / test / ui / privacy / associated-item-privacy-trait.rs
1 // ignore-tidy-linelength
2
3 #![feature(decl_macro, associated_type_defaults)]
4 #![allow(unused, private_in_public)]
5
6 mod priv_trait {
7     trait PrivTr {
8         fn method(&self) {}
9         const CONST: u8 = 0;
10         type AssocTy = u8;
11     }
12     pub struct Pub;
13     impl PrivTr for Pub {}
14     pub trait PubTr: PrivTr {}
15
16     pub macro mac() {
17         let value = <Pub as PrivTr>::method;
18         //~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
19         value;
20         //~^ ERROR type `for<'r> fn(&'r priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
21         Pub.method();
22         //~^ ERROR type `for<'r> fn(&'r Self) {<Self as PrivTr>::method}` is private
23         <Pub as PrivTr>::CONST;
24         //~^ ERROR associated constant `<Pub as PrivTr>::CONST` is private
25         let _: <Pub as PrivTr>::AssocTy;
26         //~^ ERROR associated type `<Pub as PrivTr>::AssocTy` is private
27         pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
28         //~^ ERROR trait `PrivTr` is private
29         pub trait InSignatureTr: PrivTr {}
30         //~^ ERROR trait `PrivTr` is private
31         impl PrivTr for u8 {}
32         //~^ ERROR trait `PrivTr` is private
33     }
34 }
35 fn priv_trait() {
36     priv_trait::mac!();
37 }
38
39 mod priv_signature {
40     pub trait PubTr {
41         fn method(&self, arg: Priv) {}
42     }
43     struct Priv;
44     pub struct Pub;
45     impl PubTr for Pub {}
46
47     pub macro mac() {
48         let value = <Pub as PubTr>::method;
49         //~^ ERROR type `priv_signature::Priv` is private
50         value;
51         //~^ ERROR type `priv_signature::Priv` is private
52         Pub.method(loop {});
53         //~^ ERROR type `priv_signature::Priv` is private
54     }
55 }
56 fn priv_signature() {
57     priv_signature::mac!();
58 }
59
60 mod priv_substs {
61     pub trait PubTr {
62         fn method<T>(&self) {}
63     }
64     struct Priv;
65     pub struct Pub;
66     impl PubTr for Pub {}
67
68     pub macro mac() {
69         let value = <Pub as PubTr>::method::<Priv>;
70         //~^ ERROR type `priv_substs::Priv` is private
71         value;
72         //~^ ERROR type `priv_substs::Priv` is private
73         Pub.method::<Priv>();
74         //~^ ERROR type `priv_substs::Priv` is private
75     }
76 }
77 fn priv_substs() {
78     priv_substs::mac!();
79 }
80
81 mod priv_parent_substs {
82     pub trait PubTr<T = Priv> {
83         fn method(&self) {}
84         const CONST: u8 = 0;
85         type AssocTy = u8;
86     }
87     struct Priv;
88     pub struct Pub;
89     impl PubTr<Priv> for Pub {}
90     impl PubTr<Pub> for Priv {}
91
92     pub macro mac() {
93         let value = <Pub as PubTr>::method;
94         //~^ ERROR type `priv_parent_substs::Priv` is private
95         value;
96         //~^ ERROR type `priv_parent_substs::Priv` is private
97         let value = <Pub as PubTr<_>>::method;
98         //~^ ERROR type `priv_parent_substs::Priv` is private
99         value;
100         //~^ ERROR type `priv_parent_substs::Priv` is private
101         Pub.method();
102         //~^ ERROR type `priv_parent_substs::Priv` is private
103
104         let value = <Priv as PubTr<_>>::method;
105         //~^ ERROR type `priv_parent_substs::Priv` is private
106         value;
107         //~^ ERROR type `priv_parent_substs::Priv` is private
108         Priv.method();
109         //~^ ERROR type `priv_parent_substs::Priv` is private
110
111         <Pub as PubTr>::CONST;
112         //~^ ERROR type `priv_parent_substs::Priv` is private
113         <Pub as PubTr<_>>::CONST;
114         //~^ ERROR type `priv_parent_substs::Priv` is private
115         <Priv as PubTr<_>>::CONST;
116         //~^ ERROR type `priv_parent_substs::Priv` is private
117
118         let _: <Pub as PubTr>::AssocTy; // FIXME no longer an error?!
119         let _: <Pub as PubTr<_>>::AssocTy;
120         //~^ ERROR type `priv_parent_substs::Priv` is private
121         let _: <Priv as PubTr<_>>::AssocTy;
122         //~^ ERROR type `priv_parent_substs::Priv` is private
123
124         pub type InSignatureTy1 = <Pub as PubTr>::AssocTy;
125         //~^ ERROR type `priv_parent_substs::Priv` is private
126         pub type InSignatureTy2 = <Priv as PubTr<Pub>>::AssocTy;
127         //~^ ERROR type `priv_parent_substs::Priv` is private
128         impl PubTr for u8 {}
129         //~^ ERROR type `priv_parent_substs::Priv` is private
130     }
131 }
132 fn priv_parent_substs() {
133     priv_parent_substs::mac!();
134 }
135
136 fn main() {}