]> git.lizzy.rs Git - rust.git/blob - src/test/ui/privacy/privacy1.rs
Rollup merge of #70038 - DutchGhost:const-forget-tests, r=RalfJung
[rust.git] / src / test / ui / privacy / privacy1.rs
1 #![feature(lang_items, start, no_core)]
2 #![no_core] // makes debugging this test *a lot* easier (during resolve)
3
4 #[lang="sized"]
5 pub trait Sized {}
6
7 #[lang="copy"]
8 pub trait Copy {}
9
10 #[lang="deref"]
11 pub trait Deref {
12     type Target;
13 }
14
15 #[lang="receiver"]
16 pub trait Receiver: Deref {}
17
18 impl<'a, T> Deref for &'a T {
19     type Target = T;
20 }
21
22 impl<'a, T> Receiver for &'a T {}
23
24 mod bar {
25     // shouldn't bring in too much
26     pub use self::glob::*;
27
28     // can't publicly re-export private items
29     pub use self::baz::{foo, bar};
30
31     pub struct A;
32     impl A {
33         pub fn foo() {}
34         fn bar() {}
35
36         pub fn foo2(&self) {}
37         fn bar2(&self) {}
38     }
39
40     trait B {
41         fn foo() -> Self;
42     }
43
44     impl B for isize { fn foo() -> isize { 3 } }
45
46     pub enum Enum {
47         Pub
48     }
49
50     mod baz {
51         pub struct A;
52         impl A {
53             pub fn foo() {}
54             fn bar() {}
55
56             pub fn foo2(&self) {}
57             fn bar2(&self) {}
58         }
59
60         pub fn foo() {}
61         pub fn bar() {}
62     }
63
64     extern {
65         fn epriv();
66         pub fn epub();
67     }
68
69     fn test() {
70         self::Enum::Pub;
71         unsafe {
72             epriv();
73             epub();
74         }
75         self::baz::A;
76         self::baz::A::foo();
77         self::baz::A::bar(); //~ ERROR: associated function `bar` is private
78         self::baz::A.foo2();
79
80         // this used to cause an ICE in privacy traversal.
81         super::gpub();
82     }
83
84     mod glob {
85         pub fn gpub() {}
86         fn gpriv() {}
87     }
88 }
89
90 pub fn gpub() {}
91
92 fn lol() {
93     bar::A;
94     bar::A::foo();
95     bar::A::bar(); //~ ERROR: associated function `bar` is private
96     bar::A.foo2();
97 }
98
99 mod foo {
100     fn test() {
101         ::bar::A::foo();
102         ::bar::A::bar();        //~ ERROR: associated function `bar` is private
103         ::bar::A.foo2();
104         ::bar::baz::A::foo();   //~ ERROR: module `baz` is private
105         ::bar::baz::A::bar();   //~ ERROR: module `baz` is private
106                                 //~^ ERROR: associated function `bar` is private
107         ::bar::baz::A.foo2();   //~ ERROR: module `baz` is private
108         ::bar::baz::A.bar2();   //~ ERROR: module `baz` is private
109                                 //~^ ERROR: associated function `bar2` is private
110
111         let _: isize =
112         ::bar::B::foo();        //~ ERROR: trait `B` is private
113         ::lol();
114
115         ::bar::Enum::Pub;
116
117         unsafe {
118             ::bar::epriv(); //~ ERROR: function `epriv` is private
119             ::bar::epub();
120         }
121
122         ::bar::foo();
123         ::bar::bar();
124
125         ::bar::gpub();
126
127         ::bar::baz::foo(); //~ ERROR: module `baz` is private
128         ::bar::baz::bar(); //~ ERROR: module `baz` is private
129     }
130
131     fn test2() {
132         use bar::baz::{foo, bar};
133         //~^ ERROR: module `baz` is private
134         //~| ERROR: module `baz` is private
135
136         foo();
137         bar();
138     }
139
140     fn test3() {
141         use bar::baz;
142         //~^ ERROR: module `baz` is private
143     }
144
145     fn test4() {
146         use bar::{foo, bar};
147         foo();
148         bar();
149     }
150
151     fn test5() {
152         use bar;
153         bar::foo();
154         bar::bar();
155     }
156
157     impl ::bar::B for f32 { fn foo() -> f32 { 1.0 } }
158     //~^ ERROR: trait `B` is private
159 }
160
161 pub mod mytest {
162     // Even though the inner `A` struct is a publicly exported item (usable from
163     // external crates through `foo::foo`, it should not be accessible through
164     // its definition path (which has the private `i` module).
165     use self::foo::i::A; //~ ERROR: module `i` is private
166
167     pub mod foo {
168         pub use self::i::A as foo;
169
170         mod i {
171             pub struct A;
172         }
173     }
174 }
175
176 #[start] fn main(_: isize, _: *const *const u8) -> isize { 3 }