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