summaryrefslogtreecommitdiffstats
path: root/tests/ui/privacy/associated-item-privacy-trait.rs
blob: f038ae9e261df1f60c6b0e45e9ef8f2d2f185e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#![feature(decl_macro, associated_type_defaults)]
#![allow(private_interfaces, private_bounds)]

mod priv_trait {
    trait PrivTr {
        fn method(&self) {}
        const CONST: u8 = 0;
        type AssocTy = u8;
    }
    pub struct Pub;
    impl PrivTr for Pub {}
    pub trait PubTr: PrivTr {}

    pub macro mac() {
        let value = <Pub as PrivTr>::method;
        //~^ ERROR type `for<'a> fn(&'a priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
        value;
        //~^ ERROR type `for<'a> fn(&'a priv_trait::Pub) {<priv_trait::Pub as PrivTr>::method}` is private
        Pub.method();
        //~^ ERROR type `for<'a> fn(&'a Self) {<Self as PrivTr>::method}` is private
        <Pub as PrivTr>::CONST;
        //~^ ERROR associated constant `PrivTr::CONST` is private
        let _: <Pub as PrivTr>::AssocTy;
        //~^ ERROR associated type `PrivTr::AssocTy` is private
        pub type InSignatureTy = <Pub as PrivTr>::AssocTy;
        //~^ ERROR associated type `PrivTr::AssocTy` is private
        pub trait InSignatureTr: PrivTr {}
        //~^ ERROR trait `PrivTr` is private
        impl PrivTr for u8 {}
        //~^ ERROR trait `PrivTr` is private
    }
}
fn priv_trait() {
    priv_trait::mac!();
}

mod priv_signature {
    pub trait PubTr {
        fn method(&self, arg: Priv) {}
    }
    struct Priv;
    pub struct Pub;
    impl PubTr for Pub {}

    pub macro mac() {
        let value = <Pub as PubTr>::method;
        //~^ ERROR type `priv_signature::Priv` is private
        value;
        //~^ ERROR type `priv_signature::Priv` is private
        Pub.method(loop {});
        //~^ ERROR type `priv_signature::Priv` is private
    }
}
fn priv_signature() {
    priv_signature::mac!();
}

mod priv_substs {
    pub trait PubTr {
        fn method<T>(&self) {}
    }
    struct Priv;
    pub struct Pub;
    impl PubTr for Pub {}

    pub macro mac() {
        let value = <Pub as PubTr>::method::<Priv>;
        //~^ ERROR type `priv_substs::Priv` is private
        value;
        //~^ ERROR type `priv_substs::Priv` is private
        Pub.method::<Priv>();
        //~^ ERROR type `priv_substs::Priv` is private
    }
}
fn priv_substs() {
    priv_substs::mac!();
}

mod priv_parent_substs {
    pub trait PubTr<T = Priv> {
        fn method(&self) {}
        const CONST: u8 = 0;
        type AssocTy = u8;
    }
    struct Priv;
    pub struct Pub;
    impl PubTr<Priv> for Pub {}
    impl PubTr<Pub> for Priv {}

    pub macro mac() {
        let value = <Pub as PubTr>::method;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        value;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        let value = <Pub as PubTr<_>>::method;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        value;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        Pub.method();
        //~^ ERROR type `priv_parent_substs::Priv` is private

        let value = <Priv as PubTr<_>>::method;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        value;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        Priv.method();
        //~^ ERROR type `priv_parent_substs::Priv` is private

        <Pub as PubTr>::CONST;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        <Pub as PubTr<_>>::CONST;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        <Priv as PubTr<_>>::CONST;
        //~^ ERROR type `priv_parent_substs::Priv` is private

        let _: <Pub as PubTr>::AssocTy; // FIXME no longer an error?!
        let _: <Pub as PubTr<_>>::AssocTy;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        let _: <Priv as PubTr<_>>::AssocTy;
        //~^ ERROR type `priv_parent_substs::Priv` is private

        pub type InSignatureTy1 = <Pub as PubTr>::AssocTy;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        pub type InSignatureTy2 = <Priv as PubTr<Pub>>::AssocTy;
        //~^ ERROR type `priv_parent_substs::Priv` is private
        impl PubTr for u8 {}
        //~^ ERROR type `priv_parent_substs::Priv` is private
    }
}
fn priv_parent_substs() {
    priv_parent_substs::mac!();
}

fn main() {}