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