|
| 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 | +#![feature(pub_restricted)] |
| 14 | +#![deny(private_in_public)] |
| 15 | +#![allow(warnings)] |
| 16 | +extern crate pub_restricted; |
| 17 | + |
| 18 | +mod foo { |
| 19 | + pub mod bar { |
| 20 | + pub(super) fn f() {} |
| 21 | + #[derive(Default)] |
| 22 | + pub struct S { |
| 23 | + pub(super) x: i32, |
| 24 | + } |
| 25 | + impl S { |
| 26 | + pub(super) fn f(&self) {} |
| 27 | + pub(super) fn g() {} |
| 28 | + } |
| 29 | + } |
| 30 | + fn f() { |
| 31 | + use foo::bar::S; |
| 32 | + pub(self) use foo::bar::f; // ok |
| 33 | + pub(super) use foo::bar::f as g; //~ ERROR cannot be reexported |
| 34 | + S::default().x; // ok |
| 35 | + S::default().f(); // ok |
| 36 | + S::g(); // ok |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +fn f() { |
| 41 | + use foo::bar::S; |
| 42 | + use foo::bar::f; //~ ERROR private |
| 43 | + S::default().x; //~ ERROR private |
| 44 | + S::default().f(); //~ ERROR private |
| 45 | + S::g(); //~ ERROR private |
| 46 | +} |
| 47 | + |
| 48 | +fn main() { |
| 49 | + use pub_restricted::Universe; |
| 50 | + use pub_restricted::Crate; //~ ERROR private |
| 51 | + |
| 52 | + let u = Universe::default(); |
| 53 | + let _ = u.x; |
| 54 | + let _ = u.y; //~ ERROR private |
| 55 | + u.f(); |
| 56 | + u.g(); //~ ERROR private |
| 57 | +} |
| 58 | + |
| 59 | +mod pathological { |
| 60 | + pub(bad::path) mod m1 {} //~ ERROR failed to resolve module path |
| 61 | + pub(foo) mod m2 {} //~ ERROR visibilities can only be restricted to ancestor modules |
| 62 | +} |
0 commit comments