Fix existing privacy/visibility violations

This commit fixes all of the fallout of the previous commit which is an attempt
to refine privacy. There were a few unfortunate leaks which now must be plugged,
and the most horrible one is the current `shouldnt_be_public` module now inside
`std::rt`. I think that this either needs a slight reorganization of the
runtime, or otherwise it needs to just wait for the external users of these
modules to get replaced with their `rt` implementations.

Other fixes involve making things pub which should be pub, and otherwise
updating error messages that now reference privacy instead of referencing an
"unresolved name" (yay!).
This commit is contained in:
Alex Crichton 2013-10-05 14:44:37 -07:00
parent 439e2770be
commit de7d143176
43 changed files with 165 additions and 108 deletions

View File

@ -40,7 +40,7 @@ pub trait Deque<T> : Mutable {
}
#[cfg(test)]
mod bench {
pub mod bench {
use std::container::MutableMap;
use std::{vec, rand};
use std::rand::Rng;

View File

@ -346,7 +346,7 @@ impl <T: FixedBuffer> StandardPadding for T {
#[cfg(test)]
mod test {
pub mod test {
use std::rand::{IsaacRng, Rng};
use std::vec;

View File

@ -101,7 +101,8 @@ pub trait Stats {
/// Extracted collection of all the summary statistics of a sample set.
#[deriving(Clone, Eq)]
struct Summary {
#[allow(missing_doc)]
pub struct Summary {
sum: f64,
min: f64,
max: f64,

View File

@ -31,8 +31,8 @@ use syntax::ast_util::id_range;
use syntax::codemap::Span;
use syntax::print::pprust;
use syntax::visit;
use syntax::visit::Visitor;
use syntax::ast::{Expr, fn_kind, fn_decl, Block, NodeId, Stmt, Pat, Local};
use syntax::visit::{Visitor, fn_kind};
use syntax::ast::{Expr, fn_decl, Block, NodeId, Stmt, Pat, Local};
mod lifetime;
mod restrictions;

View File

@ -581,7 +581,7 @@ impl Datum {
if !header && !ty::type_contents(bcx.tcx(), content_ty).contains_managed() {
let ptr = self.to_value_llval(bcx);
let ty = type_of(bcx.ccx(), content_ty);
let ty = type_of::type_of(bcx.ccx(), content_ty);
let body = PointerCast(bcx, ptr, ty.ptr_to());
Datum {val: body, ty: content_ty, mode: ByRef(ZeroMem)}
} else { // has a header

View File

@ -1026,7 +1026,7 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock {
// which may not be equal to the enum's type for
// non-C-like enums.
let val = base::get_item_val(bcx.ccx(), did.node);
let pty = type_of(bcx.ccx(), const_ty).ptr_to();
let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to();
PointerCast(bcx, val, pty)
} else {
{
@ -1040,7 +1040,7 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: &ast::Expr) -> DatumBlock {
}
unsafe {
let llty = type_of(bcx.ccx(), const_ty);
let llty = type_of::type_of(bcx.ccx(), const_ty);
let symbol = csearch::get_symbol(
bcx.ccx().sess.cstore,
did);
@ -1396,7 +1396,7 @@ fn trans_unary_datum(bcx: @mut Block,
heap: heap) -> DatumBlock {
let _icx = push_ctxt("trans_boxed_expr");
if heap == heap_exchange {
let llty = type_of(bcx.ccx(), contents_ty);
let llty = type_of::type_of(bcx.ccx(), contents_ty);
let size = llsize_of(bcx.ccx(), llty);
let Result { bcx: bcx, val: val } = malloc_raw_dyn(bcx, contents_ty,
heap_exchange, size);

View File

@ -203,7 +203,7 @@ pub fn lazily_emit_tydesc_glue(ccx: @mut CrateContext,
field: uint,
ti: @mut tydesc_info) {
let _icx = push_ctxt("lazily_emit_tydesc_glue");
let llfnty = Type::glue_fn(type_of::type_of(ccx, ti.ty).ptr_to());
let llfnty = Type::glue_fn(type_of(ccx, ti.ty).ptr_to());
if lazily_emit_simplified_tydesc_glue(ccx, field, ti) {
return;
@ -345,7 +345,7 @@ pub fn make_visit_glue(bcx: @mut Block, v: ValueRef, t: ty::t) -> @mut Block {
bcx.tcx().sess.fatal(s);
}
};
let v = PointerCast(bcx, v, type_of::type_of(bcx.ccx(), object_ty).ptr_to());
let v = PointerCast(bcx, v, type_of(bcx.ccx(), object_ty).ptr_to());
bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, visitor_trait.def_id);
// The visitor is a boxed object and needs to be dropped
add_clean(bcx, v, object_ty);

View File

@ -330,8 +330,8 @@ impl CoherenceChecker {
let impl_poly_type = ty::lookup_item_type(tcx, impl_id);
let provided = ty::provided_trait_methods(tcx, trait_ref.def_id);
for trait_method in provided.iter() {
let prov = ty::provided_trait_methods(tcx, trait_ref.def_id);
for trait_method in prov.iter() {
// Synthesize an ID.
let new_id = tcx.sess.next_node_id();
let new_did = local_def(new_id);

View File

@ -126,7 +126,7 @@ enum Implementor {
/// to be a fairly large and expensive structure to clone. Instead this adheres
/// to both `Send` and `Freeze` so it may be stored in a `RWArc` instance and
/// shared among the various rendering tasks.
struct Cache {
pub struct Cache {
/// Mapping of typaram ids to the name of the type parameter. This is used
/// when pretty-printing a type (so pretty printing doesn't have to
/// painfully maintain a context like this)

View File

@ -24,7 +24,7 @@ use utils::*;
/// This structure keeps track of the state of the world for the code being
/// executed in rusti.
#[deriving(Clone)]
struct Program {
pub struct Program {
/// All known local variables
local_vars: HashMap<~str, LocalVariable>,
/// New variables which will be present (learned from typechecking)

View File

@ -36,10 +36,10 @@ pub mod c_double_utils {
pub fn exp(n: c_double) -> c_double;
// rename: for consistency with underscore usage elsewhere
#[link_name="expm1"]
fn exp_m1(n: c_double) -> c_double;
pub fn exp_m1(n: c_double) -> c_double;
pub fn exp2(n: c_double) -> c_double;
#[link_name="fabs"]
fn abs(n: c_double) -> c_double;
pub fn abs(n: c_double) -> c_double;
// rename: for clarity and consistency with add/sub/mul/div
#[link_name="fdim"]
pub fn abs_sub(a: c_double, b: c_double) -> c_double;

View File

@ -335,14 +335,15 @@ mod test {
// newtype struct autoderef weirdness
#[test]
fn test_buffered_stream() {
use rt;
struct S;
impl Writer for S {
impl rt::io::Writer for S {
fn write(&mut self, _: &[u8]) {}
fn flush(&mut self) {}
}
impl Reader for S {
impl rt::io::Reader for S {
fn read(&mut self, _: &mut [u8]) -> Option<uint> { None }
fn eof(&mut self) -> bool { true }
}

View File

@ -300,7 +300,8 @@ pub mod comm_adapters;
mod extensions;
/// Non-I/O things needed by the I/O module
mod support;
// XXX: shouldn this really be pub?
pub mod support;
/// Basic Timer
pub mod timer;

View File

@ -67,14 +67,27 @@ use rt::local::Local;
use rt::sched::{Scheduler, Shutdown};
use rt::sleeper_list::SleeperList;
use rt::task::{Task, SchedTask, GreenTask, Sched};
use rt::thread::Thread;
use rt::work_queue::WorkQueue;
use rt::uv::uvio::UvEventLoop;
use unstable::atomics::{AtomicInt, SeqCst};
use unstable::sync::UnsafeArc;
use vec;
use vec::{OwnedVector, MutableVector, ImmutableVector};
use self::thread::Thread;
use self::work_queue::WorkQueue;
// XXX: these probably shouldn't be public...
#[doc(hidden)]
pub mod shouldnt_be_public {
pub use super::sched::Scheduler;
pub use super::kill::KillHandle;
pub use super::thread::Thread;
pub use super::work_queue::WorkQueue;
pub use super::select::SelectInner;
pub use super::rtio::EventLoop;
pub use super::select::{SelectInner, SelectPortInner};
}
/// The global (exchange) heap.
pub mod global_heap;

View File

@ -803,6 +803,12 @@ impl SchedHandle {
self.queue.push(msg);
self.remote.fire();
}
pub fn send_task_from_friend(&mut self, friend: ~Task) {
self.send(TaskFromFriend(friend));
}
pub fn send_shutdown(&mut self) {
self.send(Shutdown);
}
}
struct CleanupJob {

View File

@ -15,10 +15,8 @@ use iter::{Iterator, DoubleEndedIterator};
use option::*;
// use either::{Either, Left, Right};
// use rt::kill::BlockedTask;
use rt::sched::Scheduler;
use rt::select::{SelectInner, SelectPortInner};
use rt::local::Local;
use rt::rtio::EventLoop;
use rt::shouldnt_be_public::{EventLoop, Scheduler, SelectInner, SelectPortInner};
use task;
use unstable::finally::Finally;
use vec::{OwnedVector, MutableVector};

View File

@ -551,7 +551,7 @@ pub fn deschedule() {
//! Yield control to the task scheduler
use rt::local::Local;
use rt::sched::Scheduler;
use rt::shouldnt_be_public::Scheduler;
// FIXME(#7544): Optimize this, since we know we won't block.
let sched: ~Scheduler = Local::take();

View File

@ -89,11 +89,8 @@ use unstable::sync::Exclusive;
use rt::in_green_task_context;
use rt::local::Local;
use rt::task::{Task, Sched};
use rt::kill::KillHandle;
use rt::sched::Scheduler;
use rt::shouldnt_be_public::{Scheduler, KillHandle, WorkQueue, Thread};
use rt::uv::uvio::UvEventLoop;
use rt::thread::Thread;
use rt::work_queue::WorkQueue;
#[cfg(test)] use task::default_task_opts;
#[cfg(test)] use comm;
@ -556,8 +553,6 @@ fn enlist_many(child: &KillHandle, child_arc: &TaskGroupArc,
}
pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
use rt::sched::*;
rtassert!(in_green_task_context());
let child_data = Cell::new(gen_child_taskgroup(opts.linked, opts.supervised));
@ -622,7 +617,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
let mut new_sched_handle = new_sched.make_handle();
// Allow the scheduler to exit when the pinned task exits
new_sched_handle.send(Shutdown);
new_sched_handle.send_shutdown();
// Pin the new task to the new scheduler
let new_task = if opts.watched {
@ -660,7 +655,7 @@ pub fn spawn_raw(mut opts: TaskOpts, f: ~fn()) {
rtdebug!("enqueing join_task");
// Now tell the original scheduler to join with this thread
// by scheduling a thread-joining task on the original scheduler
orig_sched_handle.send(TaskFromFriend(join_task));
orig_sched_handle.send_task_from_friend(join_task);
// NB: We can't simply send a message from here to another task
// because this code isn't running in a task and message passing doesn't

View File

@ -38,7 +38,7 @@ a normal large stack.
*/
pub fn run_in_bare_thread(f: ~fn()) {
use cell::Cell;
use rt::thread::Thread;
use rt::shouldnt_be_public::Thread;
let f_cell = Cell::new(f);
let (port, chan) = comm::stream();

View File

@ -90,10 +90,10 @@ mod tests {
use super::*;
use clone::Clone;
use ops::Drop;
use option::{None, Some};
use either::{Either, Left, Right};
use sys::size_of;
use kinds::Drop;
#[test]
fn identity_crisis() {

View File

@ -964,7 +964,7 @@ mod test {
use super::*;
use std::io;
use opt_vec;
use std::hash::HashMap;
use std::hashmap::HashMap;
fn ident_to_segment(id : &Ident) -> PathSegment {
PathSegment{identifier:id.clone(), lifetime: None, types: opt_vec::Empty}

View File

@ -1551,7 +1551,8 @@ mod test {
let varrefs = @mut ~[];
visit::walk_crate(&mut new_path_finder(varrefs), &renamed_ast, ());
match varrefs {
@[Path{segments:[ref seg],_}] => assert_eq!(mtwt_resolve(seg.identifier),a2_name),
@[ast::Path{segments:[ref seg],_}] =>
assert_eq!(mtwt_resolve(seg.identifier),a2_name),
_ => assert_eq!(0,1)
}
@ -1565,7 +1566,8 @@ mod test {
let varrefs = @mut ~[];
visit::walk_crate(&mut new_path_finder(varrefs), &double_renamed, ());
match varrefs {
@[Path{segments:[ref seg],_}] => assert_eq!(mtwt_resolve(seg.identifier),a3_name),
@[ast::Path{segments:[ref seg],_}] =>
assert_eq!(mtwt_resolve(seg.identifier),a3_name),
_ => assert_eq!(0,1)
}
}

View File

@ -8,9 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: import
use m::unexported;
//~^ ERROR: is private
mod m {
pub fn exported() { }

View File

@ -8,12 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: unresolved name
mod foo {
pub fn x() { }
enum y { y1, }
}
fn main() { let z = foo::y1; }
fn main() { let z = foo::y1; } //~ ERROR: is private

View File

@ -8,12 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use zoo::{duck, goose}; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: found `goose` in `zoo` but it is private
use zoo::{duck, goose}; //~ ERROR: variant `goose` is private
mod zoo {
pub enum bird {
pub duck,
pub duck, //~ ERROR: unnecessary `pub` visibility
priv goose
}
}

View File

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use zoo::fly; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: found `fly` in `zoo` but it is private
use zoo::fly; //~ ERROR: function `fly` is private
mod zoo {
type fly = ();
fn fly() {}
}
fn main() {}
fn main() {
fly();
}

View File

@ -8,12 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use zoo::fly; //~ ERROR failed to resolve import
//~^ ERROR unresolved import: found `fly` in `zoo` but it is private
use zoo::fly; //~ ERROR: function `fly` is private
mod zoo {
fn fly() {}
}
fn main() {}
fn main() {
fly();
}

View File

@ -0,0 +1,38 @@
// Copyright 2013 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.
// ensures that 'use foo:*' doesn't import non-public item
use m1::*;
mod foo {
pub fn foo() {}
}
mod a {
pub mod b {
use foo::foo;
type bar = int;
}
pub mod sub {
use a::b::*;
fn sub() -> bar { 1 }
//~^ ERROR: undeclared type name
}
}
mod m1 {
fn foo() {}
}
fn main() {
foo(); //~ ERROR: unresolved name
}

View File

@ -27,8 +27,7 @@ mod a {
}
pub mod sub {
use a::b::*;
fn sub() -> bar { foo(); 1 } //~ ERROR: unresolved name `foo`
//~^ ERROR: use of undeclared type name `bar`
fn sub() -> int { foo(); 1 } //~ ERROR: unresolved name `foo`
}
}
@ -36,6 +35,4 @@ mod m1 {
fn foo() {}
}
fn main() {
foo(); //~ ERROR: unresolved name `foo`
}
fn main() {}

View File

@ -18,5 +18,5 @@ mod bar {
fn main() {
local_data::set(bar::baz, -10.0);
//~^ ERROR unresolved name `bar::baz`
//~^ ERROR static `baz` is private
}

View File

@ -13,5 +13,5 @@ mod a {
}
fn main() {
a::f(); //~ ERROR unresolved name
a::f(); //~ ERROR function `f` is private
}

View File

@ -17,5 +17,5 @@ mod a {
}
fn main() {
let x = a::Liege; //~ ERROR unresolved name
let x = a::Liege; //~ ERROR variant `Liege` is private
}

View File

@ -24,15 +24,15 @@ mod child {
fn foo(_: int) {}
fn full_ref() {
foo(static_priv_by_default::private); //~ ERROR: unresolved name
foo(static_priv_by_default::private); //~ ERROR: static `private` is private
foo(static_priv_by_default::public);
foo(child::childs_child::private); //~ ERROR: unresolved name
foo(child::childs_child::private); //~ ERROR: static `private` is private
foo(child::childs_child::public);
}
fn medium_ref() {
use child::childs_child;
foo(childs_child::private); //~ ERROR: unresolved name
foo(childs_child::private); //~ ERROR: static `private` is private
foo(childs_child::public);
}

View File

@ -19,11 +19,22 @@ mod child {
}
}
fn main() {
use static_priv_by_default::private; //~ ERROR: unresolved import
//~^ ERROR: failed to resolve
use static_priv_by_default::public;
use child::childs_child::private; //~ ERROR: unresolved import
//~^ ERROR: failed to resolve
fn foo<T>(_: T) {}
fn test1() {
use child::childs_child::private;
//~^ ERROR: static `private` is private
use child::childs_child::public;
foo(private);
}
fn test2() {
use static_priv_by_default::private;
//~^ ERROR: static `private` is private
use static_priv_by_default::public;
foo(private);
}
fn main() {}

View File

@ -15,8 +15,8 @@ extern mod xc_private_method_lib;
fn main() {
let _ = xc_private_method_lib::Struct::static_meth_struct();
//~^ ERROR: unresolved name
//~^ ERROR: method `static_meth_struct` is private
let _ = xc_private_method_lib::Enum::static_meth_enum();
//~^ ERROR: unresolved name
//~^ ERROR: method `static_meth_enum` is private
}

View File

@ -10,15 +10,14 @@
// aux-build:static_priv_by_default.rs
#[allow(unused_imports)];
#[no_std];
#[no_std]; // helps if debugging resolve
extern mod static_priv_by_default;
fn foo<T>() {}
#[start]
fn main(_: int, _: **u8, _: *u8) -> int {
fn main(_: int, _: **u8) -> int {
// Actual public items should be public
static_priv_by_default::a;
static_priv_by_default::b;
@ -33,25 +32,23 @@ fn main(_: int, _: **u8, _: *u8) -> int {
// private items at the top should be inaccessible
static_priv_by_default::i;
//~^ ERROR: unresolved name
//~^ ERROR: static `i` is private
static_priv_by_default::j;
//~^ ERROR: unresolved name
//~^ ERROR: function `j` is private
static_priv_by_default::k;
//~^ ERROR: unresolved name
//~^ ERROR: struct `k` is private
foo::<static_priv_by_default::l>();
//~^ ERROR: use of undeclared type name
//~^^ ERROR: use of undeclared type name
//~^ ERROR: type `l` is private
// public items in a private mod should be inaccessible
static_priv_by_default::foo::a;
//~^ ERROR: unresolved name
//~^ ERROR: static `a` is private
static_priv_by_default::foo::b;
//~^ ERROR: unresolved name
//~^ ERROR: function `b` is private
static_priv_by_default::foo::c;
//~^ ERROR: unresolved name
//~^ ERROR: struct `c` is private
foo::<static_priv_by_default::foo::d>();
//~^ ERROR: use of undeclared type name
//~^^ ERROR: use of undeclared type name
//~^ ERROR: type `d` is private
3
}

View File

@ -9,7 +9,7 @@
// except according to those terms.
mod foo {
mod bar {
pub mod bar {
pub fn y() { super::super::foo::x(); }
}

View File

@ -17,7 +17,7 @@ mod rustrt1 {
#[abi = "cdecl"]
#[link_name = "rustrt"]
extern {
fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> libc::intptr_t;
}
}
@ -27,7 +27,7 @@ mod rustrt2 {
#[abi = "cdecl"]
#[link_name = "rustrt"]
extern {
fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> libc::intptr_t;
}
}

View File

@ -14,7 +14,7 @@ mod rustrt {
use std::libc;
extern {
fn rust_get_test_int() -> libc::intptr_t;
pub fn rust_get_test_int() -> libc::intptr_t;
}
}

View File

@ -11,7 +11,7 @@
mod rusti {
#[abi = "rust-intrinsic"]
extern "rust-intrinsic" {
fn uninit<T>() -> T;
pub fn uninit<T>() -> T;
}
}
pub fn main() {

View File

@ -17,24 +17,24 @@ extern mod extra;
mod rusti {
#[abi = "rust-intrinsic"]
extern "rust-intrinsic" {
fn ctpop8(x: i8) -> i8;
fn ctpop16(x: i16) -> i16;
fn ctpop32(x: i32) -> i32;
fn ctpop64(x: i64) -> i64;
pub fn ctpop8(x: i8) -> i8;
pub fn ctpop16(x: i16) -> i16;
pub fn ctpop32(x: i32) -> i32;
pub fn ctpop64(x: i64) -> i64;
fn ctlz8(x: i8) -> i8;
fn ctlz16(x: i16) -> i16;
fn ctlz32(x: i32) -> i32;
fn ctlz64(x: i64) -> i64;
pub fn ctlz8(x: i8) -> i8;
pub fn ctlz16(x: i16) -> i16;
pub fn ctlz32(x: i32) -> i32;
pub fn ctlz64(x: i64) -> i64;
fn cttz8(x: i8) -> i8;
fn cttz16(x: i16) -> i16;
fn cttz32(x: i32) -> i32;
fn cttz64(x: i64) -> i64;
pub fn cttz8(x: i8) -> i8;
pub fn cttz16(x: i16) -> i16;
pub fn cttz32(x: i32) -> i32;
pub fn cttz64(x: i64) -> i64;
fn bswap16(x: i16) -> i16;
fn bswap32(x: i32) -> i32;
fn bswap64(x: i64) -> i64;
pub fn bswap16(x: i16) -> i16;
pub fn bswap32(x: i32) -> i32;
pub fn bswap64(x: i64) -> i64;
}
}

View File

@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
mod test;
pub mod test;

View File

@ -46,7 +46,7 @@ mod m {
}
#[cfg(target_arch = "x86_64")]
mod m {
pub mod m {
pub fn align() -> uint { 8u }
pub fn size() -> uint { 16u }
}