-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(pub_restricted)] | ||
|
||
pub(crate) struct Crate; | ||
#[derive(Default)] | ||
pub struct Universe { | ||
pub x: i32, | ||
pub(crate) y: i32 | ||
} | ||
|
||
impl Universe { | ||
pub fn f(&self) {} | ||
pub(crate) fn g(&self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
pub(crate) //~ ERROR experimental | ||
mod foo {} | ||
|
||
pub(self) //~ ERROR experimental | ||
mod bar {} | ||
|
||
struct S { | ||
pub(self) x: i32, //~ ERROR experimental | ||
} | ||
impl S { | ||
pub(self) fn f() {} //~ ERROR experimental | ||
} | ||
extern { | ||
pub(self) fn f(); //~ ERROR experimental | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/compile-fail/privacy/restricted/lookup-ignores-private.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(rustc_attrs, pub_restricted)] | ||
#![allow(warnings)] | ||
|
||
mod foo { | ||
pub use foo::bar::S; | ||
mod bar { | ||
#[derive(Default)] | ||
pub struct S { | ||
pub(foo) x: i32, | ||
} | ||
impl S { | ||
pub(foo) fn f(&self) -> i32 { 0 } | ||
} | ||
|
||
pub struct S2 { | ||
pub(crate) x: bool, | ||
} | ||
impl S2 { | ||
pub(crate) fn f(&self) -> bool { false } | ||
} | ||
|
||
impl ::std::ops::Deref for S { | ||
type Target = S2; | ||
fn deref(&self) -> &S2 { unimplemented!() } | ||
} | ||
} | ||
} | ||
|
||
#[rustc_error] | ||
fn main() { //~ ERROR compilation successful | ||
let s = foo::S::default(); | ||
let _: bool = s.x; | ||
let _: bool = s.f(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/compile-fail/privacy/restricted/private-in-public.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(pub_restricted)] | ||
|
||
mod foo { | ||
struct Priv; | ||
mod bar { | ||
use foo::Priv; | ||
pub(super) fn f(_: Priv) {} | ||
pub(crate) fn f(_: Priv) {} //~ ERROR private | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/compile-fail/privacy/restricted/struct-literal-field.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(pub_restricted)] | ||
#![deny(private_in_public)] | ||
#![allow(warnings)] | ||
|
||
mod foo { | ||
pub mod bar { | ||
pub struct S { | ||
pub(foo) x: i32, | ||
} | ||
} | ||
|
||
fn f() { | ||
use foo::bar::S; | ||
S { x: 0 }; // ok | ||
} | ||
} | ||
|
||
fn main() { | ||
use foo::bar::S; | ||
S { x: 0 }; //~ ERROR private | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:pub_restricted.rs | ||
|
||
#![feature(pub_restricted)] | ||
#![deny(private_in_public)] | ||
#![allow(warnings)] | ||
extern crate pub_restricted; | ||
|
||
mod foo { | ||
pub mod bar { | ||
pub(super) fn f() {} | ||
#[derive(Default)] | ||
pub struct S { | ||
pub(super) x: i32, | ||
} | ||
impl S { | ||
pub(super) fn f(&self) {} | ||
pub(super) fn g() {} | ||
} | ||
} | ||
fn f() { | ||
use foo::bar::S; | ||
pub(self) use foo::bar::f; // ok | ||
pub(super) use foo::bar::f as g; //~ ERROR cannot be reexported | ||
S::default().x; // ok | ||
S::default().f(); // ok | ||
S::g(); // ok | ||
} | ||
} | ||
|
||
fn f() { | ||
use foo::bar::S; | ||
use foo::bar::f; //~ ERROR private | ||
S::default().x; //~ ERROR private | ||
S::default().f(); //~ ERROR private | ||
S::g(); //~ ERROR private | ||
} | ||
|
||
fn main() { | ||
use pub_restricted::Universe; | ||
use pub_restricted::Crate; //~ ERROR private | ||
|
||
let u = Universe::default(); | ||
let _ = u.x; | ||
let _ = u.y; //~ ERROR private | ||
u.f(); | ||
u.g(); //~ ERROR private | ||
} | ||
|
||
mod pathological { | ||
pub(bad::path) mod m1 {} //~ ERROR failed to resolve module path | ||
pub(foo) mod m2 {} //~ ERROR visibilities can only be restricted to ancestor modules | ||
} |