]> git.lizzy.rs Git - rust.git/blob - src/test/ui/privacy/privacy1.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[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: method `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: method `bar` is private
96     bar::A.foo2();
97 }
98
99 mod foo {
100     fn test() {
101         ::bar::A::foo();
102         ::bar::A::bar();        //~ ERROR: method `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: method `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: method `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
135         foo();
136         bar();
137     }
138
139     fn test3() {
140         use bar::baz;
141         //~^ ERROR: module `baz` is private
142     }
143
144     fn test4() {
145         use bar::{foo, bar};
146         foo();
147         bar();
148     }
149
150     fn test5() {
151         use bar;
152         bar::foo();
153         bar::bar();
154     }
155
156     impl ::bar::B for f32 { fn foo() -> f32 { 1.0 } }
157     //~^ ERROR: trait `B` is private
158 }
159
160 pub mod mytest {
161     // Even though the inner `A` struct is a publicly exported item (usable from
162     // external crates through `foo::foo`, it should not be accessible through
163     // its definition path (which has the private `i` module).
164     use self::foo::i::A; //~ ERROR: module `i` is private
165
166     pub mod foo {
167         pub use self::i::A as foo;
168
169         mod i {
170             pub struct A;
171         }
172     }
173 }
174
175 #[start] fn main(_: isize, _: *const *const u8) -> isize { 3 }