]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/privacy/restricted/test.rs
Reexport -> re-export in error messages
[rust.git] / src / test / compile-fail / privacy / restricted / test.rs
1 // Copyright 2016 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 // aux-build:pub_restricted.rs
12
13 #![allow(warnings)]
14 extern crate pub_restricted;
15
16 mod foo {
17     pub mod bar {
18         pub(super) fn f() {}
19         #[derive(Default)]
20         pub struct S {
21             pub(super) x: i32,
22         }
23         impl S {
24             pub(super) fn f(&self) {}
25             pub(super) fn g() {}
26         }
27     }
28     fn f() {
29         use foo::bar::S;
30         pub(self) use foo::bar::f; // ok
31         pub(super) use foo::bar::f as g; //~ ERROR cannot be re-exported
32         S::default().x; // ok
33         S::default().f(); // ok
34         S::g(); // ok
35     }
36 }
37
38 fn f() {
39     use foo::bar::S;
40     use foo::bar::f; //~ ERROR private
41     S::default().x; //~ ERROR private
42     S::default().f(); //~ ERROR private
43     S::g(); //~ ERROR private
44 }
45
46 fn main() {
47     use pub_restricted::Universe;
48     use pub_restricted::Crate; //~ ERROR private
49
50     let u = Universe::default();
51     let _ = u.x;
52     let _ = u.y; //~ ERROR private
53     let _ = u.z; //~ ERROR private
54     u.f();
55     u.g(); //~ ERROR private
56     u.h(); //~ ERROR private
57 }
58
59 mod pathological {
60     pub(in bad::path) mod m1 {} //~ ERROR failed to resolve. Maybe a missing `extern crate bad;`?
61     pub(in foo) mod m2 {} //~ ERROR visibilities can only be restricted to ancestor modules
62 }