Skip to content

Commit caffeda

Browse files
committed
---
yaml --- r: 277170 b: refs/heads/try c: e14504a h: refs/heads/master
1 parent 50671c1 commit caffeda

File tree

7 files changed

+206
-1
lines changed

7 files changed

+206
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: daec3fe4e6bd4af52e551c1e09ae345a80b42452
4+
refs/heads/try: e14504a113b55c09686a5986c51bbdd6ae9c5da4
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
#![feature(pub_restricted)]
12+
13+
pub(crate) struct Crate;
14+
#[derive(Default)]
15+
pub struct Universe {
16+
pub x: i32,
17+
pub(crate) y: i32
18+
}
19+
20+
impl Universe {
21+
pub fn f(&self) {}
22+
pub(crate) fn g(&self) {}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
pub(crate) //~ ERROR experimental
12+
mod foo {}
13+
14+
pub(self) //~ ERROR experimental
15+
mod bar {}
16+
17+
struct S {
18+
pub(self) x: i32, //~ ERROR experimental
19+
}
20+
impl S {
21+
pub(self) fn f() {} //~ ERROR experimental
22+
}
23+
extern {
24+
pub(self) fn f(); //~ ERROR experimental
25+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#![feature(rustc_attrs, pub_restricted)]
12+
#![allow(warnings)]
13+
14+
mod foo {
15+
pub use foo::bar::S;
16+
mod bar {
17+
#[derive(Default)]
18+
pub struct S {
19+
pub(foo) x: i32,
20+
}
21+
impl S {
22+
pub(foo) fn f(&self) -> i32 { 0 }
23+
}
24+
25+
pub struct S2 {
26+
pub(crate) x: bool,
27+
}
28+
impl S2 {
29+
pub(crate) fn f(&self) -> bool { false }
30+
}
31+
32+
impl ::std::ops::Deref for S {
33+
type Target = S2;
34+
fn deref(&self) -> &S2 { unimplemented!() }
35+
}
36+
}
37+
}
38+
39+
#[rustc_error]
40+
fn main() { //~ ERROR compilation successful
41+
let s = foo::S::default();
42+
let _: bool = s.x;
43+
let _: bool = s.f();
44+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
#![feature(pub_restricted)]
12+
13+
mod foo {
14+
struct Priv;
15+
mod bar {
16+
use foo::Priv;
17+
pub(super) fn f(_: Priv) {}
18+
pub(crate) fn f(_: Priv) {} //~ ERROR private
19+
}
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
#![feature(pub_restricted)]
12+
#![deny(private_in_public)]
13+
#![allow(warnings)]
14+
15+
mod foo {
16+
pub mod bar {
17+
pub struct S {
18+
pub(foo) x: i32,
19+
}
20+
}
21+
22+
fn f() {
23+
use foo::bar::S;
24+
S { x: 0 }; // ok
25+
}
26+
}
27+
28+
fn main() {
29+
use foo::bar::S;
30+
S { x: 0 }; //~ ERROR private
31+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)