diff options
Diffstat (limited to 'src/libcore')
35 files changed, 454 insertions, 621 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 7d410c0337a..ce3dec89e41 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -1,7 +1,7 @@ //! Managed vectors // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cast::transmute; @@ -21,7 +21,7 @@ extern mod rustrt { #[abi = "rust-intrinsic"] extern mod rusti { #[legacy_exports]; - fn move_val_init<T>(&dst: T, -src: T); + fn move_val_init<T>(dst: &mut T, -src: T); } /// Returns the number of elements the vector can hold without reallocating @@ -176,7 +176,7 @@ pub mod raw { push_slow(v, move initval); } } - // This doesn't bother to make sure we have space. + #[inline(always)] // really pretty please pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&v); @@ -184,7 +184,7 @@ pub mod raw { (**repr).unboxed.fill += sys::size_of::<T>(); let p = addr_of(&((**repr).unboxed.data)); let p = ptr::offset(p, fill) as *mut T; - rusti::move_val_init(*p, move initval); + rusti::move_val_init(&mut(*p), move initval); } pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) { diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index f4f0d7b6104..030f05c6eea 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -1,4 +1,5 @@ //! Unsafe operations +#[forbid(deprecated_mode)] #[abi = "rust-intrinsic"] extern mod rusti { @@ -18,7 +19,7 @@ pub unsafe fn reinterpret_cast<T, U>(src: &T) -> U { * The forget function will take ownership of the provided value but neglect * to run any required cleanup or memory-management operations on it. This * can be used for various acts of magick, particularly when using - * reinterpret_cast on managed pointer types. + * reinterpret_cast on pointer types. */ #[inline(always)] pub unsafe fn forget<T>(thing: T) { rusti::forget(move thing); } diff --git a/src/libcore/cmath.rs b/src/libcore/cmath.rs index 9a9a7cb3112..b0aeb78afaa 100644 --- a/src/libcore/cmath.rs +++ b/src/libcore/cmath.rs @@ -40,15 +40,15 @@ pub extern mod c_double { #[link_name="fmax"] pure fn fmax(a: c_double, b: c_double) -> c_double; #[link_name="fmin"] pure fn fmin(a: c_double, b: c_double) -> c_double; pure fn nextafter(x: c_double, y: c_double) -> c_double; - pure fn frexp(n: c_double, &value: c_int) -> c_double; + pure fn frexp(n: c_double, value: &mut c_int) -> c_double; pure fn hypot(x: c_double, y: c_double) -> c_double; pure fn ldexp(x: c_double, n: c_int) -> c_double; #[cfg(unix)] #[link_name="lgamma_r"] pure fn lgamma(n: c_double, - &sign: c_int) -> c_double; + sign: &mut c_int) -> c_double; #[cfg(windows)] #[link_name="__lgamma_r"] pure fn lgamma(n: c_double, - &sign: c_int) -> c_double; + sign: &mut c_int) -> c_double; // renamed: log is a reserved keyword; ln seems more natural, too #[link_name="log"] pure fn ln(n: c_double) -> c_double; // renamed: "logb" /often/ is confused for log2 by beginners @@ -58,7 +58,7 @@ pub extern mod c_double { pure fn log10(n: c_double) -> c_double; pure fn log2(n: c_double) -> c_double; #[link_name="ilogb"] pure fn ilog_radix(n: c_double) -> c_int; - pure fn modf(n: c_double, &iptr: c_double) -> c_double; + pure fn modf(n: c_double, iptr: &mut c_double) -> c_double; pure fn pow(n: c_double, e: c_double) -> c_double; // FIXME (#1379): enable when rounding modes become available // pure fn rint(n: c_double) -> c_double; @@ -110,7 +110,7 @@ pub extern mod c_float { #[link_name="fdimf"] pure fn abs_sub(a: c_float, b: c_float) -> c_float; #[link_name="floorf"] pure fn floor(n: c_float) -> c_float; #[link_name="frexpf"] pure fn frexp(n: c_float, - &value: c_int) -> c_float; + value: &mut c_int) -> c_float; #[link_name="fmaf"] pure fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float; #[link_name="fmaxf"] pure fn fmax(a: c_float, b: c_float) -> c_float; @@ -122,11 +122,11 @@ pub extern mod c_float { #[cfg(unix)] #[link_name="lgammaf_r"] pure fn lgamma(n: c_float, - &sign: c_int) -> c_float; + sign: &mut c_int) -> c_float; #[cfg(windows)] #[link_name="__lgammaf_r"] pure fn lgamma(n: c_float, - &sign: c_int) -> c_float; + sign: &mut c_int) -> c_float; #[link_name="logf"] pure fn ln(n: c_float) -> c_float; #[link_name="logbf"] pure fn log_radix(n: c_float) -> c_float; @@ -135,7 +135,7 @@ pub extern mod c_float { #[link_name="log10f"] pure fn log10(n: c_float) -> c_float; #[link_name="ilogbf"] pure fn ilog_radix(n: c_float) -> c_int; #[link_name="modff"] pure fn modf(n: c_float, - &iptr: c_float) -> c_float; + iptr: &mut c_float) -> c_float; #[link_name="powf"] pure fn pow(n: c_float, e: c_float) -> c_float; // FIXME (#1379): enable when rounding modes become available // #[link_name="rintf"] pure fn rint(n: c_float) -> c_float; diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 64c38d13e49..c9cd1a21b45 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -32,8 +32,8 @@ will once again be the preferred module for intertask communication. */ -// NB: transitionary, de-mode-ing -// tjc: re-forbid deprecated modes after snapshot +// NB: transitionary, de-mode-ing. +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use either::Either; @@ -74,7 +74,7 @@ pub fn Port<T: Send>() -> Port<T> { impl<T: Send> Port<T> { - fn chan() -> Chan<T> { Chan(self) } + fn chan() -> Chan<T> { Chan(&self) } fn send(v: T) { self.chan().send(move v) } fn recv() -> T { recv(self) } fn peek() -> bool { peek(self) } @@ -166,7 +166,7 @@ fn as_raw_port<T: Send, U>(ch: comm::Chan<T>, f: fn(*rust_port) -> U) -> U { * Constructs a channel. The channel is bound to the port used to * construct it. */ -pub fn Chan<T: Send>(&&p: Port<T>) -> Chan<T> { +pub fn Chan<T: Send>(p: &Port<T>) -> Chan<T> { Chan_(rustrt::get_port_id((**p).po)) } @@ -304,19 +304,19 @@ extern mod rusti { #[test] -fn create_port_and_chan() { let p = Port::<int>(); Chan(p); } +fn create_port_and_chan() { let p = Port::<int>(); Chan(&p); } #[test] fn send_int() { let p = Port::<int>(); - let c = Chan(p); + let c = Chan(&p); send(c, 22); } #[test] fn send_recv_fn() { let p = Port::<int>(); - let c = Chan::<int>(p); + let c = Chan::<int>(&p); send(c, 42); assert (recv(p) == 42); } @@ -324,7 +324,7 @@ fn send_recv_fn() { #[test] fn send_recv_fn_infer() { let p = Port(); - let c = Chan(p); + let c = Chan(&p); send(c, 42); assert (recv(p) == 42); } @@ -332,23 +332,23 @@ fn send_recv_fn_infer() { #[test] fn chan_chan_infer() { let p = Port(), p2 = Port::<int>(); - let c = Chan(p); - send(c, Chan(p2)); + let c = Chan(&p); + send(c, Chan(&p2)); recv(p); } #[test] fn chan_chan() { let p = Port::<Chan<int>>(), p2 = Port::<int>(); - let c = Chan(p); - send(c, Chan(p2)); + let c = Chan(&p); + send(c, Chan(&p2)); recv(p); } #[test] fn test_peek() { let po = Port(); - let ch = Chan(po); + let ch = Chan(&po); assert !peek(po); send(ch, ()); assert peek(po); @@ -360,8 +360,8 @@ fn test_peek() { fn test_select2_available() { let po_a = Port(); let po_b = Port(); - let ch_a = Chan(po_a); - let ch_b = Chan(po_b); + let ch_a = Chan(&po_a); + let ch_b = Chan(&po_b); send(ch_a, ~"a"); @@ -376,8 +376,8 @@ fn test_select2_available() { fn test_select2_rendezvous() { let po_a = Port(); let po_b = Port(); - let ch_a = Chan(po_a); - let ch_b = Chan(po_b); + let ch_a = Chan(&po_a); + let ch_b = Chan(&po_b); for iter::repeat(10) { do task::spawn { @@ -400,8 +400,8 @@ fn test_select2_rendezvous() { fn test_select2_stress() { let po_a = Port(); let po_b = Port(); - let ch_a = Chan(po_a); - let ch_b = Chan(po_b); + let ch_a = Chan(&po_a); + let ch_b = Chan(&po_b); let msgs = 100; let times = 4u; @@ -436,7 +436,7 @@ fn test_select2_stress() { #[test] fn test_recv_chan() { let po = Port(); - let ch = Chan(po); + let ch = Chan(&po); send(ch, ~"flower"); assert recv_chan(ch) == ~"flower"; } @@ -445,7 +445,7 @@ fn test_recv_chan() { #[should_fail] #[ignore(cfg(windows))] fn test_recv_chan_dead() { - let ch = Chan(Port()); + let ch = Chan(&Port()); send(ch, ~"flower"); recv_chan(ch); } @@ -454,7 +454,7 @@ fn test_recv_chan_dead() { #[ignore(cfg(windows))] fn test_recv_chan_wrong_task() { let po = Port(); - let ch = Chan(po); + let ch = Chan(&po); send(ch, ~"flower"); assert result::is_err(&task::try(|| recv_chan(ch) diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 818e1e890ec..94e6decc4ca 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -36,227 +36,185 @@ Implicitly, all crates behave as if they included the following prologue: // Don't link to core. We are core. #[no_core]; -#[legacy_exports]; - #[warn(deprecated_mode)]; #[warn(deprecated_pattern)]; #[warn(vecs_implicitly_copyable)]; #[deny(non_camel_case_types)]; -export int, i8, i16, i32, i64; -export uint, u8, u16, u32, u64; -export float, f32, f64; -export box, char, str, ptr, vec, at_vec, bool; -export either, option, result, iter; -export gc, io, libc, os, run, rand, sys, cast, logging; -export comm, task, future, pipes; -export extfmt; -// The test harness links against core, so don't include runtime in tests. -// FIXME (#2861): Uncomment this after snapshot gets updated. -//#[cfg(notest)] -export rt; -export tuple; -export to_str, to_bytes; -export from_str; -export util; -export dvec, dvec_iter; -export dlist, dlist_iter; -export send_map; -export hash; -export cmp; -export num; -export path; -export mutable; -export flate; -export unit; -export uniq; -export repr; -export cleanup; -export reflect; - -// NDM seems to be necessary for resolve to work -export option_iter; - -// This creates some APIs that I do not want to commit to, but it must be -// exported from core in order for uv to remain in std (see #2648). -export private; - - // Built-in-type support modules /// Operations and constants for `int` #[path = "int-template"] -mod int { +pub mod int { pub use inst::{ pow }; #[path = "int.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `i8` #[path = "int-template"] -mod i8 { +pub mod i8 { #[path = "i8.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `i16` #[path = "int-template"] -mod i16 { +pub mod i16 { #[path = "i16.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `i32` #[path = "int-template"] -mod i32 { +pub mod i32 { #[path = "i32.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `i64` #[path = "int-template"] -mod i64 { +pub mod i64 { #[path = "i64.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `uint` #[path = "uint-template"] -mod uint { +pub mod uint { pub use inst::{ div_ceil, div_round, div_floor, iterate, next_power_of_two }; #[path = "uint.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `u8` #[path = "uint-template"] -mod u8 { +pub mod u8 { pub use inst::is_ascii; #[path = "u8.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `u16` #[path = "uint-template"] -mod u16 { +pub mod u16 { #[path = "u16.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `u32` #[path = "uint-template"] -mod u32 { +pub mod u32 { #[path = "u32.rs"] - mod inst; + pub mod inst; } /// Operations and constants for `u64` #[path = "uint-template"] -mod u64 { +pub mod u64 { #[path = "u64.rs"] - mod inst; + pub mod inst; } -mod box; -mod char; -mod float; -mod f32; -mod f64; -mod str; -mod ptr; -mod vec; -mod at_vec; -mod bool; -mod tuple; -mod unit; -mod uniq; +pub mod box; +pub mod char; +pub mod float; +pub mod f32; +pub mod f64; +pub mod str; +pub mod ptr; +pub mod vec; +pub mod at_vec; +pub mod bool; +pub mod tuple; +pub mod unit; +pub mod uniq; // Ubiquitous-utility-type modules #[cfg(notest)] -mod ops; -mod cmp; -mod num; -mod hash; -mod either; -mod iter; -mod logging; -mod option; +pub mod ops; +pub mod cmp; +pub mod num; +pub mod hash; +pub mod either; +pub mod iter; +pub mod logging; +pub mod option; #[path="iter-trait"] -mod option_iter { +pub mod option_iter { #[path = "option.rs"] - mod inst; + pub mod inst; } -mod result; -mod to_str; -mod to_bytes; -mod from_str; -mod util; +pub mod result; +pub mod to_str; +pub mod to_bytes; +pub mod from_str; +pub mod util; // Data structure modules -mod dvec; +pub mod dvec; #[path="iter-trait"] -mod dvec_iter { +pub mod dvec_iter { #[path = "dvec.rs"] - mod inst; + pub mod inst; } -mod dlist; +pub mod dlist; #[path="iter-trait"] -mod dlist_iter { +pub mod dlist_iter { #[path ="dlist.rs"] - mod inst; + pub mod inst; } -mod send_map; +pub mod send_map; // Concurrency -mod comm; -mod task { +pub mod comm; +pub mod task { pub mod local_data; mod local_data_priv; pub mod spawn; pub mod rt; } -mod future; -mod pipes; +pub mod future; +pub mod pipes; // Runtime and language-primitive support -mod gc; -mod io; -mod libc; -mod os; -mod path; -mod rand; -mod run; -mod sys; -mod cast; -mod mutable; -mod flate; -mod repr; -mod cleanup; -mod reflect; +pub mod gc; +pub mod io; +pub mod libc; +pub mod os; +pub mod path; +pub mod rand; +pub mod run; +pub mod sys; +pub mod cast; +pub mod mutable; +pub mod flate; +pub mod repr; +pub mod cleanup; +pub mod reflect; // Modules supporting compiler-generated code // Exported but not part of the public interface -#[legacy_exports] -mod extfmt; +pub mod extfmt; // The test harness links against core, so don't include runtime in tests. #[cfg(notest)] #[legacy_exports] -mod rt; - +pub mod rt; -// For internal use, not exported +// Ideally not exported, but currently is. +pub mod private; +// For internal use, not exported. mod unicode; -mod private; mod cmath; mod stackwalk; diff --git a/src/libcore/core.rs b/src/libcore/core.rs index c7261aa8c29..a14b67b40f1 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -2,101 +2,76 @@ // Export various ubiquitous types, constructors, methods. -use option::{Some, None}; -use Option = option::Option; -use result::{Result, Ok, Err}; +pub use option::{Some, None}; +pub use Option = option::Option; +pub use result::{Result, Ok, Err}; -use Path = path::Path; -use GenericPath = path::GenericPath; -use WindowsPath = path::WindowsPath; -use PosixPath = path::PosixPath; +pub use Path = path::Path; +pub use GenericPath = path::GenericPath; +pub use WindowsPath = path::WindowsPath; +pub use PosixPath = path::PosixPath; -use tuple::{TupleOps, ExtendedTupleOps}; -use str::{StrSlice, UniqueStr}; -use vec::{ConstVector, CopyableVector, ImmutableVector}; -use vec::{ImmutableEqVector, ImmutableCopyableVector}; -use vec::{MutableVector, MutableCopyableVector}; -use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter}; -use iter::{CopyableOrderedIter, Times, TimesIx}; -use num::Num; -use ptr::Ptr; -use to_str::ToStr; - -export Path, WindowsPath, PosixPath, GenericPath; -export Option, Some, None; -export Result, Ok, Err; -export extensions; -// The following exports are the extension impls for numeric types -export Num, Times, TimesIx; -// The following exports are the common traits -export StrSlice, UniqueStr; -export ConstVector, CopyableVector, ImmutableVector; -export ImmutableEqVector, ImmutableCopyableVector, IterTraitExtensions; -export MutableVector, MutableCopyableVector; -export BaseIter, CopyableIter, CopyableOrderedIter, ExtendedIter, EqIter; -export TupleOps, ExtendedTupleOps; -export Ptr; -export ToStr; +pub use tuple::{TupleOps, ExtendedTupleOps}; +pub use str::{StrSlice, UniqueStr}; +pub use vec::{ConstVector, CopyableVector, ImmutableVector}; +pub use vec::{ImmutableEqVector, ImmutableCopyableVector}; +pub use vec::{MutableVector, MutableCopyableVector}; +pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter}; +pub use iter::{CopyableOrderedIter, Times, TimesIx}; +pub use num::Num; +pub use ptr::Ptr; +pub use to_str::ToStr; // The following exports are the core operators and kinds // The compiler has special knowlege of these so we must not duplicate them // when compiling for testing #[cfg(notest)] -use ops::{Const, Copy, Send, Owned}; +pub use ops::{Const, Copy, Send, Owned}; #[cfg(notest)] -use ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr, BitXor}; +pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr, BitXor}; #[cfg(notest)] -use ops::{Shl, Shr, Index}; - -#[cfg(notest)] -export Const, Copy, Send, Owned; -#[cfg(notest)] -export Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr, BitXor; -#[cfg(notest)] -export Shl, Shr, Index; +pub use ops::{Shl, Shr, Index}; #[cfg(test)] extern mod coreops(name = "core", vers = "0.4"); #[cfg(test)] -use coreops::ops::{Const, Copy, Send, Owned}; +pub use coreops::ops::{Const, Copy, Send, Owned}; +#[cfg(test)] +pub use coreops::ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr}; #[cfg(test)] -use coreops::ops::{Add, Sub, Mul, Div, Modulo, Neg, BitAnd, BitOr, BitXor}; +pub use coreops::ops::{BitXor}; #[cfg(test)] -use coreops::ops::{Shl, Shr, Index}; +pub use coreops::ops::{Shl, Shr, Index}; // Export the log levels as global constants. Higher levels mean // more-verbosity. Error is the bottom level, default logging level is // warn-and-below. -export error, warn, info, debug; - /// The error log level -const error : u32 = 0_u32; +pub const error : u32 = 0_u32; /// The warning log level -const warn : u32 = 1_u32; +pub const warn : u32 = 1_u32; /// The info log level -const info : u32 = 2_u32; +pub const info : u32 = 2_u32; /// The debug log level -const debug : u32 = 3_u32; +pub const debug : u32 = 3_u32; // A curious inner-module that's not exported that contains the binding // 'core' so that macro-expanded references to core::error and such // can be resolved within libcore. #[doc(hidden)] // FIXME #3538 mod core { - #[legacy_exports]; - const error : u32 = 0_u32; - const warn : u32 = 1_u32; - const info : u32 = 2_u32; - const debug : u32 = 3_u32; + pub const error : u32 = 0_u32; + pub const warn : u32 = 1_u32; + pub const info : u32 = 2_u32; + pub const debug : u32 = 3_u32; } // Similar to above. Some magic to make core testable. #[cfg(test)] mod std { - #[legacy_exports]; extern mod std(vers = "0.4"); - use std::test; + pub use std::test; } diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 17ddd6ea73b..3bcf486ef7e 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -9,7 +9,7 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate. */ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; type DListLink<T> = Option<DListNode<T>>; diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index a2a70908797..1540eb30fe5 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -10,7 +10,7 @@ Note that recursive use is not permitted. */ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cast::reinterpret_cast; diff --git a/src/libcore/either.rs b/src/libcore/either.rs index c64cd25e481..7500ff409a4 100644 --- a/src/libcore/either.rs +++ b/src/libcore/either.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; //! A type that represents one of two alternatives diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index e10ff4bac71..de2e91b2e32 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -1,4 +1,7 @@ #[doc(hidden)]; +// NB: transitionary, de-mode-ing. +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; /* Syntax Extension: fmt @@ -41,11 +44,10 @@ use option::{Some, None}; */ // Functions used by the fmt extension at compile time -mod ct { - #[legacy_exports]; - enum Signedness { Signed, Unsigned, } - enum Caseness { CaseUpper, CaseLower, } - enum Ty { +pub mod ct { + pub enum Signedness { Signed, Unsigned, } + pub enum Caseness { CaseUpper, CaseLower, } + pub enum Ty { TyBool, TyStr, TyChar, @@ -56,14 +58,14 @@ mod ct { TyFloat, TyPoly, } - enum Flag { + pub enum Flag { FlagLeftJustify, FlagLeftZeroPad, FlagSpaceForSign, FlagSignAlways, FlagAlternate, } - enum Count { + pub enum Count { CountIs(int), CountIsParam(int), CountIsNextParam, @@ -71,7 +73,7 @@ mod ct { } // A formatted conversion from an expression to a string - type Conv = + pub type Conv = {param: Option<int>, flags: ~[Flag], width: Count, @@ -80,10 +82,10 @@ mod ct { // A fragment of the output sequence - enum Piece { PieceString(~str), PieceConv(Conv), } - type ErrorFn = fn@(&str) -> ! ; + pub enum Piece { PieceString(~str), PieceConv(Conv), } + pub type ErrorFn = fn@(&str) -> ! ; - fn parse_fmt_string(s: &str, error: ErrorFn) -> ~[Piece] { + pub fn parse_fmt_string(s: &str, error: ErrorFn) -> ~[Piece] { let mut pieces: ~[Piece] = ~[]; let lim = str::len(s); let mut buf = ~""; @@ -118,7 +120,7 @@ mod ct { flush_buf(move buf, &mut pieces); move pieces } - fn peek_num(s: &str, i: uint, lim: uint) -> + pub fn peek_num(s: &str, i: uint, lim: uint) -> Option<{num: uint, next: uint}> { let mut j = i; let mut accum = 0u; @@ -140,7 +142,8 @@ mod ct { None } } - fn parse_conversion(s: &str, i: uint, lim: uint, error: ErrorFn) -> + pub fn parse_conversion(s: &str, i: uint, lim: uint, + error: ErrorFn) -> {piece: Piece, next: uint} { let parm = parse_parameter(s, i, lim); let flags = parse_flags(s, parm.next, lim); @@ -155,7 +158,7 @@ mod ct { ty: ty.ty}), next: ty.next}; } - fn parse_parameter(s: &str, i: uint, lim: uint) -> + pub fn parse_parameter(s: &str, i: uint, lim: uint) -> {param: Option<int>, next: uint} { if i >= lim { return {param: None, next: i}; } let num = peek_num(s, i, lim); @@ -170,7 +173,7 @@ mod ct { } }; } - fn parse_flags(s: &str, i: uint, lim: uint) -> + pub fn parse_flags(s: &str, i: uint, lim: uint) -> {flags: ~[Flag], next: uint} { let noflags: ~[Flag] = ~[]; if i >= lim { return {flags: move noflags, next: i}; } @@ -198,7 +201,7 @@ mod ct { more(FlagAlternate, s, i, lim) } else { {flags: move noflags, next: i} }; } - fn parse_count(s: &str, i: uint, lim: uint) + pub fn parse_count(s: &str, i: uint, lim: uint) -> {count: Count, next: uint} { return if i >= lim { {count: CountImplied, next: i} @@ -220,7 +223,7 @@ mod ct { } }; } - fn parse_precision(s: &str, i: uint, lim: uint) -> + pub fn parse_precision(s: &str, i: uint, lim: uint) -> {count: Count, next: uint} { return if i >= lim { {count: CountImplied, next: i} @@ -236,7 +239,7 @@ mod ct { } } else { {count: CountImplied, next: i} }; } - fn parse_type(s: &str, i: uint, lim: uint, error: ErrorFn) -> + pub fn parse_type(s: &str, i: uint, lim: uint, error: ErrorFn) -> {ty: Ty, next: uint} { if i >= lim { error(~"missing type in conversion"); } let tstr = str::slice(s, i, i+1u); @@ -274,21 +277,20 @@ mod ct { // decisions made a runtime. If it proves worthwhile then some of these // conditions can be evaluated at compile-time. For now though it's cleaner to // implement it 0this way, I think. -mod rt { - #[legacy_exports]; - const flag_none : u32 = 0u32; - const flag_left_justify : u32 = 0b00000000000000000000000000000001u32; - const flag_left_zero_pad : u32 = 0b00000000000000000000000000000010u32; - const flag_space_for_sign : u32 = 0b00000000000000000000000000000100u32; - const flag_sign_always : u32 = 0b00000000000000000000000000001000u32; - const flag_alternate : u32 = 0b00000000000000000000000000010000u32; +pub mod rt { + pub const flag_none : u32 = 0u32; + pub const flag_left_justify : u32 = 0b00000000000001u32; + pub const flag_left_zero_pad : u32 = 0b00000000000010u32; + pub const flag_space_for_sign : u32 = 0b00000000000100u32; + pub const flag_sign_always : u32 = 0b00000000001000u32; + pub const flag_alternate : u32 = 0b00000000010000u32; - enum Count { CountIs(int), CountImplied, } - enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, } + pub enum Count { CountIs(int), CountImplied, } + pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, } - type Conv = {flags: u32, width: Count, precision: Count, ty: Ty}; + pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty}; - pure fn conv_int(cv: Conv, i: int) -> ~str { + pub pure fn conv_int(cv: Conv, i: int) -> ~str { let radix = 10; let prec = get_int_precision(cv); let mut s : ~str = int_to_str_prec(i, radix, prec); @@ -301,7 +303,7 @@ mod rt { } return unsafe { pad(cv, s, PadSigned) }; } - pure fn conv_uint(cv: Conv, u: uint) -> ~str { + pub pure fn conv_uint(cv: Conv, u: uint) -> ~str { let prec = get_int_precision(cv); let mut rs = match cv.ty { @@ -313,17 +315,17 @@ mod rt { }; return unsafe { pad(cv, rs, PadUnsigned) }; } - pure fn conv_bool(cv: Conv, b: bool) -> ~str { + pub pure fn conv_bool(cv: Conv, b: bool) -> ~str { let s = if b { ~"true" } else { ~"false" }; // run the boolean conversion through the string conversion logic, // giving it the same rules for precision, etc. return conv_str(cv, s); } - pure fn conv_char(cv: Conv, c: char) -> ~str { + pub pure fn conv_char(cv: Conv, c: char) -> ~str { let mut s = str::from_char(c); return unsafe { pad(cv, s, PadNozero) }; } - pure fn conv_str(cv: Conv, s: &str) -> ~str { + pub pure fn conv_str(cv: Conv, s: &str) -> ~str { // For strings, precision is the maximum characters // displayed let mut unpadded = match cv.precision { @@ -336,7 +338,7 @@ mod rt { }; return unsafe { pad(cv, unpadded, PadNozero) }; } - pure fn conv_float(cv: Conv, f: float) -> ~str { + pub pure fn conv_float(cv: Conv, f: float) -> ~str { let (to_str, digits) = match cv.precision { CountIs(c) => (float::to_str_exact, c as uint), CountImplied => (float::to_str, 6u) @@ -351,14 +353,14 @@ mod rt { } return unsafe { pad(cv, s, PadFloat) }; } - pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str { + pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str { let s = sys::log_str(v); return conv_str(cv, s); } // Convert an int to string with minimum number of digits. If precision is // 0 and num is 0 then the result is the empty string. - pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str { + pub pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str { return if num < 0 { ~"-" + uint_to_str_prec(-num as uint, radix, prec) } else { uint_to_str_prec(num as uint, radix, prec) }; @@ -367,7 +369,8 @@ mod rt { // Convert a uint to string with a minimum number of digits. If precision // is 0 and num is 0 then the result is the empty string. Could move this // to uint: but it doesn't seem all that useful. - pure fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str { + pub pure fn uint_to_str_prec(num: uint, radix: uint, + prec: uint) -> ~str { return if prec == 0u && num == 0u { ~"" } else { @@ -380,16 +383,16 @@ mod rt { } else { move s } }; } - pure fn get_int_precision(cv: Conv) -> uint { + pub pure fn get_int_precision(cv: Conv) -> uint { return match cv.precision { CountIs(c) => c as uint, CountImplied => 1u }; } - enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat } + pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat } - impl PadMode : Eq { + pub impl PadMode : Eq { pure fn eq(other: &PadMode) -> bool { match (self, (*other)) { (PadSigned, PadSigned) => true, @@ -405,7 +408,7 @@ mod rt { pure fn ne(other: &PadMode) -> bool { !self.eq(other) } } - fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str { + pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str { let mut s = move s; // sadtimes let uwidth : uint = match cv.width { CountImplied => return s, @@ -458,209 +461,13 @@ mod rt { } return padstr + s; } - pure fn have_flag(flags: u32, f: u32) -> bool { - flags & f != 0 - } -} - -// Remove after snapshot - -// Functions used by the fmt extension at runtime. For now there are a lot of -// decisions made a runtime. If it proves worthwhile then some of these -// conditions can be evaluated at compile-time. For now though it's cleaner to -// implement it 0this way, I think. -mod rt2 { - #[legacy_exports]; - const flag_none : u32 = 0u32; - const flag_left_justify : u32 = 0b00000000000000000000000000000001u32; - const flag_left_zero_pad : u32 = 0b00000000000000000000000000000010u32; - const flag_space_for_sign : u32 = 0b00000000000000000000000000000100u32; - const flag_sign_always : u32 = 0b00000000000000000000000000001000u32; - const flag_alternate : u32 = 0b00000000000000000000000000010000u32; - - enum Count { CountIs(int), CountImplied, } - enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, } - - type Conv = {flags: u32, width: Count, precision: Count, ty: Ty}; - - pure fn conv_int(cv: Conv, i: int) -> ~str { - let radix = 10; - let prec = get_int_precision(cv); - let mut s : ~str = int_to_str_prec(i, radix, prec); - if 0 <= i { - if have_flag(cv.flags, flag_sign_always) { - unsafe { str::unshift_char(&mut s, '+') }; - } else if have_flag(cv.flags, flag_space_for_sign) { - unsafe { str::unshift_char(&mut s, ' ') }; - } - } - return unsafe { pad(cv, s, PadSigned) }; - } - pure fn conv_uint(cv: Conv, u: uint) -> ~str { - let prec = get_int_precision(cv); - let mut rs = - match cv.ty { - TyDefault => uint_to_str_prec(u, 10u, prec), - TyHexLower => uint_to_str_prec(u, 16u, prec), - TyHexUpper => str::to_upper(uint_to_str_prec(u, 16u, prec)), - TyBits => uint_to_str_prec(u, 2u, prec), - TyOctal => uint_to_str_prec(u, 8u, prec) - }; - return unsafe { pad(cv, rs, PadUnsigned) }; - } - pure fn conv_bool(cv: Conv, b: bool) -> ~str { - let s = if b { ~"true" } else { ~"false" }; - // run the boolean conversion through the string conversion logic, - // giving it the same rules for precision, etc. - return conv_str(cv, s); - } - pure fn conv_char(cv: Conv, c: char) -> ~str { - let mut s = str::from_char(c); - return unsafe { pad(cv, s, PadNozero) }; - } - pure fn conv_str(cv: Conv, s: &str) -> ~str { - // For strings, precision is the maximum characters - // displayed - let mut unpadded = match cv.precision { - CountImplied => s.to_unique(), - CountIs(max) => if max as uint < str::char_len(s) { - str::substr(s, 0u, max as uint) - } else { - s.to_unique() - } - }; - return unsafe { pad(cv, unpadded, PadNozero) }; - } - pure fn conv_float(cv: Conv, f: float) -> ~str { - let (to_str, digits) = match cv.precision { - CountIs(c) => (float::to_str_exact, c as uint), - CountImplied => (float::to_str, 6u) - }; - let mut s = unsafe { to_str(f, digits) }; - if 0.0 <= f { - if have_flag(cv.flags, flag_sign_always) { - s = ~"+" + s; - } else if have_flag(cv.flags, flag_space_for_sign) { - s = ~" " + s; - } - } - return unsafe { pad(cv, s, PadFloat) }; - } - pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str { - let s = sys::log_str(v); - return conv_str(cv, s); - } - - // Convert an int to string with minimum number of digits. If precision is - // 0 and num is 0 then the result is the empty string. - pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str { - return if num < 0 { - ~"-" + uint_to_str_prec(-num as uint, radix, prec) - } else { uint_to_str_prec(num as uint, radix, prec) }; - } - - // Convert a uint to string with a minimum number of digits. If precision - // is 0 and num is 0 then the result is the empty string. Could move this - // to uint: but it doesn't seem all that useful. - pure fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str { - return if prec == 0u && num == 0u { - ~"" - } else { - let s = uint::to_str(num, radix); - let len = str::char_len(s); - if len < prec { - let diff = prec - len; - let pad = str::from_chars(vec::from_elem(diff, '0')); - pad + s - } else { move s } - }; - } - pure fn get_int_precision(cv: Conv) -> uint { - return match cv.precision { - CountIs(c) => c as uint, - CountImplied => 1u - }; - } - - enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat } - - impl PadMode : Eq { - pure fn eq(other: &PadMode) -> bool { - match (self, (*other)) { - (PadSigned, PadSigned) => true, - (PadUnsigned, PadUnsigned) => true, - (PadNozero, PadNozero) => true, - (PadFloat, PadFloat) => true, - (PadSigned, _) => false, - (PadUnsigned, _) => false, - (PadNozero, _) => false, - (PadFloat, _) => false - } - } - pure fn ne(other: &PadMode) -> bool { !self.eq(other) } - } - - fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str { - let mut s = move s; // sadtimes - let uwidth : uint = match cv.width { - CountImplied => return s, - CountIs(width) => { - // FIXME: width should probably be uint (see Issue #1996) - width as uint - } - }; - let strlen = str::char_len(s); - if uwidth <= strlen { return s; } - let mut padchar = ' '; - let diff = uwidth - strlen; - if have_flag(cv.flags, flag_left_justify) { - let padstr = str::from_chars(vec::from_elem(diff, padchar)); - return s + padstr; - } - let {might_zero_pad, signed} = match mode { - PadNozero => {might_zero_pad:false, signed:false}, - PadSigned => {might_zero_pad:true, signed:true }, - PadFloat => {might_zero_pad:true, signed:true}, - PadUnsigned => {might_zero_pad:true, signed:false} - }; - pure fn have_precision(cv: Conv) -> bool { - return match cv.precision { CountImplied => false, _ => true }; - } - let zero_padding = { - if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) && - (!have_precision(cv) || mode == PadFloat) { - padchar = '0'; - true - } else { - false - } - }; - let padstr = str::from_chars(vec::from_elem(diff, padchar)); - // This is completely heinous. If we have a signed value then - // potentially rip apart the intermediate result and insert some - // zeros. It may make sense to convert zero padding to a precision - // instead. - - if signed && zero_padding && s.len() > 0 { - let head = str::shift_char(&mut s); - if head == '+' || head == '-' || head == ' ' { - let headstr = str::from_chars(vec::from_elem(1u, head)); - return headstr + padstr + s; - } - else { - str::unshift_char(&mut s, head); - } - } - return padstr + s; - } - pure fn have_flag(flags: u32, f: u32) -> bool { + pub pure fn have_flag(flags: u32, f: u32) -> bool { flags & f != 0 } } #[cfg(test)] mod test { - #[legacy_exports]; #[test] fn fmt_slice() { let s = "abc"; diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 11b6a2c0135..efd5ff65aa5 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -1,5 +1,6 @@ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +// tjc: allowing deprecated modes due to function issue. +// can re-forbid them after snapshot #[forbid(deprecated_pattern)]; /*! @@ -86,7 +87,7 @@ pub fn from_port<A:Send>(port: future_pipe::client::waiting<A>) -> } } -pub fn from_fn<A>(+f: ~fn() -> A) -> Future<A> { +pub fn from_fn<A>(f: ~fn() -> A) -> Future<A> { /*! * Create a future from a function. * @@ -98,7 +99,7 @@ pub fn from_fn<A>(+f: ~fn() -> A) -> Future<A> { Future {state: Pending(move f)} } -pub fn spawn<A:Send>(+blk: fn~() -> A) -> Future<A> { +pub fn spawn<A:Send>(blk: fn~() -> A) -> Future<A> { /*! * Create a future from a unique closure. * diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 6942d38d5d3..8cb689fd286 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use T = inst::T; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 2efc96933da..865b8013fb0 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -4,6 +4,9 @@ Basic input/output */ +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use result::Result; use cmp::Eq; diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs index 09bfe2eff36..6de6633f5f8 100644 --- a/src/libcore/iter-trait.rs +++ b/src/libcore/iter-trait.rs @@ -2,7 +2,8 @@ // workaround our lack of traits and lack of macros. See core.{rc,rs} for // how this file is used. -#[warn(deprecated_mode)]; +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; use cmp::{Eq, Ord}; use inst::{IMPL_T, EACH, SIZE_HINT}; diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index bf3e91f7071..322012db135 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -4,6 +4,9 @@ The iteration traits and common implementation */ +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use cmp::{Eq, Ord}; /// A function used to initialize the elements of a sequence diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index 5948c630cd8..b314ad61ee2 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -8,7 +8,7 @@ dynamic checks: your program will fail if you attempt to perform mutation when the data structure should be immutable. */ -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use util::with; diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 038c117b8be..7c6bcf5bd51 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1,5 +1,8 @@ // Core operators and kinds. +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + #[lang="const"] pub trait Const { // Empty. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 6bd326186cb..c60b7b401cc 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -1,15 +1,37 @@ /*! - * Operations on the ubiquitous `option` type. - * - * Type `option` represents an optional value. - * - * Every `Option<T>` value can either be `Some(T)` or `none`. Where in other - * languages you might use a nullable type, in Rust you would use an option - * type. - */ - -// NB: transitionary, de-mode-ing. -#[warn(deprecated_mode)]; + +Operations on the ubiquitous `Option` type. + +Type `Option` represents an optional value. + +Every `Option<T>` value can either be `Some(T)` or `None`. Where in other +languages you might use a nullable type, in Rust you would use an option +type. + +Options are most commonly used with pattern matching to query the presence +of a value and take action, always accounting for the `None` case. + +# Example + +~~~ +let msg = Some(~"howdy"); + +// Take a reference to the contained string +match msg { + Some(ref m) => io::println(m), + None => () +} + +// Remove the contained string, destroying the Option +let unwrapped_msg = match move msg { + Some(move m) => m, + None => ~"default message" +}; +~~~ + +*/ + +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cmp::Eq; @@ -22,12 +44,19 @@ pub enum Option<T> { pub pure fn get<T: Copy>(opt: &Option<T>) -> T { /*! - * Gets the value out of an option - * - * # Failure - * - * Fails if the value equals `none` - */ + Gets the value out of an option + + # Failure + + Fails if the value equals `None` + + # Safety note + + In general, because this function may fail, its use is discouraged + (calling `get` on `None` is akin to dereferencing a null pointer). + Instead, prefer to use pattern matching and handle the `None` + case explicitly. + */ match *opt { Some(copy x) => return x, @@ -37,11 +66,18 @@ pub pure fn get<T: Copy>(opt: &Option<T>) -> T { pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T { /*! - * Gets an immutable reference to the value inside an option. - * - * # Failure - * - * Fails if the value equals `none` + Gets an immutable reference to the value inside an option. + + # Failure + + Fails if the value equals `None` + + # Safety note + + In general, because this function may fail, its use is discouraged + (calling `get` on `None` is akin to dereferencing a null pointer). + Instead, prefer to use pattern matching and handle the `None` + case explicitly. */ match *opt { Some(ref x) => x, @@ -154,10 +190,20 @@ pub pure fn iter<T>(opt: &Option<T>, f: fn(x: &T)) { #[inline(always)] pub pure fn unwrap<T>(opt: Option<T>) -> T { /*! - * Moves a value out of an option type and returns it. - * - * Useful primarily for getting strings, vectors and unique pointers out - * of option types without copying them. + Moves a value out of an option type and returns it. + + Useful primarily for getting strings, vectors and unique pointers out + of option types without copying them. + + # Failure + + Fails if the value equals `None`. + + # Safety note + + In general, because this function may fail, its use is discouraged. + Instead, prefer to use pattern matching and handle the `None` + case explicitly. */ match move opt { Some(move x) => move x, @@ -165,9 +211,16 @@ pub pure fn unwrap<T>(opt: Option<T>) -> T { } } -/// The ubiquitous option dance. #[inline(always)] pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T { + /*! + The option dance. Moves a value out of an option type and returns it, + replacing the original with `None`. + + # Failure + + Fails if the value equals `None`. + */ if opt.is_none() { fail ~"option::swap_unwrap none" } unwrap(util::replace(opt, None)) } @@ -201,18 +254,38 @@ impl<T> &Option<T> { pure fn iter(f: fn(x: &T)) { iter(self, f) } /// Maps a `some` value from one type to another by reference pure fn map<U>(f: fn(x: &T) -> U) -> Option<U> { map(self, f) } - /// Gets an immutable reference to the value inside a `some`. + /** + Gets an immutable reference to the value inside an option. + + # Failure + + Fails if the value equals `None` + + # Safety note + + In general, because this function may fail, its use is discouraged + (calling `get` on `None` is akin to dereferencing a null pointer). + Instead, prefer to use pattern matching and handle the `None` + case explicitly. + */ pure fn get_ref() -> &self/T { get_ref(self) } } impl<T: Copy> Option<T> { /** - * Gets the value out of an option - * - * # Failure - * - * Fails if the value equals `none` - */ + Gets the value out of an option + + # Failure + + Fails if the value equals `None` + + # Safety note + + In general, because this function may fail, its use is discouraged + (calling `get` on `None` is akin to dereferencing a null pointer). + Instead, prefer to use pattern matching and handle the `None` + case explicitly. + */ pure fn get() -> T { get(&self) } pure fn get_default(def: T) -> T { get_default(&self, def) } /** @@ -252,10 +325,10 @@ impl<T: Eq> Option<T> : Eq { #[test] fn test_unwrap_ptr() { let x = ~0; - let addr_x = ptr::p2::addr_of(&(*x)); + let addr_x = ptr::addr_of(&(*x)); let opt = Some(x); let y = unwrap(opt); - let addr_y = ptr::p2::addr_of(&(*y)); + let addr_y = ptr::addr_of(&(*y)); assert addr_x == addr_y; } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 68571da3a1e..3fd98e7f298 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -// tjc: re-forbid +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; /*! @@ -132,7 +132,7 @@ mod global_env { let env_ch = get_global_env_chan(); let po = comm::Port(); comm::send(env_ch, MsgGetEnv(str::from_slice(n), - comm::Chan(po))); + comm::Chan(&po))); comm::recv(po) } @@ -141,14 +141,14 @@ mod global_env { let po = comm::Port(); comm::send(env_ch, MsgSetEnv(str::from_slice(n), str::from_slice(v), - comm::Chan(po))); + comm::Chan(&po))); comm::recv(po) } pub fn env() -> ~[(~str,~str)] { let env_ch = get_global_env_chan(); let po = comm::Port(); - comm::send(env_ch, MsgEnv(comm::Chan(po))); + comm::send(env_ch, MsgEnv(comm::Chan(&po))); comm::recv(po) } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index e34c0db35e9..791c6bccde8 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -73,7 +73,8 @@ bounded and unbounded protocols allows for less code duplication. */ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +// tjc: allowing deprecated modes due to function issue, +// re-forbid after snapshot #[forbid(deprecated_pattern)]; use cmp::Eq; @@ -859,7 +860,7 @@ endpoint is passed to the new task. pub fn spawn_service<T: Send, Tb: Send>( init: extern fn() -> (SendPacketBuffered<T, Tb>, RecvPacketBuffered<T, Tb>), - +service: fn~(v: RecvPacketBuffered<T, Tb>)) + service: fn~(v: RecvPacketBuffered<T, Tb>)) -> SendPacketBuffered<T, Tb> { let (client, server) = init(); @@ -883,7 +884,7 @@ receive state. pub fn spawn_service_recv<T: Send, Tb: Send>( init: extern fn() -> (RecvPacketBuffered<T, Tb>, SendPacketBuffered<T, Tb>), - +service: fn~(v: SendPacketBuffered<T, Tb>)) + service: fn~(v: SendPacketBuffered<T, Tb>)) -> RecvPacketBuffered<T, Tb> { let (client, server) = init(); diff --git a/src/libcore/private.rs b/src/libcore/private.rs index c1b2b32edaf..c4ef136a592 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -1,5 +1,6 @@ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +// tjc: Re-forbid deprecated modes once a snapshot fixes the +// function problem #[forbid(deprecated_pattern)]; #[doc(hidden)]; @@ -45,7 +46,7 @@ type GlobalPtr = *libc::uintptr_t; pub unsafe fn chan_from_global_ptr<T: Send>( global: GlobalPtr, task_fn: fn() -> task::TaskBuilder, - +f: fn~(comm::Port<T>) + f: fn~(comm::Port<T>) ) -> comm::Chan<T> { enum Msg { @@ -63,7 +64,7 @@ pub unsafe fn chan_from_global_ptr<T: Send>( let (setup_po, setup_ch) = do task_fn().spawn_conversation |move f, setup_po, setup_ch| { let po = comm::Port::<T>(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); comm::send(setup_ch, ch); // Wait to hear if we are the official instance of @@ -109,7 +110,7 @@ pub fn test_from_global_chan1() { // The global channel let globchan = 0; - let globchanp = ptr::p2::addr_of(&globchan); + let globchanp = ptr::addr_of(&globchan); // Create the global channel, attached to a new task let ch = unsafe { @@ -122,7 +123,7 @@ pub fn test_from_global_chan1() { }; // Talk to it let po = comm::Port(); - comm::send(ch, comm::Chan(po)); + comm::send(ch, comm::Chan(&po)); assert comm::recv(po) == true; // This one just reuses the previous channel @@ -135,7 +136,7 @@ pub fn test_from_global_chan1() { // Talk to the original global task let po = comm::Port(); - comm::send(ch, comm::Chan(po)); + comm::send(ch, comm::Chan(&po)); assert comm::recv(po) == true; } @@ -145,10 +146,10 @@ pub fn test_from_global_chan2() { for iter::repeat(100) { // The global channel let globchan = 0; - let globchanp = ptr::p2::addr_of(&globchan); + let globchanp = ptr::addr_of(&globchan); let resultpo = comm::Port(); - let resultch = comm::Chan(resultpo); + let resultch = comm::Chan(&resultpo); // Spawn a bunch of tasks that all want to compete to // create the global channel @@ -165,7 +166,7 @@ pub fn test_from_global_chan2() { } }; let po = comm::Port(); - comm::send(ch, comm::Chan(po)); + comm::send(ch, comm::Chan(&po)); // We are The winner if our version of the // task was installed let winner = comm::recv(po); @@ -203,7 +204,7 @@ pub fn test_from_global_chan2() { */ pub unsafe fn weaken_task(f: fn(comm::Port<()>)) { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); unsafe { rustrt::rust_task_weaken(cast::reinterpret_cast(&ch)); } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index fad7eddd2d8..ffa11dcfc75 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -1,5 +1,8 @@ //! Unsafe pointer utility functions +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use cmp::{Eq, Ord}; use libc::{c_void, size_t}; @@ -28,12 +31,6 @@ extern mod rusti { #[inline(always)] pub pure fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } } -pub mod p2 { - /// Get an unsafe pointer to a value - #[inline(always)] - pub pure fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } } -} - /// Get an unsafe mut pointer to a value #[inline(always)] pub pure fn mut_addr_of<T>(val: &T) -> *mut T { diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 32f77a533a6..786fed88de9 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -1,7 +1,7 @@ //! Random number generation // NB: transitional, de-mode-ing. -#[warn(deprecated_mode)]; +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; #[allow(non_camel_case_types)] // runtime type @@ -310,7 +310,7 @@ pub fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng { // used to make space in TLS for a random number generator -fn tls_rng_state(+_v: @RandRes) {} +fn tls_rng_state(_v: @RandRes) {} /** * Gives back a lazily initialized task-local random number generator, diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs index 41006e1dfb5..505804b3da8 100644 --- a/src/libcore/reflect.rs +++ b/src/libcore/reflect.rs @@ -4,6 +4,9 @@ Runtime type reflection */ +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor}; use libc::c_void; diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index ff82ed3fb41..0501b032d2d 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -4,6 +4,9 @@ More runtime type reflection */ +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use dvec::DVec; use io::{Writer, WriterUtil}; use libc::c_void; diff --git a/src/libcore/result.rs b/src/libcore/result.rs index e61690d5b2c..39fae8905f9 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1,7 +1,8 @@ //! A type representing either success or failure // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot + +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cmp::Eq; diff --git a/src/libcore/run.rs b/src/libcore/run.rs index f3e98f6ba82..0ff91749209 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -1,5 +1,5 @@ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; //! Process spawning @@ -296,7 +296,7 @@ pub fn program_output(prog: &str, args: &[~str]) -> // or the other. FIXME (#2625): Surely there's a much more // clever way to do this. let p = comm::Port(); - let ch = comm::Chan(p); + let ch = comm::Chan(&p); do task::spawn_sched(task::SingleThreaded) { let errput = readclose(pipe_err.in); comm::send(ch, (2, move errput)); diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 09973148c8c..a88a44701ce 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -3,8 +3,8 @@ #[legacy_modes]; // tjc: remove after snapshot // NB: transitionary, de-mode-ing. -// XXX: Can't do this because frame_address needs a deprecated mode. -//#[forbid(deprecated_mode)]; +// XXX: Can't forbid this because frame_address needs a deprecated mode. +#[allow(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cast::reinterpret_cast; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index cf996a8b254..285b6114957 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -7,8 +7,8 @@ * some heavy-duty uses, try std::rope. */ -#[warn(deprecated_mode)]; -#[warn(deprecated_pattern)]; +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; use cmp::{Eq, Ord}; use libc::size_t; diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 5ca35a7f562..8d7791d18d9 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -1,5 +1,6 @@ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +// tjc: Deprecated modes allowed because of function arg issue +// in task::spawn. Re-forbid after snapshot. #[forbid(deprecated_pattern)]; /*! @@ -219,7 +220,7 @@ pub type TaskOpts = { // FIXME (#2585): Replace the 'consumed' bit with move mode on self pub enum TaskBuilder = { opts: TaskOpts, - gen_body: fn@(+v: fn~()) -> fn~(), + gen_body: fn@(v: fn~()) -> fn~(), can_not_copy: Option<util::NonCopyable>, mut consumed: bool, }; @@ -232,7 +233,7 @@ pub enum TaskBuilder = { pub fn task() -> TaskBuilder { TaskBuilder({ opts: default_task_opts(), - gen_body: |+body| move body, // Identity function + gen_body: |body| move body, // Identity function can_not_copy: None, mut consumed: false, }) @@ -409,7 +410,7 @@ impl TaskBuilder { * generator by applying the task body which results from the * existing body generator to the new body generator. */ - fn add_wrapper(wrapper: fn@(+v: fn~()) -> fn~()) -> TaskBuilder { + fn add_wrapper(wrapper: fn@(v: fn~()) -> fn~()) -> TaskBuilder { let prev_gen_body = self.gen_body; let notify_chan = if self.opts.notify_chan.is_none() { None @@ -441,7 +442,7 @@ impl TaskBuilder { * When spawning into a new scheduler, the number of threads requested * must be greater than zero. */ - fn spawn(+f: fn~()) { + fn spawn(f: fn~()) { let notify_chan = if self.opts.notify_chan.is_none() { None } else { @@ -459,7 +460,7 @@ impl TaskBuilder { spawn::spawn_raw(move opts, x.gen_body(move f)); } /// Runs a task, while transfering ownership of one argument to the child. - fn spawn_with<A: Send>(arg: A, +f: fn~(+v: A)) { + fn spawn_with<A: Send>(arg: A, f: fn~(v: A)) { let arg = ~mut Some(move arg); do self.spawn |move arg, move f| { f(option::swap_unwrap(arg)) @@ -477,12 +478,12 @@ impl TaskBuilder { * otherwise be required to establish communication from the parent * to the child. */ - fn spawn_listener<A: Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> { + fn spawn_listener<A: Send>(f: fn~(comm::Port<A>)) -> comm::Chan<A> { let setup_po = comm::Port(); - let setup_ch = comm::Chan(setup_po); + let setup_ch = comm::Chan(&setup_po); do self.spawn |move f| { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); comm::send(setup_ch, ch); f(move po); } @@ -493,10 +494,10 @@ impl TaskBuilder { * Runs a new task, setting up communication in both directions */ fn spawn_conversation<A: Send, B: Send> - (+f: fn~(comm::Port<A>, comm::Chan<B>)) + (f: fn~(comm::Port<A>, comm::Chan<B>)) -> (comm::Port<B>, comm::Chan<A>) { let from_child = comm::Port(); - let to_parent = comm::Chan(from_child); + let to_parent = comm::Chan(&from_child); let to_child = do self.spawn_listener |move f, from_parent| { f(from_parent, to_parent) }; @@ -516,9 +517,9 @@ impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn try<T: Send>(+f: fn~() -> T) -> Result<T,()> { + fn try<T: Send>(f: fn~() -> T) -> Result<T,()> { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); let mut result = None; let fr_task_builder = self.future_result(|+r| { @@ -555,7 +556,7 @@ pub fn default_task_opts() -> TaskOpts { /* Spawn convenience functions */ -pub fn spawn(+f: fn~()) { +pub fn spawn(f: fn~()) { /*! * Creates and executes a new child task * @@ -568,7 +569,7 @@ pub fn spawn(+f: fn~()) { task().spawn(move f) } -pub fn spawn_unlinked(+f: fn~()) { +pub fn spawn_unlinked(f: fn~()) { /*! * Creates a child task unlinked from the current one. If either this * task or the child task fails, the other will not be killed. @@ -577,7 +578,7 @@ pub fn spawn_unlinked(+f: fn~()) { task().unlinked().spawn(move f) } -pub fn spawn_supervised(+f: fn~()) { +pub fn spawn_supervised(f: fn~()) { /*! * Creates a child task unlinked from the current one. If either this * task or the child task fails, the other will not be killed. @@ -586,7 +587,7 @@ pub fn spawn_supervised(+f: fn~()) { task().supervised().spawn(move f) } -pub fn spawn_with<A:Send>(+arg: A, +f: fn~(+v: A)) { +pub fn spawn_with<A:Send>(arg: A, f: fn~(v: A)) { /*! * Runs a task, while transfering ownership of one argument to the * child. @@ -600,7 +601,7 @@ pub fn spawn_with<A:Send>(+arg: A, +f: fn~(+v: A)) { task().spawn_with(move arg, move f) } -pub fn spawn_listener<A:Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> { +pub fn spawn_listener<A:Send>(f: fn~(comm::Port<A>)) -> comm::Chan<A> { /*! * Runs a new task while providing a channel from the parent to the child * @@ -611,7 +612,7 @@ pub fn spawn_listener<A:Send>(+f: fn~(comm::Port<A>)) -> comm::Chan<A> { } pub fn spawn_conversation<A: Send, B: Send> - (+f: fn~(comm::Port<A>, comm::Chan<B>)) + (f: fn~(comm::Port<A>, comm::Chan<B>)) -> (comm::Port<B>, comm::Chan<A>) { /*! * Runs a new task, setting up communication in both directions @@ -622,7 +623,7 @@ pub fn spawn_conversation<A: Send, B: Send> task().spawn_conversation(move f) } -pub fn spawn_sched(mode: SchedMode, +f: fn~()) { +pub fn spawn_sched(mode: SchedMode, f: fn~()) { /*! * Creates a new scheduler and executes a task on it * @@ -639,7 +640,7 @@ pub fn spawn_sched(mode: SchedMode, +f: fn~()) { task().sched_mode(mode).spawn(move f) } -pub fn try<T:Send>(+f: fn~() -> T) -> Result<T,()> { +pub fn try<T:Send>(f: fn~() -> T) -> Result<T,()> { /*! * Execute a function in another task and return either the return value * of the function or result::err. @@ -772,7 +773,7 @@ fn test_cant_dup_task_builder() { #[test] #[ignore(cfg(windows))] fn test_spawn_unlinked_unsup_no_fail_down() { // grandchild sends on a port let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); do spawn_unlinked { do spawn_unlinked { // Give middle task a chance to fail-but-not-kill-us. @@ -802,7 +803,7 @@ fn test_spawn_unlinked_sup_fail_down() { #[test] #[should_fail] #[ignore(cfg(windows))] fn test_spawn_linked_sup_fail_up() { // child fails; parent fails let po = comm::Port::<()>(); - let _ch = comm::Chan(po); + let _ch = comm::Chan(&po); // Unidirectional "parenting" shouldn't override bidirectional linked. // We have to cheat with opts - the interface doesn't support them because // they don't make sense (redundant with task().supervised()). @@ -845,7 +846,7 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails #[test] #[should_fail] #[ignore(cfg(windows))] fn test_spawn_linked_unsup_fail_up() { // child fails; parent fails let po = comm::Port::<()>(); - let _ch = comm::Chan(po); + let _ch = comm::Chan(&po); // Default options are to spawn linked & unsupervised. do spawn { fail; } comm::recv(po); // We should get punted awake @@ -917,7 +918,7 @@ fn test_spawn_linked_sup_propagate_sibling() { #[test] fn test_run_basic() { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); do task().spawn { comm::send(ch, ()); } @@ -927,7 +928,7 @@ fn test_run_basic() { #[test] fn test_add_wrapper() { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); let b0 = task(); let b1 = do b0.add_wrapper |body| { fn~() { @@ -961,7 +962,7 @@ fn test_back_to_the_future_result() { #[test] fn test_spawn_listiner_bidi() { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); let ch = do spawn_listener |po| { // Now the child has a port called 'po' to read from and // an environment-captured channel called 'ch'. @@ -1017,7 +1018,7 @@ fn test_spawn_sched_no_threads() { #[test] fn test_spawn_sched() { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); fn f(i: int, ch: comm::Chan<()>) { let parent_sched_id = rt::rust_get_sched_id(); @@ -1041,7 +1042,7 @@ fn test_spawn_sched() { #[test] fn test_spawn_sched_childs_on_same_sched() { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); do spawn_sched(SingleThreaded) { let parent_sched_id = rt::rust_get_sched_id(); @@ -1075,9 +1076,9 @@ fn test_spawn_sched_blocking() { for iter::repeat(20u) { let start_po = comm::Port(); - let start_ch = comm::Chan(start_po); + let start_ch = comm::Chan(&start_po); let fin_po = comm::Port(); - let fin_ch = comm::Chan(fin_po); + let fin_ch = comm::Chan(&fin_po); let lock = testrt::rust_dbg_lock_create(); @@ -1105,12 +1106,12 @@ fn test_spawn_sched_blocking() { } let setup_po = comm::Port(); - let setup_ch = comm::Chan(setup_po); + let setup_ch = comm::Chan(&setup_po); let parent_po = comm::Port(); - let parent_ch = comm::Chan(parent_po); + let parent_ch = comm::Chan(&parent_po); do spawn { let child_po = comm::Port(); - comm::send(setup_ch, comm::Chan(child_po)); + comm::send(setup_ch, comm::Chan(&child_po)); pingpong(child_po, parent_ch); }; @@ -1126,15 +1127,15 @@ fn test_spawn_sched_blocking() { } #[cfg(test)] -fn avoid_copying_the_body(spawnfn: fn(+v: fn~())) { +fn avoid_copying_the_body(spawnfn: fn(v: fn~())) { let p = comm::Port::<uint>(); - let ch = comm::Chan(p); + let ch = comm::Chan(&p); let x = ~1; - let x_in_parent = ptr::p2::addr_of(&(*x)) as uint; + let x_in_parent = ptr::addr_of(&(*x)) as uint; do spawnfn { - let x_in_child = ptr::p2::addr_of(&(*x)) as uint; + let x_in_child = ptr::addr_of(&(*x)) as uint; comm::send(ch, x_in_child); } @@ -1149,7 +1150,7 @@ fn test_avoid_copying_the_body_spawn() { #[test] fn test_avoid_copying_the_body_spawn_listener() { - do avoid_copying_the_body |+f| { + do avoid_copying_the_body |f| { spawn_listener(fn~(move f, _po: comm::Port<int>) { f(); }); @@ -1167,7 +1168,7 @@ fn test_avoid_copying_the_body_task_spawn() { #[test] fn test_avoid_copying_the_body_spawn_listener_1() { - do avoid_copying_the_body |+f| { + do avoid_copying_the_body |f| { task().spawn_listener(fn~(move f, _po: comm::Port<int>) { f(); }); @@ -1195,7 +1196,7 @@ fn test_avoid_copying_the_body_unlinked() { #[test] fn test_platform_thread() { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); do task().sched_mode(PlatformThread).spawn { comm::send(ch, ()); } diff --git a/src/libcore/task/local_data.rs b/src/libcore/task/local_data.rs index 2130354229a..99101189315 100644 --- a/src/libcore/task/local_data.rs +++ b/src/libcore/task/local_data.rs @@ -78,7 +78,7 @@ pub unsafe fn local_data_modify<T: Owned>( } #[test] -pub fn test_tls_multitask() unsafe { +fn test_tls_multitask() unsafe { fn my_key(_x: @~str) { } local_data_set(my_key, @~"parent data"); do task::spawn unsafe { @@ -94,7 +94,7 @@ pub fn test_tls_multitask() unsafe { } #[test] -pub fn test_tls_overwrite() unsafe { +fn test_tls_overwrite() unsafe { fn my_key(_x: @~str) { } local_data_set(my_key, @~"first data"); local_data_set(my_key, @~"next data"); // Shouldn't leak. @@ -102,7 +102,7 @@ pub fn test_tls_overwrite() unsafe { } #[test] -pub fn test_tls_pop() unsafe { +fn test_tls_pop() unsafe { fn my_key(_x: @~str) { } local_data_set(my_key, @~"weasel"); assert *(local_data_pop(my_key).get()) == ~"weasel"; @@ -111,7 +111,7 @@ pub fn test_tls_pop() unsafe { } #[test] -pub fn test_tls_modify() unsafe { +fn test_tls_modify() unsafe { fn my_key(_x: @~str) { } local_data_modify(my_key, |data| { match data { @@ -130,7 +130,7 @@ pub fn test_tls_modify() unsafe { } #[test] -pub fn test_tls_crust_automorestack_memorial_bug() unsafe { +fn test_tls_crust_automorestack_memorial_bug() unsafe { // This might result in a stack-canary clobber if the runtime fails to set // sp_limit to 0 when calling the cleanup extern - it might automatically // jump over to the rust stack, which causes next_c_sp to get recorded as @@ -143,7 +143,7 @@ pub fn test_tls_crust_automorestack_memorial_bug() unsafe { } #[test] -pub fn test_tls_multiple_types() unsafe { +fn test_tls_multiple_types() unsafe { fn str_key(_x: @~str) { } fn box_key(_x: @@()) { } fn int_key(_x: @int) { } @@ -155,7 +155,7 @@ pub fn test_tls_multiple_types() unsafe { } #[test] -pub fn test_tls_overwrite_multiple_types() { +fn test_tls_overwrite_multiple_types() { fn str_key(_x: @~str) { } fn box_key(_x: @@()) { } fn int_key(_x: @int) { } @@ -171,7 +171,7 @@ pub fn test_tls_overwrite_multiple_types() { #[test] #[should_fail] #[ignore(cfg(windows))] -pub fn test_tls_cleanup_on_failure() unsafe { +fn test_tls_cleanup_on_failure() unsafe { fn str_key(_x: @~str) { } fn box_key(_x: @@()) { } fn int_key(_x: @int) { } diff --git a/src/libcore/task/local_data_priv.rs b/src/libcore/task/local_data_priv.rs index 9849ce7b68c..e84e4dad164 100644 --- a/src/libcore/task/local_data_priv.rs +++ b/src/libcore/task/local_data_priv.rs @@ -17,11 +17,11 @@ impl LocalData: Eq { // We use dvec because it's the best data structure in core. If TLS is used // heavily in future, this could be made more efficient with a proper map. -pub type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); +type TaskLocalElement = (*libc::c_void, *libc::c_void, LocalData); // Has to be a pointer at outermost layer; the foreign call returns void *. -pub type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>; +type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>; -pub extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { +extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { assert !map_ptr.is_null(); // Get and keep the single reference that was created at the beginning. let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr); @@ -29,7 +29,7 @@ pub extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { } // Gets the map from the runtime. Lazily initialises if not done so already. -pub unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { +unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { // Relies on the runtime initialising the pointer to null. // NOTE: The map's box lives in TLS invisibly referenced once. Each time @@ -52,7 +52,7 @@ pub unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { } } -pub unsafe fn key_to_key_value<T: Owned>( +unsafe fn key_to_key_value<T: Owned>( key: LocalDataKey<T>) -> *libc::c_void { // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr. @@ -62,7 +62,7 @@ pub unsafe fn key_to_key_value<T: Owned>( } // If returning Some(..), returns with @T with the map's reference. Careful! -pub unsafe fn local_data_lookup<T: Owned>( +unsafe fn local_data_lookup<T: Owned>( map: TaskLocalMap, key: LocalDataKey<T>) -> Option<(uint, *libc::c_void)> { @@ -80,7 +80,7 @@ pub unsafe fn local_data_lookup<T: Owned>( } } -pub unsafe fn local_get_helper<T: Owned>( +unsafe fn local_get_helper<T: Owned>( task: *rust_task, key: LocalDataKey<T>, do_pop: bool) -> Option<@T> { diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 0e1284da3bc..6eaace1fa1a 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -61,6 +61,7 @@ ****************************************************************************/ #[doc(hidden)]; // FIXME #3538 +#[warn(deprecated_mode)]; use rt::rust_task; use rt::rust_closure; @@ -69,16 +70,16 @@ macro_rules! move_it ( { $x:expr } => { unsafe { let y <- *ptr::addr_of(&($x)); move y } } ) -pub type TaskSet = send_map::linear::LinearMap<*rust_task,()>; +type TaskSet = send_map::linear::LinearMap<*rust_task,()>; -pub fn new_taskset() -> TaskSet { +fn new_taskset() -> TaskSet { send_map::linear::LinearMap() } -pub fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { +fn taskset_insert(tasks: &mut TaskSet, task: *rust_task) { let didnt_overwrite = tasks.insert(task, ()); assert didnt_overwrite; } -pub fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { +fn taskset_remove(tasks: &mut TaskSet, task: *rust_task) { let was_present = tasks.remove(&task); assert was_present; } @@ -87,7 +88,7 @@ pub fn taskset_each(tasks: &TaskSet, blk: fn(v: *rust_task) -> bool) { } // One of these per group of linked-failure tasks. -pub type TaskGroupData = { +type TaskGroupData = { // All tasks which might kill this group. When this is empty, the group // can be "GC"ed (i.e., its link in the ancestor list can be removed). mut members: TaskSet, @@ -95,12 +96,12 @@ pub type TaskGroupData = { // tasks in this group. mut descendants: TaskSet, }; -pub type TaskGroupArc = private::Exclusive<Option<TaskGroupData>>; +type TaskGroupArc = private::Exclusive<Option<TaskGroupData>>; -pub type TaskGroupInner = &mut Option<TaskGroupData>; +type TaskGroupInner = &mut Option<TaskGroupData>; // A taskgroup is 'dead' when nothing can cause it to fail; only members can. -pub pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { +pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { (&tg.members).is_empty() } @@ -111,7 +112,7 @@ pub pure fn taskgroup_is_dead(tg: &TaskGroupData) -> bool { // taskgroup which was spawned-unlinked. Tasks from intermediate generations // have references to the middle of the list; when intermediate generations // die, their node in the list will be collected at a descendant's spawn-time. -pub type AncestorNode = { +type AncestorNode = { // Since the ancestor list is recursive, we end up with references to // exclusives within other exclusives. This is dangerous business (if // circular references arise, deadlock and memory leaks are imminent). @@ -124,16 +125,16 @@ pub type AncestorNode = { // Recursive rest of the list. mut ancestors: AncestorList, }; -pub enum AncestorList = Option<private::Exclusive<AncestorNode>>; +enum AncestorList = Option<private::Exclusive<AncestorNode>>; // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. #[inline(always)] -pub fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { +fn access_group<U>(x: &TaskGroupArc, blk: fn(TaskGroupInner) -> U) -> U { unsafe { x.with(blk) } } #[inline(always)] -pub fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>, +fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>, blk: fn(x: &mut AncestorNode) -> U) -> U { unsafe { x.with(blk) } } @@ -146,7 +147,7 @@ pub fn access_ancestors<U>(x: &private::Exclusive<AncestorNode>, // (3) As a bonus, coalesces away all 'dead' taskgroup nodes in the list. // FIXME(#2190): Change Option<fn@(...)> to Option<fn&(...)>, to save on // allocations. Once that bug is fixed, changing the sigil should suffice. -pub fn each_ancestor(list: &mut AncestorList, +fn each_ancestor(list: &mut AncestorList, bail_opt: Option<fn@(TaskGroupInner)>, forward_blk: fn(TaskGroupInner) -> bool) -> bool { @@ -271,7 +272,7 @@ pub fn each_ancestor(list: &mut AncestorList, } // One of these per task. -pub struct TCB { +struct TCB { me: *rust_task, // List of tasks with whose fates this one's is intertwined. tasks: TaskGroupArc, // 'none' means the group has failed. @@ -303,7 +304,7 @@ pub struct TCB { } } -pub fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, +fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, is_main: bool, notifier: Option<AutoNotify>) -> TCB { let notifier = move notifier; @@ -318,7 +319,7 @@ pub fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, } } -pub struct AutoNotify { +struct AutoNotify { notify_chan: Chan<Notification>, mut failed: bool, drop { @@ -327,14 +328,14 @@ pub struct AutoNotify { } } -pub fn AutoNotify(chan: Chan<Notification>) -> AutoNotify { +fn AutoNotify(chan: Chan<Notification>) -> AutoNotify { AutoNotify { notify_chan: chan, failed: true // Un-set above when taskgroup successfully made. } } -pub fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, +fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) -> bool { let newstate = util::replace(state, None); // If 'None', the group was failing. Can't enlist. @@ -350,7 +351,7 @@ pub fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task, } // NB: Runs in destructor/post-exit context. Can't 'fail'. -pub fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, +fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, is_member: bool) { let newstate = util::replace(state, None); // If 'None', already failing and we've already gotten a kill signal. @@ -363,7 +364,7 @@ pub fn leave_taskgroup(state: TaskGroupInner, me: *rust_task, } // NB: Runs in destructor/post-exit context. Can't 'fail'. -pub fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { +fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // NB: We could do the killing iteration outside of the group arc, by // having "let mut newstate" here, swapping inside, and iterating after. // But that would let other exiting tasks fall-through and exit while we @@ -405,7 +406,7 @@ macro_rules! taskgroup_key ( () => (cast::transmute((-2 as uint, 0u))) ) -pub fn gen_child_taskgroup(linked: bool, supervised: bool) +fn gen_child_taskgroup(linked: bool, supervised: bool) -> (TaskGroupArc, AncestorList, bool) { let spawner = rt::rust_get_task(); /*######################################################################* @@ -487,7 +488,7 @@ pub fn gen_child_taskgroup(linked: bool, supervised: bool) } } -pub fn spawn_raw(opts: TaskOpts, +f: fn~()) { +pub fn spawn_raw(opts: TaskOpts, f: fn~()) { let (child_tg, ancestors, is_main) = gen_child_taskgroup(opts.linked, opts.supervised); @@ -532,7 +533,7 @@ pub fn spawn_raw(opts: TaskOpts, +f: fn~()) { fn make_child_wrapper(child: *rust_task, child_arc: TaskGroupArc, ancestors: AncestorList, is_main: bool, notify_chan: Option<Chan<Notification>>, - +f: fn~()) -> fn~() { + f: fn~()) -> fn~() { let child_data = ~mut Some((move child_arc, move ancestors)); return fn~(move notify_chan, move child_data, move f) { // Agh. Get move-mode items into the closure. FIXME (#2829) @@ -636,7 +637,7 @@ pub fn spawn_raw(opts: TaskOpts, +f: fn~()) { #[test] fn test_spawn_raw_simple() { let po = comm::Port(); - let ch = comm::Chan(po); + let ch = comm::Chan(&po); do spawn_raw(default_task_opts()) { comm::send(ch, ()); } diff --git a/src/libcore/util.rs b/src/libcore/util.rs index aa1fe14ba88..6c633f16abf 100644 --- a/src/libcore/util.rs +++ b/src/libcore/util.rs @@ -5,7 +5,7 @@ Miscellaneous helpers for common patterns. */ // NB: transitionary, de-mode-ing. -// tjc: re-forbid deprecated modes after snapshot +#[forbid(deprecated_mode)]; #[forbid(deprecated_pattern)]; use cmp::Eq; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 0c822bd0a03..3a2b73f5b5b 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1,7 +1,7 @@ //! Vectors -#[warn(deprecated_mode)]; -#[warn(deprecated_pattern)]; +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; #[warn(non_camel_case_types)]; use cmp::{Eq, Ord}; @@ -18,9 +18,10 @@ extern mod rustrt { #[abi = "rust-intrinsic"] extern mod rusti { - fn move_val_init<T>(&dst: T, -src: T); + fn move_val_init<T>(dst: &mut T, -src: T); } + /// Returns true if a vector contains no elements pub pure fn is_empty<T>(v: &[const T]) -> bool { as_const_buf(v, |_p, len| len == 0u) @@ -104,7 +105,7 @@ pub pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] { do as_mut_buf(v) |p, _len| { let mut i: uint = 0u; while i < n_elts { - rusti::move_val_init(*ptr::mut_offset(p, i), op(i)); + rusti::move_val_init(&mut(*ptr::mut_offset(p, i)), op(i)); i += 1u; } } @@ -489,7 +490,7 @@ unsafe fn push_fast<T>(v: &mut ~[T], initval: T) { (**repr).unboxed.fill += sys::size_of::<T>(); let p = addr_of(&((**repr).unboxed.data)); let p = ptr::offset(p, fill) as *mut T; - rusti::move_val_init(*p, move initval); + rusti::move_val_init(&mut(*p), move initval); } #[inline(never)] @@ -1769,7 +1770,7 @@ pub mod raw { do as_mut_buf(v) |p, _len| { let mut box2 = None; box2 <-> box; - rusti::move_val_init(*ptr::mut_offset(p, i), + rusti::move_val_init(&mut(*ptr::mut_offset(p, i)), option::unwrap(move box2)); } } @@ -1918,10 +1919,9 @@ impl<A: Copy> &[A]: iter::CopyableIter<A> { } pure fn to_vec() -> ~[A] { iter::to_vec(&self) } - // FIXME--bug in resolve prevents this from working (#2611) - // fn flat_map_to_vec<B:copy,IB:base_iter<B>>(op: fn(A) -> IB) -> ~[B] { - // iter::flat_map_to_vec(self, op) - // } + pure fn flat_map_to_vec<B:Copy,IB:BaseIter<B>>(op: fn(A) -> IB) -> ~[B] { + iter::flat_map_to_vec(&self, op) + } pub pure fn find(p: fn(a: A) -> bool) -> Option<A> { iter::find(&self, p) |
