Skip to content

Commit

Permalink
auto merge of #13184 : alexcrichton/rust/priv-fields, r=brson
Browse files Browse the repository at this point in the history
This is an implementation of a portion of [RFC #4](https://github.com/rust-lang/rfcs/blob/master/active/0004-private-fields.md). This PR makes named struct fields private by default (as opposed to inherited by default).

The only real meaty change is the first commit to `rustc`, all other commits are just fallout of that change.

Summary of changes made:

* Named fields are private by default *everywhere*
* The `priv` keyword is now default-deny on named fields (done in a "lint" pass in privacy)

Changes yet to be done (before the RFC is closed)

* Change tuple structs to have private fields by default
* Remove `priv` enum variants
* Make `priv` a reserved keyword
  • Loading branch information
bors committed Mar 31, 2014
2 parents a7e057d + 37a3131 commit b8ef9fd
Show file tree
Hide file tree
Showing 278 changed files with 2,649 additions and 2,674 deletions.
56 changes: 28 additions & 28 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,87 +21,87 @@ pub enum mode {
#[deriving(Clone)]
pub struct config {
// The library paths required for running the compiler
compile_lib_path: ~str,
pub compile_lib_path: ~str,

// The library paths required for running compiled programs
run_lib_path: ~str,
pub run_lib_path: ~str,

// The rustc executable
rustc_path: Path,
pub rustc_path: Path,

// The clang executable
clang_path: Option<Path>,
pub clang_path: Option<Path>,

// The llvm binaries path
llvm_bin_path: Option<Path>,
pub llvm_bin_path: Option<Path>,

// The directory containing the tests to run
src_base: Path,
pub src_base: Path,

// The directory where programs should be built
build_base: Path,
pub build_base: Path,

// Directory for auxiliary libraries
aux_base: Path,
pub aux_base: Path,

// The name of the stage being built (stage1, etc)
stage_id: ~str,
pub stage_id: ~str,

// The test mode, compile-fail, run-fail, run-pass
mode: mode,
pub mode: mode,

// Run ignored tests
run_ignored: bool,
pub run_ignored: bool,

// Only run tests that match this filter
filter: Option<~str>,
pub filter: Option<~str>,

// Write out a parseable log of tests that were run
logfile: Option<Path>,
pub logfile: Option<Path>,

// Write out a json file containing any metrics of the run
save_metrics: Option<Path>,
pub save_metrics: Option<Path>,

// Write and ratchet a metrics file
ratchet_metrics: Option<Path>,
pub ratchet_metrics: Option<Path>,

// Percent change in metrics to consider noise
ratchet_noise_percent: Option<f64>,
pub ratchet_noise_percent: Option<f64>,

// "Shard" of the testsuite to run: this has the form of
// "Shard" of the testsuite to pub run: this has the form of
// two numbers (a,b), and causes only those tests with
// positional order equal to a mod b to run.
test_shard: Option<(uint,uint)>,
pub test_shard: Option<(uint,uint)>,

// A command line to prefix program execution with,
// for running under valgrind
runtool: Option<~str>,
pub runtool: Option<~str>,

// Flags to pass to the compiler when building for the host
host_rustcflags: Option<~str>,
pub host_rustcflags: Option<~str>,

// Flags to pass to the compiler when building for the target
target_rustcflags: Option<~str>,
pub target_rustcflags: Option<~str>,

// Run tests using the JIT
jit: bool,
pub jit: bool,

// Target system to be tested
target: ~str,
pub target: ~str,

// Host triple for the compiler being invoked
host: ~str,
pub host: ~str,

// Extra parameter to run adb on arm-linux-androideabi
adb_path: ~str,
pub adb_path: ~str,

// Extra parameter to run test sute on arm-linux-androideabi
adb_test_dir: ~str,
pub adb_test_dir: ~str,

// status whether android device available or not
adb_device_status: bool,
pub adb_device_status: bool,

// Explain what's going on
verbose: bool
pub verbose: bool

}
6 changes: 5 additions & 1 deletion src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

use std::io::{BufferedReader, File};

pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
pub struct ExpectedError {
pub line: uint,
pub kind: ~str,
pub msg: ~str,
}

// Load any test directives embedded in the file
pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
Expand Down
20 changes: 10 additions & 10 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ use util;

pub struct TestProps {
// Lines that should be expected, in order, on standard out
error_patterns: Vec<~str> ,
pub error_patterns: Vec<~str> ,
// Extra flags to pass to the compiler
compile_flags: Option<~str>,
pub compile_flags: Option<~str>,
// If present, the name of a file that this test should match when
// pretty-printed
pp_exact: Option<Path>,
pub pp_exact: Option<Path>,
// Modules from aux directory that should be compiled
aux_builds: Vec<~str> ,
pub aux_builds: Vec<~str> ,
// Environment settings to use during execution
exec_env: Vec<(~str,~str)> ,
pub exec_env: Vec<(~str,~str)> ,
// Commands to be given to the debugger, when testing debug info
debugger_cmds: Vec<~str> ,
pub debugger_cmds: Vec<~str> ,
// Lines to check if they appear in the expected debugger output
check_lines: Vec<~str> ,
pub check_lines: Vec<~str> ,
// Flag to force a crate to be built with the host architecture
force_host: bool,
pub force_host: bool,
// Check stdout for error-pattern output as well as stderr
check_stdout: bool,
pub check_stdout: bool,
// Don't force a --crate-type=dylib flag on the command line
no_prefer_dynamic: bool,
pub no_prefer_dynamic: bool,
}

// Load any test directives embedded in the file
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> {
return env;
}

pub struct Result {status: ProcessExit, out: ~str, err: ~str}
pub struct Result {pub status: ProcessExit, pub out: ~str, pub err: ~str}

pub fn run(lib_path: &str,
prog: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ use std::ptr;
// Unique<T> has the same semantics as ~T
pub struct Unique<T> {
// It contains a single raw, mutable pointer to the object in question.
priv ptr: *mut T
ptr: *mut T
}
// Implement methods for creating and using the values in the box.
Expand Down
15 changes: 6 additions & 9 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1527,12 +1527,9 @@ of an item to see whether it should be allowed or not. This is where privacy
warnings are generated, or otherwise "you used a private item of another module
and weren't allowed to."

By default, everything in rust is *private*, with two exceptions. The first
exception is that struct fields are public by default (but the struct itself is
still private by default), and the remaining exception is that enum variants in
a `pub` enum are the default visibility of the enum container itself.. You are
allowed to alter this default visibility with the `pub` keyword (or `priv`
keyword for struct fields and enum variants). When an item is declared as `pub`,
By default, everything in rust is *private*, with one exception. Enum variants
in a `pub` enum are also public by default. You are allowed to alter this
default visibility with the `priv` keyword. When an item is declared as `pub`,
it can be thought of as being accessible to the outside world. For example:

~~~~
Expand All @@ -1542,7 +1539,7 @@ struct Foo;
// Declare a public struct with a private field
pub struct Bar {
priv field: int
field: int
}
// Declare a public enum with public and private variants
Expand Down Expand Up @@ -2354,7 +2351,7 @@ The following are examples of structure expressions:
~~~~
# struct Point { x: f64, y: f64 }
# struct TuplePoint(f64, f64);
# mod game { pub struct User<'a> { name: &'a str, age: uint, score: uint } }
# mod game { pub struct User<'a> { pub name: &'a str, pub age: uint, pub score: uint } }
# struct Cookie; fn some_fn<T>(t: T) {}
Point {x: 10.0, y: 20.0};
TuplePoint(10.0, 20.0);
Expand Down Expand Up @@ -3140,7 +3137,7 @@ The types `char` and `str` hold textual data.
A value of type `char` is a [Unicode scalar value](
http://www.unicode.org/glossary/#unicode_scalar_value)
(ie. a code point that is not a surrogate),
represented as a 32-bit unsigned word in the 0x0000 to 0xD7FF
represented as a 32-bit unsigned word in the 0x0000 to 0xD7FF
or 0xE000 to 0x10FFFF range.
A `[char]` vector is effectively an UCS-4 / UTF-32 string.

Expand Down
8 changes: 4 additions & 4 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2657,8 +2657,8 @@ Rust doesn't support encapsulation: both struct fields and methods can
be private. But this encapsulation is at the module level, not the
struct level.

For convenience, fields are _public_ by default, and can be made _private_ with
the `priv` keyword:
Fields are _private_ by default, and can be made _public_ with
the `pub` keyword:

~~~
mod farm {
Expand All @@ -2667,8 +2667,8 @@ mod farm {
# impl Human { pub fn rest(&self) { } }
# pub fn make_me_a_farm() -> Farm { Farm { chickens: ~[], farmer: Human(0) } }
pub struct Farm {
priv chickens: ~[Chicken],
farmer: Human
chickens: ~[Chicken],
pub farmer: Human
}
impl Farm {
Expand Down
14 changes: 8 additions & 6 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#![allow(missing_doc)]
#![feature(managed_boxes)]

#![allow(visible_private_types)] // NOTE: remove after a stage0 snap

extern crate collections;

use std::cast::{transmute, transmute_mut, transmute_mut_region};
Expand Down Expand Up @@ -83,9 +85,9 @@ pub struct Arena {
// The head is separated out from the list as a unbenchmarked
// microoptimization, to avoid needing to case on the list to
// access the head.
priv head: Chunk,
priv copy_head: Chunk,
priv chunks: RefCell<Vec<Chunk>>,
head: Chunk,
copy_head: Chunk,
chunks: RefCell<Vec<Chunk>>,
}

impl Arena {
Expand Down Expand Up @@ -333,14 +335,14 @@ fn test_arena_destructors_fail() {
/// run again for these objects.
pub struct TypedArena<T> {
/// A pointer to the next object to be allocated.
priv ptr: *T,
ptr: *T,

/// A pointer to the end of the allocated area. When this pointer is
/// reached, a new chunk is allocated.
priv end: *T,
end: *T,

/// A pointer to the first arena segment.
priv first: Option<~TypedArenaChunk<T>>,
first: Option<~TypedArenaChunk<T>>,
}

struct TypedArenaChunk<T> {
Expand Down
18 changes: 9 additions & 9 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ enum Op {Union, Intersect, Assign, Difference}
#[deriving(Clone)]
pub struct Bitv {
/// Internal representation of the bit vector (small or large)
priv rep: BitvVariant,
rep: BitvVariant,
/// The number of valid bits in the internal representation
priv nbits: uint
nbits: uint
}

fn die() -> ! {
Expand Down Expand Up @@ -587,9 +587,9 @@ fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool {

/// An iterator for `Bitv`.
pub struct Bits<'a> {
priv bitv: &'a Bitv,
priv next_idx: uint,
priv end_idx: uint,
bitv: &'a Bitv,
next_idx: uint,
end_idx: uint,
}

impl<'a> Iterator<bool> for Bits<'a> {
Expand Down Expand Up @@ -648,12 +648,12 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
/// as a `uint`.
#[deriving(Clone)]
pub struct BitvSet {
priv size: uint,
size: uint,

// In theory this is a `Bitv` instead of always a `BigBitv`, but knowing that
// there's an array of storage makes our lives a whole lot easier when
// performing union/intersection/etc operations
priv bitv: BigBitv
bitv: BigBitv
}

impl BitvSet {
Expand Down Expand Up @@ -912,8 +912,8 @@ impl BitvSet {
}

pub struct BitPositions<'a> {
priv set: &'a BitvSet,
priv next_idx: uint
set: &'a BitvSet,
next_idx: uint
}

impl<'a> Iterator<uint> for BitPositions<'a> {
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ use std::fmt::Show;

#[allow(missing_doc)]
pub struct BTree<K, V> {
priv root: Node<K, V>,
priv len: uint,
priv lower_bound: uint,
priv upper_bound: uint
root: Node<K, V>,
len: uint,
lower_bound: uint,
upper_bound: uint
}

impl<K: TotalOrd, V> BTree<K, V> {
Expand Down
Loading

0 comments on commit b8ef9fd

Please sign in to comment.