From 839311c76b5727504858f019994c6471a45eb62e Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 16 Feb 2015 12:15:30 +0200 Subject: Implement ExactSizeIterator for Args and ArgsOs Fixes #22343 --- src/libstd/env.rs | 8 ++++++++ src/libstd/sys/unix/os.rs | 4 ++++ src/libstd/sys/windows/os.rs | 4 ++++ 3 files changed, 16 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/env.rs b/src/libstd/env.rs index ea18838211f..93dc3efe2c4 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -488,12 +488,20 @@ impl Iterator for Args { fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } +impl ExactSizeIterator for Args { + fn len(&self) -> usize { self.inner.len() } +} + impl Iterator for ArgsOs { type Item = OsString; fn next(&mut self) -> Option { self.inner.next() } fn size_hint(&self) -> (usize, Option) { self.inner.size_hint() } } +impl ExactSizeIterator for ArgsOs { + fn len(&self) -> usize { self.inner.len() } +} + /// Returns the page size of the current architecture in bytes. pub fn page_size() -> usize { os_imp::page_size() diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 8a6ef17818a..df03841276e 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -247,6 +247,10 @@ impl Iterator for Args { fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } } +impl ExactSizeIterator for Args { + fn len(&self) -> usize { self.iter.len() } +} + /// Returns the command line arguments /// /// Returns a list of the command line arguments. diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 7e684c52341..6aa1ac04ca9 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -303,6 +303,10 @@ impl Iterator for Args { fn size_hint(&self) -> (usize, Option) { self.range.size_hint() } } +impl ExactSizeIterator for Args { + fn len(&self) -> usize { self.range.len() } +} + impl Drop for Args { fn drop(&mut self) { unsafe { c::LocalFree(self.cur as *mut c_void); } -- cgit 1.4.1-3-g733a5 From 5a6ea7a0716e9b6e10655b62d893a973b7c43ad8 Mon Sep 17 00:00:00 2001 From: Sébastien Marie Date: Mon, 16 Feb 2015 13:53:46 +0100 Subject: change the signal used to test signal_reported_right The test "signal_reported_right" send a signal `1` to `/bin/sh`, and check the status code to check if the signal is reported right. Under OpenBSD, the signal `1` (`SIGHUP`) is catched by `/bin/sh`, resulting the test failed. Use the uncatchable signal `9` (`SIGKILL`) for test. --- src/libstd/old_io/process.rs | 6 +++--- src/libstd/process.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs index 195d33c41a6..09a0deec9c9 100644 --- a/src/libstd/old_io/process.rs +++ b/src/libstd/old_io/process.rs @@ -800,12 +800,12 @@ mod tests { #[cfg(all(unix, not(target_os="android")))] #[test] fn signal_reported_right() { - let p = Command::new("/bin/sh").arg("-c").arg("kill -1 $$").spawn(); + let p = Command::new("/bin/sh").arg("-c").arg("kill -9 $$").spawn(); assert!(p.is_ok()); let mut p = p.unwrap(); match p.wait().unwrap() { - process::ExitSignal(1) => {}, - result => panic!("not terminated by signal 1 (instead, {})", result), + process::ExitSignal(9) => {}, + result => panic!("not terminated by signal 9 (instead, {})", result), } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index d2b98ec8939..0530527c93f 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -537,12 +537,12 @@ mod tests { fn signal_reported_right() { use os::unix::ExitStatusExt; - let p = Command::new("/bin/sh").arg("-c").arg("kill -1 $$").spawn(); + let p = Command::new("/bin/sh").arg("-c").arg("kill -9 $$").spawn(); assert!(p.is_ok()); let mut p = p.unwrap(); match p.wait().unwrap().signal() { - Some(1) => {}, - result => panic!("not terminated by signal 1 (instead, {:?})", result), + Some(9) => {}, + result => panic!("not terminated by signal 9 (instead, {:?})", result), } } -- cgit 1.4.1-3-g733a5 From 1a133f3e2c65961d0a9c550bd759fbefc1e729a6 Mon Sep 17 00:00:00 2001 From: mdinger Date: Fri, 13 Feb 2015 20:41:49 -0500 Subject: Document std::num::Float with examples --- src/libstd/num/mod.rs | 819 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 777 insertions(+), 42 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 29532cb9b02..4582dcd2b03 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -51,71 +51,143 @@ pub trait Float + Rem { // inlined methods from `num::Float` - /// Returns the NaN value. + /// Returns the `NaN` value. + /// + /// ``` + /// use std::num::Float; + /// + /// let nan: f32 = Float::nan(); + /// + /// assert!(nan.is_nan()); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn nan() -> Self; /// Returns the infinite value. + /// + /// ``` + /// use std::num::Float; + /// use std::f32; + /// + /// let infinity: f32 = Float::infinity(); + /// + /// assert!(infinity.is_infinite()); + /// assert!(!infinity.is_finite()); + /// assert!(infinity > f32::MAX); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn infinity() -> Self; /// Returns the negative infinite value. + /// + /// ``` + /// use std::num::Float; + /// use std::f32; + /// + /// let neg_infinity: f32 = Float::neg_infinity(); + /// + /// assert!(neg_infinity.is_infinite()); + /// assert!(!neg_infinity.is_finite()); + /// assert!(neg_infinity < f32::MIN); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn neg_infinity() -> Self; - /// Returns the `0` value. + /// Returns `0.0`. + /// + /// ``` + /// use std::num::Float; + /// + /// let inf: f32 = Float::infinity(); + /// let zero: f32 = Float::zero(); + /// let neg_zero: f32 = Float::neg_zero(); + /// + /// assert_eq!(zero, neg_zero); + /// assert_eq!(7.0f32/inf, zero); + /// assert_eq!(zero * 10.0, zero); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn zero() -> Self; - /// Returns -0.0. + /// Returns `-0.0`. + /// + /// ``` + /// use std::num::Float; + /// + /// let inf: f32 = Float::infinity(); + /// let zero: f32 = Float::zero(); + /// let neg_zero: f32 = Float::neg_zero(); + /// + /// assert_eq!(zero, neg_zero); + /// assert_eq!(7.0f32/inf, zero); + /// assert_eq!(zero * 10.0, zero); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn neg_zero() -> Self; - /// Returns the `1` value. + /// Returns `1.0`. + /// + /// ``` + /// use std::num::Float; + /// + /// let one: f32 = Float::one(); + /// + /// assert_eq!(one, 1.0f32); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn one() -> Self; // FIXME (#5527): These should be associated constants - /// Returns the number of binary digits of mantissa that this type supports. + /// Deprecated: use `std::f32::MANTISSA_DIGITS` or `std::f64::MANTISSA_DIGITS` + /// instead. #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use `std::f32::MANTISSA_DIGITS` or \ `std::f64::MANTISSA_DIGITS` as appropriate")] fn mantissa_digits(unused_self: Option) -> uint; - /// Returns the number of base-10 digits of precision that this type supports. + /// Deprecated: use `std::f32::DIGITS` or `std::f64::DIGITS` instead. #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use `std::f32::DIGITS` or `std::f64::DIGITS` as appropriate")] fn digits(unused_self: Option) -> uint; - /// Returns the difference between 1.0 and the smallest representable number larger than 1.0. + /// Deprecated: use `std::f32::EPSILON` or `std::f64::EPSILON` instead. #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use `std::f32::EPSILON` or `std::f64::EPSILON` as appropriate")] fn epsilon() -> Self; - /// Returns the minimum binary exponent that this type can represent. + /// Deprecated: use `std::f32::MIN_EXP` or `std::f64::MIN_EXP` instead. #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use `std::f32::MIN_EXP` or `std::f64::MIN_EXP` as appropriate")] fn min_exp(unused_self: Option) -> int; - /// Returns the maximum binary exponent that this type can represent. + /// Deprecated: use `std::f32::MAX_EXP` or `std::f64::MAX_EXP` instead. #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use `std::f32::MAX_EXP` or `std::f64::MAX_EXP` as appropriate")] fn max_exp(unused_self: Option) -> int; - /// Returns the minimum base-10 exponent that this type can represent. + /// Deprecated: use `std::f32::MIN_10_EXP` or `std::f64::MIN_10_EXP` instead. #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use `std::f32::MIN_10_EXP` or `std::f64::MIN_10_EXP` as appropriate")] fn min_10_exp(unused_self: Option) -> int; - /// Returns the maximum base-10 exponent that this type can represent. + /// Deprecated: use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` instead. #[unstable(feature = "std_misc")] #[deprecated(since = "1.0.0", reason = "use `std::f32::MAX_10_EXP` or `std::f64::MAX_10_EXP` as appropriate")] fn max_10_exp(unused_self: Option) -> int; /// Returns the smallest finite value that this type can represent. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x: f64 = Float::min_value(); + /// + /// assert_eq!(x, f64::MIN); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn min_value() -> Self; @@ -124,50 +196,222 @@ pub trait Float reason = "unsure about its place in the world")] fn min_pos_value(unused_self: Option) -> Self; /// Returns the largest finite value that this type can represent. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x: f64 = Float::max_value(); + /// assert_eq!(x, f64::MAX); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn max_value() -> Self; - - /// Returns true if this value is NaN and false otherwise. + /// Returns `true` if this value is `NaN` and false otherwise. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let nan = f64::NAN; + /// let f = 7.0; + /// + /// assert!(nan.is_nan()); + /// assert!(!f.is_nan()); + /// ``` #[unstable(feature = "std_misc", reason = "position is undecided")] fn is_nan(self) -> bool; - /// Returns true if this value is positive infinity or negative infinity and + /// Returns `true` if this value is positive infinity or negative infinity and /// false otherwise. + /// + /// ``` + /// use std::num::Float; + /// use std::f32; + /// + /// let f = 7.0f32; + /// let inf: f32 = Float::infinity(); + /// let neg_inf: f32 = Float::neg_infinity(); + /// let nan: f32 = f32::NAN; + /// + /// assert!(!f.is_infinite()); + /// assert!(!nan.is_infinite()); + /// + /// assert!(inf.is_infinite()); + /// assert!(neg_inf.is_infinite()); + /// ``` #[unstable(feature = "std_misc", reason = "position is undecided")] fn is_infinite(self) -> bool; - /// Returns true if this number is neither infinite nor NaN. + /// Returns `true` if this number is neither infinite nor `NaN`. + /// + /// ``` + /// use std::num::Float; + /// use std::f32; + /// + /// let f = 7.0f32; + /// let inf: f32 = Float::infinity(); + /// let neg_inf: f32 = Float::neg_infinity(); + /// let nan: f32 = f32::NAN; + /// + /// assert!(f.is_finite()); + /// + /// assert!(!nan.is_finite()); + /// assert!(!inf.is_finite()); + /// assert!(!neg_inf.is_finite()); + /// ``` #[unstable(feature = "std_misc", reason = "position is undecided")] fn is_finite(self) -> bool; - /// Returns true if this number is neither zero, infinite, denormal, or NaN. + /// Returns `true` if the number is neither zero, infinite, + /// [subnormal][subnormal], or `NaN`. + /// + /// ``` + /// use std::num::Float; + /// use std::f32; + /// + /// let min = f32::MIN_POSITIVE; // 1.17549435e-38f32 + /// let max = f32::MAX; + /// let lower_than_min = 1.0e-40_f32; + /// let zero = 0.0f32; + /// + /// assert!(min.is_normal()); + /// assert!(max.is_normal()); + /// + /// assert!(!zero.is_normal()); + /// assert!(!f32::NAN.is_normal()); + /// assert!(!f32::INFINITY.is_normal()); + /// // Values between `0` and `min` are Subnormal. + /// assert!(!lower_than_min.is_normal()); + /// ``` + /// [subnormal]: http://en.wikipedia.org/wiki/Denormal_number #[unstable(feature = "std_misc", reason = "position is undecided")] fn is_normal(self) -> bool; - /// Returns the category that this number falls into. + + /// Returns the floating point category of the number. If only one property + /// is going to be tested, it is generally faster to use the specific + /// predicate instead. + /// + /// ``` + /// use std::num::{Float, FpCategory}; + /// use std::f32; + /// + /// let num = 12.4f32; + /// let inf = f32::INFINITY; + /// + /// assert_eq!(num.classify(), FpCategory::Normal); + /// assert_eq!(inf.classify(), FpCategory::Infinite); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn classify(self) -> FpCategory; - /// Returns the mantissa, exponent and sign as integers, respectively. + /// Returns the mantissa, base 2 exponent, and sign as integers, respectively. + /// The original number can be recovered by `sign * mantissa * 2 ^ exponent`. + /// The floating point encoding is documented in the [Reference][floating-point]. + /// + /// ``` + /// use std::num::Float; + /// + /// let num = 2.0f32; + /// + /// // (8388608u64, -22i16, 1i8) + /// let (mantissa, exponent, sign) = num.integer_decode(); + /// let sign_f = sign as f32; + /// let mantissa_f = mantissa as f32; + /// let exponent_f = num.powf(exponent as f32); + /// + /// // 1 * 8388608 * 2^(-22) == 2 + /// let abs_difference = (sign_f * mantissa_f * exponent_f - num).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` + /// [floating-point]: ../../../../../reference.html#machine-types #[unstable(feature = "std_misc", reason = "signature is undecided")] fn integer_decode(self) -> (u64, i16, i8); - /// Return the largest integer less than or equal to a number. + /// Returns the largest integer less than or equal to a number. + /// + /// ``` + /// use std::num::Float; + /// + /// let f = 3.99; + /// let g = 3.0; + /// + /// assert_eq!(f.floor(), 3.0); + /// assert_eq!(g.floor(), 3.0); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn floor(self) -> Self; - /// Return the smallest integer greater than or equal to a number. + /// Returns the smallest integer greater than or equal to a number. + /// + /// ``` + /// use std::num::Float; + /// + /// let f = 3.01; + /// let g = 4.0; + /// + /// assert_eq!(f.ceil(), 4.0); + /// assert_eq!(g.ceil(), 4.0); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn ceil(self) -> Self; - /// Return the nearest integer to a number. Round half-way cases away from + /// Returns the nearest integer to a number. Round half-way cases away from /// `0.0`. + /// + /// ``` + /// use std::num::Float; + /// + /// let f = 3.3; + /// let g = -3.3; + /// + /// assert_eq!(f.round(), 3.0); + /// assert_eq!(g.round(), -3.0); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn round(self) -> Self; /// Return the integer part of a number. + /// + /// ``` + /// use std::num::Float; + /// + /// let f = 3.3; + /// let g = -3.7; + /// + /// assert_eq!(f.trunc(), 3.0); + /// assert_eq!(g.trunc(), -3.0); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn trunc(self) -> Self; - /// Return the fractional part of a number. + /// Returns the fractional part of a number. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 3.5; + /// let y = -3.5; + /// let abs_difference_x = (x.fract() - 0.5).abs(); + /// let abs_difference_y = (y.fract() - (-0.5)).abs(); + /// + /// assert!(abs_difference_x < 1e-10); + /// assert!(abs_difference_y < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn fract(self) -> Self; - /// Computes the absolute value of `self`. Returns `Float::nan()` if the /// number is `Float::nan()`. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x = 3.5; + /// let y = -3.5; + /// + /// let abs_difference_x = (x.abs() - x).abs(); + /// let abs_difference_y = (y.abs() - (-y)).abs(); + /// + /// assert!(abs_difference_x < 1e-10); + /// assert!(abs_difference_y < 1e-10); + /// + /// assert!(f64::NAN.abs().is_nan()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn abs(self) -> Self; /// Returns a number that represents the sign of `self`. @@ -175,24 +419,88 @@ pub trait Float /// - `1.0` if the number is positive, `+0.0` or `Float::infinity()` /// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()` /// - `Float::nan()` if the number is `Float::nan()` + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let f = 3.5; + /// + /// assert_eq!(f.signum(), 1.0); + /// assert_eq!(f64::NEG_INFINITY.signum(), -1.0); + /// + /// assert!(f64::NAN.signum().is_nan()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn signum(self) -> Self; /// Returns `true` if `self` is positive, including `+0.0` and /// `Float::infinity()`. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let nan: f64 = f64::NAN; + /// + /// let f = 7.0; + /// let g = -7.0; + /// + /// assert!(f.is_positive()); + /// assert!(!g.is_positive()); + /// // Requires both tests to determine if is `NaN` + /// assert!(!nan.is_positive() && !nan.is_negative()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn is_positive(self) -> bool; /// Returns `true` if `self` is negative, including `-0.0` and /// `Float::neg_infinity()`. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let nan = f64::NAN; + /// + /// let f = 7.0; + /// let g = -7.0; + /// + /// assert!(!f.is_negative()); + /// assert!(g.is_negative()); + /// // Requires both tests to determine if is `NaN`. + /// assert!(!nan.is_positive() && !nan.is_negative()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn is_negative(self) -> bool; /// Fused multiply-add. Computes `(self * a) + b` with only one rounding /// error. This produces a more accurate result with better performance than /// a separate multiplication operation followed by an add. + /// + /// ``` + /// use std::num::Float; + /// + /// let m = 10.0; + /// let x = 4.0; + /// let b = 60.0; + /// + /// // 100.0 + /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn mul_add(self, a: Self, b: Self) -> Self; /// Take the reciprocal (inverse) of a number, `1/x`. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 2.0; + /// let abs_difference = (x.recip() - (1.0/x)).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn recip(self) -> Self; @@ -200,149 +508,576 @@ pub trait Float /// Raise a number to an integer power. /// /// Using this function is generally faster than using `powf` + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 2.0; + /// let abs_difference = (x.powi(2) - x*x).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn powi(self, n: i32) -> Self; /// Raise a number to a floating point power. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 2.0; + /// let abs_difference = (x.powf(2.0) - x*x).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn powf(self, n: Self) -> Self; - /// Take the square root of a number. /// /// Returns NaN if `self` is a negative number. + /// + /// ``` + /// use std::num::Float; + /// + /// let positive = 4.0; + /// let negative = -4.0; + /// + /// let abs_difference = (positive.sqrt() - 2.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// assert!(negative.sqrt().is_nan()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn sqrt(self) -> Self; + /// Take the reciprocal (inverse) square root of a number, `1/sqrt(x)`. + /// + /// ``` + /// use std::num::Float; + /// + /// let f = 4.0; + /// + /// let abs_difference = (f.rsqrt() - 0.5).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn rsqrt(self) -> Self; /// Returns `e^(self)`, (the exponential function). + /// + /// ``` + /// use std::num::Float; + /// + /// let one = 1.0; + /// // e^1 + /// let e = one.exp(); + /// + /// // ln(e) - 1 == 0 + /// let abs_difference = (e.ln() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn exp(self) -> Self; - /// Returns 2 raised to the power of the number, `2^(self)`. + /// Returns `2^(self)`. + /// + /// ``` + /// use std::num::Float; + /// + /// let f = 2.0; + /// + /// // 2^2 - 4 == 0 + /// let abs_difference = (f.exp2() - 4.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn exp2(self) -> Self; /// Returns the natural logarithm of the number. + /// + /// ``` + /// use std::num::Float; + /// + /// let one = 1.0; + /// // e^1 + /// let e = one.exp(); + /// + /// // ln(e) - 1 == 0 + /// let abs_difference = (e.ln() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn ln(self) -> Self; /// Returns the logarithm of the number with respect to an arbitrary base. + /// + /// ``` + /// use std::num::Float; + /// + /// let ten = 10.0; + /// let two = 2.0; + /// + /// // log10(10) - 1 == 0 + /// let abs_difference_10 = (ten.log(10.0) - 1.0).abs(); + /// + /// // log2(2) - 1 == 0 + /// let abs_difference_2 = (two.log(2.0) - 1.0).abs(); + /// + /// assert!(abs_difference_10 < 1e-10); + /// assert!(abs_difference_2 < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn log(self, base: Self) -> Self; /// Returns the base 2 logarithm of the number. + /// + /// ``` + /// use std::num::Float; + /// + /// let two = 2.0; + /// + /// // log2(2) - 1 == 0 + /// let abs_difference = (two.log2() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn log2(self) -> Self; /// Returns the base 10 logarithm of the number. + /// + /// ``` + /// use std::num::Float; + /// + /// let ten = 10.0; + /// + /// // log10(10) - 1 == 0 + /// let abs_difference = (ten.log10() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn log10(self) -> Self; /// Convert radians to degrees. + /// + /// ``` + /// use std::num::Float; + /// use std::f64::consts; + /// + /// let angle = consts::PI; + /// + /// let abs_difference = (angle.to_degrees() - 180.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "desirability is unclear")] fn to_degrees(self) -> Self; /// Convert degrees to radians. + /// + /// ``` + /// use std::num::Float; + /// use std::f64::consts; + /// + /// let angle = 180.0; + /// + /// let abs_difference = (angle.to_radians() - consts::PI).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "desirability is unclear")] fn to_radians(self) -> Self; - - /// Constructs a floating point number created by multiplying `x` by 2 - /// raised to the power of `exp`. + /// Constructs a floating point number of `x*2^exp`. + /// + /// ``` + /// use std::num::Float; + /// + /// // 3*2^2 - 12 == 0 + /// let abs_difference = (Float::ldexp(3.0, 2) - 12.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "pending integer conventions")] fn ldexp(x: Self, exp: int) -> Self; /// Breaks the number into a normalized fraction and a base-2 exponent, /// satisfying: /// - /// * `self = x * pow(2, exp)` - /// + /// * `self = x * 2^exp` /// * `0.5 <= abs(x) < 1.0` + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 4.0; + /// + /// // (1/2)*2^3 -> 1 * 8/2 -> 4.0 + /// let f = x.frexp(); + /// let abs_difference_0 = (f.0 - 0.5).abs(); + /// let abs_difference_1 = (f.1 as f64 - 3.0).abs(); + /// + /// assert!(abs_difference_0 < 1e-10); + /// assert!(abs_difference_1 < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "pending integer conventions")] fn frexp(self) -> (Self, int); - /// Returns the next representable floating-point value in the direction of /// `other`. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 1.0f32; + /// + /// let abs_diff = (x.next_after(2.0) - 1.00000011920928955078125_f32).abs(); + /// + /// assert!(abs_diff < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn next_after(self, other: Self) -> Self; /// Returns the maximum of the two numbers. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 1.0; + /// let y = 2.0; + /// + /// assert_eq!(x.max(y), y); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn max(self, other: Self) -> Self; /// Returns the minimum of the two numbers. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 1.0; + /// let y = 2.0; + /// + /// assert_eq!(x.min(y), x); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn min(self, other: Self) -> Self; - /// The positive difference of two numbers. Returns `0.0` if the number is - /// less than or equal to `other`, otherwise the difference between`self` - /// and `other` is returned. + /// The positive difference of two numbers. + /// + /// * If `self <= other`: `0:0` + /// * Else: `self - other` + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 3.0; + /// let y = -3.0; + /// + /// let abs_difference_x = (x.abs_sub(1.0) - 2.0).abs(); + /// let abs_difference_y = (y.abs_sub(1.0) - 0.0).abs(); + /// + /// assert!(abs_difference_x < 1e-10); + /// assert!(abs_difference_y < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "may be renamed")] fn abs_sub(self, other: Self) -> Self; - /// Take the cubic root of a number. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 8.0; + /// + /// // x^(1/3) - 2 == 0 + /// let abs_difference = (x.cbrt() - 2.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "may be renamed")] fn cbrt(self) -> Self; /// Calculate the length of the hypotenuse of a right-angle triangle given /// legs of length `x` and `y`. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 2.0; + /// let y = 3.0; + /// + /// // sqrt(x^2 + y^2) + /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "unsure about its place in the world")] fn hypot(self, other: Self) -> Self; /// Computes the sine of a number (in radians). + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x = f64::consts::PI/2.0; + /// + /// let abs_difference = (x.sin() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn sin(self) -> Self; /// Computes the cosine of a number (in radians). + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x = 2.0*f64::consts::PI; + /// + /// let abs_difference = (x.cos() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn cos(self) -> Self; /// Computes the tangent of a number (in radians). + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x = f64::consts::PI/4.0; + /// let abs_difference = (x.tan() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-14); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn tan(self) -> Self; - /// Computes the arcsine of a number. Return value is in radians in /// the range [-pi/2, pi/2] or NaN if the number is outside the range /// [-1, 1]. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let f = f64::consts::PI / 2.0; + /// + /// // asin(sin(pi/2)) + /// let abs_difference = (f.sin().asin() - f64::consts::PI / 2.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn asin(self) -> Self; /// Computes the arccosine of a number. Return value is in radians in /// the range [0, pi] or NaN if the number is outside the range /// [-1, 1]. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let f = f64::consts::PI / 4.0; + /// + /// // acos(cos(pi/4)) + /// let abs_difference = (f.cos().acos() - f64::consts::PI / 4.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn acos(self) -> Self; /// Computes the arctangent of a number. Return value is in radians in the /// range [-pi/2, pi/2]; + /// + /// ``` + /// use std::num::Float; + /// + /// let f = 1.0; + /// + /// // atan(tan(1)) + /// let abs_difference = (f.tan().atan() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn atan(self) -> Self; - /// Computes the four quadrant arctangent of a number, `y`, and another - /// number `x`. Return value is in radians in the range [-pi, pi]. + /// Computes the four quadrant arctangent of `self` (`y`) and `other` (`x`). + /// + /// * `x = 0`, `y = 0`: `0` + /// * `x >= 0`: `arctan(y/x)` -> `[-pi/2, pi/2]` + /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]` + /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)` + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let pi = f64::consts::PI; + /// // All angles from horizontal right (+x) + /// // 45 deg counter-clockwise + /// let x1 = 3.0; + /// let y1 = -3.0; + /// + /// // 135 deg clockwise + /// let x2 = -3.0; + /// let y2 = 3.0; + /// + /// let abs_difference_1 = (y1.atan2(x1) - (-pi/4.0)).abs(); + /// let abs_difference_2 = (y2.atan2(x2) - 3.0*pi/4.0).abs(); + /// + /// assert!(abs_difference_1 < 1e-10); + /// assert!(abs_difference_2 < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn atan2(self, other: Self) -> Self; /// Simultaneously computes the sine and cosine of the number, `x`. Returns /// `(sin(x), cos(x))`. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x = f64::consts::PI/4.0; + /// let f = x.sin_cos(); + /// + /// let abs_difference_0 = (f.0 - x.sin()).abs(); + /// let abs_difference_1 = (f.1 - x.cos()).abs(); + /// + /// assert!(abs_difference_0 < 1e-10); + /// assert!(abs_difference_0 < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn sin_cos(self) -> (Self, Self); - /// Returns the exponential of the number, minus 1, in a way that is - /// accurate even if the number is close to zero. + /// Returns `e^(self) - 1` in a way that is accurate even if the + /// number is close to zero. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 7.0; + /// + /// // e^(ln(7)) - 1 + /// let abs_difference = (x.ln().exp_m1() - 6.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "may be renamed")] fn exp_m1(self) -> Self; - /// Returns the natural logarithm of the number plus 1 (`ln(1+n)`) more - /// accurately than if the operations were performed separately. + /// Returns `ln(1+n)` (natural logarithm) more accurately than if + /// the operations were performed separately. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let x = f64::consts::E - 1.0; + /// + /// // ln(1 + (e - 1)) == ln(e) == 1 + /// let abs_difference = (x.ln_1p() - 1.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[unstable(feature = "std_misc", reason = "may be renamed")] fn ln_1p(self) -> Self; /// Hyperbolic sine function. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let e = f64::consts::E; + /// let x = 1.0; + /// + /// let f = x.sinh(); + /// // Solving sinh() at 1 gives `(e^2-1)/(2e)` + /// let g = (e*e - 1.0)/(2.0*e); + /// let abs_difference = (f - g).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn sinh(self) -> Self; /// Hyperbolic cosine function. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let e = f64::consts::E; + /// let x = 1.0; + /// let f = x.cosh(); + /// // Solving cosh() at 1 gives this result + /// let g = (e*e + 1.0)/(2.0*e); + /// let abs_difference = (f - g).abs(); + /// + /// // Same result + /// assert!(abs_difference < 1.0e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn cosh(self) -> Self; /// Hyperbolic tangent function. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let e = f64::consts::E; + /// let x = 1.0; + /// + /// let f = x.tanh(); + /// // Solving tanh() at 1 gives `(1 - e^(-2))/(1 + e^(-2))` + /// let g = (1.0 - e.powi(-2))/(1.0 + e.powi(-2)); + /// let abs_difference = (f - g).abs(); + /// + /// assert!(abs_difference < 1.0e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn tanh(self) -> Self; /// Inverse hyperbolic sine function. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 1.0; + /// let f = x.sinh().asinh(); + /// + /// let abs_difference = (f - x).abs(); + /// + /// assert!(abs_difference < 1.0e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn asinh(self) -> Self; /// Inverse hyperbolic cosine function. + /// + /// ``` + /// use std::num::Float; + /// + /// let x = 1.0; + /// let f = x.cosh().acosh(); + /// + /// let abs_difference = (f - x).abs(); + /// + /// assert!(abs_difference < 1.0e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn acosh(self) -> Self; /// Inverse hyperbolic tangent function. + /// + /// ``` + /// use std::num::Float; + /// use std::f64; + /// + /// let e = f64::consts::E; + /// let f = e.tanh().atanh(); + /// + /// let abs_difference = (f - e).abs(); + /// + /// assert!(abs_difference < 1.0e-10); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn atanh(self) -> Self; } -- cgit 1.4.1-3-g733a5 From 4a9dd3f8403f84ad518b0119fa2312c379df5dd7 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 11 Feb 2015 16:57:23 -0800 Subject: Expose more of std::path This commit exposes the `is_sep` function and `MAIN_SEP` constant, as well as Windows path prefixes. The path prefix enum is safely exposed on all platforms, but it only yielded as a component for Windows. Exposing the prefix enum as part of prefix components involved changing the type from `OsStr` to the `Prefix` enum, which is a: [breaking-change] --- src/libstd/path.rs | 249 +++++++++++++++++++++++++++-------------------------- 1 file changed, 126 insertions(+), 123 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 776fa270867..485f5d8014d 100755 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -107,6 +107,7 @@ use core::prelude::*; +use ascii::*; use borrow::BorrowFrom; use cmp; use iter; @@ -118,7 +119,7 @@ use fmt; use ffi::{OsStr, OsString, AsOsStr}; -use self::platform::{is_sep, is_verbatim_sep, MAIN_SEP_STR, parse_prefix, Prefix}; +use self::platform::{is_sep_byte, is_verbatim_sep, MAIN_SEP_STR, parse_prefix}; //////////////////////////////////////////////////////////////////////////////// // GENERAL NOTES @@ -139,11 +140,12 @@ use self::platform::{is_sep, is_verbatim_sep, MAIN_SEP_STR, parse_prefix, Prefix #[cfg(unix)] mod platform { + use super::Prefix; use core::prelude::*; use ffi::OsStr; #[inline] - pub fn is_sep(b: u8) -> bool { + pub fn is_sep_byte(b: u8) -> bool { b == b'/' } @@ -156,34 +158,21 @@ mod platform { None } - #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] - pub struct Prefix<'a>; - - impl<'a> Prefix<'a> { - #[inline] - pub fn len(&self) -> usize { 0 } - #[inline] - pub fn is_verbatim(&self) -> bool { false } - #[inline] - pub fn is_drive(&self) -> bool { false } - #[inline] - pub fn has_implicit_root(&self) -> bool { false } - } - pub const MAIN_SEP_STR: &'static str = "/"; + pub const MAIN_SEP: char = '/'; } #[cfg(windows)] mod platform { use core::prelude::*; + use ascii::*; use char::CharExt as UnicodeCharExt; - use super::{os_str_as_u8_slice, u8_slice_as_os_str}; - use ascii::*; + use super::{os_str_as_u8_slice, u8_slice_as_os_str, Prefix}; use ffi::OsStr; #[inline] - pub fn is_sep(b: u8) -> bool { + pub fn is_sep_byte(b: u8) -> bool { b == b'/' || b == b'\\' } @@ -193,7 +182,7 @@ mod platform { } pub fn parse_prefix<'a>(path: &'a OsStr) -> Option { - use self::Prefix::*; + use super::Prefix::*; unsafe { // The unsafety here stems from converting between &OsStr and &[u8] // and back. This is safe to do because (1) we only look at ASCII @@ -224,8 +213,7 @@ mod platform { let c = path[0]; if c.is_ascii() && (c as char).is_alphabetic() { // \\?\C:\ path - let slice = u8_slice_as_os_str(&path[0..1]); - return Some(VerbatimDisk(slice)); + return Some(VerbatimDisk(c.to_ascii_uppercase())); } } let slice = &path[.. idx.unwrap_or(path.len())]; @@ -237,7 +225,7 @@ mod platform { let slice = &path[.. path.position_elem(&b'\\').unwrap_or(path.len())]; return Some(DeviceNS(u8_slice_as_os_str(slice))); } - match parse_two_comps(path, is_sep) { + match parse_two_comps(path, is_sep_byte) { Some((server, share)) if server.len() > 0 && share.len() > 0 => { // \\server\share return Some(UNC(u8_slice_as_os_str(server), @@ -249,7 +237,7 @@ mod platform { // C: let c = path[0]; if c.is_ascii() && (c as char).is_alphabetic() { - return Some(Disk(u8_slice_as_os_str(&path[0..1]))); + return Some(Disk(c.to_ascii_uppercase())); } } return None; @@ -267,99 +255,102 @@ mod platform { } } - /// Windows path prefixes. - /// - /// Windows uses a variety of path styles, including references to drive - /// volumes (like `C:`), network shared (like `\\server\share`) and - /// others. In addition, some path prefixes are "verbatim", in which case - /// `/` is *not* treated as a separator and essentially no normalization is - /// performed. - #[derive(Copy, Clone, Debug, Hash, Eq)] - pub enum Prefix<'a> { - /// Prefix `\\?\`, together with the given component immediately following it. - Verbatim(&'a OsStr), - - /// Prefix `\\?\UNC\`, with the "server" and "share" components following it. - VerbatimUNC(&'a OsStr, &'a OsStr), - - /// Prefix like `\\?\C:\`, for the given drive letter - VerbatimDisk(&'a OsStr), - - /// Prefix `\\.\`, together with the given component immediately following it. - DeviceNS(&'a OsStr), - - /// Prefix `\\server\share`, with the given "server" and "share" components. - UNC(&'a OsStr, &'a OsStr), - - /// Prefix `C:` for the given disk drive. - Disk(&'a OsStr), - } - - impl<'a> Prefix<'a> { - #[inline] - pub fn len(&self) -> usize { - use self::Prefix::*; - fn os_str_len(s: &OsStr) -> usize { - os_str_as_u8_slice(s).len() - } - match *self { - Verbatim(x) => 4 + os_str_len(x), - VerbatimUNC(x,y) => 8 + os_str_len(x) + - if os_str_len(y) > 0 { 1 + os_str_len(y) } - else { 0 }, - VerbatimDisk(_) => 6, - UNC(x,y) => 2 + os_str_len(x) + - if os_str_len(y) > 0 { 1 + os_str_len(y) } - else { 0 }, - DeviceNS(x) => 4 + os_str_len(x), - Disk(_) => 2 - } + pub const MAIN_SEP_STR: &'static str = "\\"; + pub const MAIN_SEP: char = '\\'; +} - } +//////////////////////////////////////////////////////////////////////////////// +// Windows Prefixes +//////////////////////////////////////////////////////////////////////////////// - #[inline] - pub fn is_verbatim(&self) -> bool { - use self::Prefix::*; - match *self { - Verbatim(_) | VerbatimDisk(_) | VerbatimUNC(_, _) => true, - _ => false - } - } +/// Path prefixes (Windows only). +/// +/// Windows uses a variety of path styles, including references to drive +/// volumes (like `C:`), network shared (like `\\server\share`) and +/// others. In addition, some path prefixes are "verbatim", in which case +/// `/` is *not* treated as a separator and essentially no normalization is +/// performed. +#[derive(Copy, Clone, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)] +pub enum Prefix<'a> { + /// Prefix `\\?\`, together with the given component immediately following it. + Verbatim(&'a OsStr), + + /// Prefix `\\?\UNC\`, with the "server" and "share" components following it. + VerbatimUNC(&'a OsStr, &'a OsStr), + + /// Prefix like `\\?\C:\`, for the given drive letter + VerbatimDisk(u8), + + /// Prefix `\\.\`, together with the given component immediately following it. + DeviceNS(&'a OsStr), + + /// Prefix `\\server\share`, with the given "server" and "share" components. + UNC(&'a OsStr, &'a OsStr), + + /// Prefix `C:` for the given disk drive. + Disk(u8), +} - #[inline] - pub fn is_drive(&self) -> bool { - match *self { - Prefix::Disk(_) => true, - _ => false, - } +impl<'a> Prefix<'a> { + #[inline] + fn len(&self) -> usize { + use self::Prefix::*; + fn os_str_len(s: &OsStr) -> usize { + os_str_as_u8_slice(s).len() + } + match *self { + Verbatim(x) => 4 + os_str_len(x), + VerbatimUNC(x,y) => 8 + os_str_len(x) + + if os_str_len(y) > 0 { 1 + os_str_len(y) } + else { 0 }, + VerbatimDisk(_) => 6, + UNC(x,y) => 2 + os_str_len(x) + + if os_str_len(y) > 0 { 1 + os_str_len(y) } + else { 0 }, + DeviceNS(x) => 4 + os_str_len(x), + Disk(_) => 2 } - #[inline] - pub fn has_implicit_root(&self) -> bool { - !self.is_drive() + } + + /// Determine if the prefix is verbatim, i.e. begins `\\?\`. + #[inline] + pub fn is_verbatim(&self) -> bool { + use self::Prefix::*; + match *self { + Verbatim(_) | VerbatimDisk(_) | VerbatimUNC(_, _) => true, + _ => false } } - impl<'a> PartialEq for Prefix<'a> { - fn eq(&self, other: &Prefix<'a>) -> bool { - use self::Prefix::*; - match (*self, *other) { - (Verbatim(x), Verbatim(y)) => x == y, - (VerbatimUNC(x1, x2), VerbatimUNC(y1, y2)) => x1 == y1 && x2 == y2, - (VerbatimDisk(x), VerbatimDisk(y)) => - os_str_as_u8_slice(x).eq_ignore_ascii_case(os_str_as_u8_slice(y)), - (DeviceNS(x), DeviceNS(y)) => x == y, - (UNC(x1, x2), UNC(y1, y2)) => x1 == y1 && x2 == y2, - (Disk(x), Disk(y)) => - os_str_as_u8_slice(x).eq_ignore_ascii_case(os_str_as_u8_slice(y)), - _ => false, - } + #[inline] + fn is_drive(&self) -> bool { + match *self { + Prefix::Disk(_) => true, + _ => false, } } - pub const MAIN_SEP_STR: &'static str = "\\"; + #[inline] + fn has_implicit_root(&self) -> bool { + !self.is_drive() + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Exposed parsing helpers +//////////////////////////////////////////////////////////////////////////////// + +/// Determine whether the character is one of the permitted path +/// separators for the current platform. +pub fn is_separator(c: char) -> bool { + use ascii::*; + c.is_ascii() && is_sep_byte(c as u8) } +/// The primary sperator for the current platform +pub const MAIN_SEPARATOR: char = platform::MAIN_SEP; + //////////////////////////////////////////////////////////////////////////////// // Misc helpers //////////////////////////////////////////////////////////////////////////////// @@ -403,7 +394,7 @@ fn has_suffix(s: &[u8], prefix: Option) -> bool { (p.len(), p.is_verbatim()) } else { (0, false) }; if prefix_len > 0 && prefix_len == s.len() && !verbatim { return true; } - let mut splits = s[prefix_len..].split(|b| is_sep(*b)); + let mut splits = s[prefix_len..].split(|b| is_sep_byte(*b)); let last = splits.next_back().unwrap(); let more = splits.next_back().is_some(); more && last == b"" @@ -412,7 +403,7 @@ fn has_suffix(s: &[u8], prefix: Option) -> bool { /// Says whether the first byte after the prefix is a separator. fn has_physical_root(s: &[u8], prefix: Option) -> bool { let path = if let Some(p) = prefix { &s[p.len()..] } else { s }; - path.len() > 0 && is_sep(path[0]) + path.len() > 0 && is_sep_byte(path[0]) } fn parse_single_component(comp: &[u8]) -> Option { @@ -473,8 +464,16 @@ enum State { /// their role in the API. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum Component<'a> { - /// A Windows path prefix, e.g. `C:` or `\server\share` - Prefix(&'a OsStr), + /// A Windows path prefix, e.g. `C:` or `\server\share`. + /// + /// Does not occur on Unix. + Prefix { + /// The prefix as an unparsed `OsStr` slice. + raw: &'a OsStr, + + /// The parsed prefix data. + parsed: Prefix<'a> + }, /// An empty component. Only used on Windows for the last component of /// verbatim paths ending with a separator (e.g. the last component of @@ -498,7 +497,7 @@ impl<'a> Component<'a> { /// Extract the underlying `OsStr` slice pub fn as_os_str(self) -> &'a OsStr { match self { - Component::Prefix(path) => path, + Component::Prefix { raw, .. } => &raw, Component::Empty => OsStr::from_str(""), Component::RootDir => OsStr::from_str(MAIN_SEP_STR), Component::CurDir => OsStr::from_str("."), @@ -568,11 +567,11 @@ impl<'a> Components<'a> { } #[inline] - fn is_sep(&self, b: u8) -> bool { + fn is_sep_byte(&self, b: u8) -> bool { if self.prefix_verbatim() { is_verbatim_sep(b) } else { - is_sep(b) + is_sep_byte(b) } } @@ -601,7 +600,7 @@ impl<'a> Components<'a> { // remove the component fn parse_next_component(&self) -> (usize, Option>) { debug_assert!(self.front == State::Body); - let (extra, comp) = match self.path.iter().position(|b| self.is_sep(*b)) { + let (extra, comp) = match self.path.iter().position(|b| self.is_sep_byte(*b)) { None => (0, self.path), Some(i) => (1, &self.path[.. i]), }; @@ -613,7 +612,7 @@ impl<'a> Components<'a> { fn parse_next_component_back(&self) -> (usize, Option>) { debug_assert!(self.back == State::Body); let start = self.prefix_and_root(); - let (extra, comp) = match self.path[start..].iter().rposition(|b| self.is_sep(*b)) { + let (extra, comp) = match self.path[start..].iter().rposition(|b| self.is_sep_byte(*b)) { None => (0, &self.path[start ..]), Some(i) => (1, &self.path[start + i + 1 ..]), }; @@ -680,9 +679,12 @@ impl<'a> Iterator for Components<'a> { State::Prefix if self.prefix_len() > 0 => { self.front = State::Root; debug_assert!(self.prefix_len() <= self.path.len()); - let prefix = &self.path[.. self.prefix_len()]; + let raw = &self.path[.. self.prefix_len()]; self.path = &self.path[self.prefix_len() .. ]; - return Some(Component::Prefix(unsafe { u8_slice_as_os_str(prefix) })) + return Some(Component::Prefix { + raw: unsafe { u8_slice_as_os_str(raw) }, + parsed: self.prefix.unwrap() + }) } State::Prefix => { self.front = State::Root; @@ -755,9 +757,10 @@ impl<'a> DoubleEndedIterator for Components<'a> { } State::Prefix if self.prefix_len() > 0 => { self.back = State::Done; - return Some(Component::Prefix(unsafe { - u8_slice_as_os_str(self.path) - })) + return Some(Component::Prefix { + raw: unsafe { u8_slice_as_os_str(self.path) }, + parsed: self.prefix.unwrap() + }) } State::Prefix => { self.back = State::Done; @@ -844,7 +847,7 @@ impl PathBuf { /// * if `path` has a prefix but no root, it replaces `self. pub fn push(&mut self, path: &P) where P: AsPath { // in general, a separator is needed if the rightmost byte is not a separator - let mut need_sep = self.as_mut_vec().last().map(|c| !is_sep(*c)).unwrap_or(false); + let mut need_sep = self.as_mut_vec().last().map(|c| !is_sep_byte(*c)).unwrap_or(false); // in the special case of `C:` on Windows, do *not* add a separator { @@ -1135,11 +1138,11 @@ impl Path { match (comp, comps.next_back()) { (Some(Component::CurDir), Some(Component::RootDir)) => None, - (Some(Component::CurDir), Some(Component::Prefix(_))) => None, + (Some(Component::CurDir), Some(Component::Prefix { .. })) => None, (Some(Component::Empty), Some(Component::RootDir)) => None, - (Some(Component::Empty), Some(Component::Prefix(_))) => None, - (Some(Component::Prefix(_)), None) => None, - (Some(Component::RootDir), Some(Component::Prefix(_))) => None, + (Some(Component::Empty), Some(Component::Prefix { .. })) => None, + (Some(Component::Prefix { .. }), None) => None, + (Some(Component::RootDir), Some(Component::Prefix { .. })) => None, _ => rest } } -- cgit 1.4.1-3-g733a5 From a1b755862c3999b6107838866663fae339bbfedc Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 16 Feb 2015 21:03:39 -0800 Subject: Make io::Seek docs less prescriptive --- src/libstd/io/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 2668baba095..1243df2f93e 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -443,9 +443,8 @@ pub trait Seek { /// A seek beyond the end of a stream is allowed, but seeking before offset /// 0 is an error. /// - /// Seeking past the end of the stream does not modify the underlying - /// stream, but the next write may cause the previous data to be filled in - /// with a bit pattern. + /// The behavior when seeking past the end of the stream is implementation + /// defined. /// /// This method returns the new position within the stream if the seek /// operation completed successfully. -- cgit 1.4.1-3-g733a5 From 9eeaa3c78694ec593450e5dd96a5f3fa10afd434 Mon Sep 17 00:00:00 2001 From: Sébastien Marie Date: Tue, 17 Feb 2015 11:11:53 +0100 Subject: openbsd: adapt connect_error test The connect_error test check if connecting to "0.0.0.0:1" works (it shouldn't). And in case of error, the test expects a ConnectionRefused error. Under OpenBSD, trying to connect to "0.0.0.0" isn't a ConnectionRefused: it is an InvalidInput error. The patch allow the error to be ConnectionRefused or InvalidInput. --- src/libstd/net/tcp.rs | 3 ++- src/libstd/old_io/net/tcp.rs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 50eafdfc5c2..01c005bd8a6 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -247,7 +247,8 @@ mod tests { fn connect_error() { match TcpStream::connect("0.0.0.0:1") { Ok(..) => panic!(), - Err(e) => assert_eq!(e.kind(), ErrorKind::ConnectionRefused), + Err(e) => assert!((e.kind() == ErrorKind::ConnectionRefused) + || (e.kind() == ErrorKind::InvalidInput)), } } diff --git a/src/libstd/old_io/net/tcp.rs b/src/libstd/old_io/net/tcp.rs index ebf7f6cc0f2..45dba733535 100644 --- a/src/libstd/old_io/net/tcp.rs +++ b/src/libstd/old_io/net/tcp.rs @@ -494,6 +494,7 @@ mod test { use old_io::{EndOfFile, TimedOut, ShortWrite, IoError}; use old_io::{ConnectionRefused, BrokenPipe, ConnectionAborted}; use old_io::{ConnectionReset, NotConnected, PermissionDenied, OtherIoError}; + use old_io::{InvalidInput}; use old_io::{Acceptor, Listener}; // FIXME #11530 this fails on android because tests are run as root @@ -510,7 +511,8 @@ mod test { fn connect_error() { match TcpStream::connect("0.0.0.0:1") { Ok(..) => panic!(), - Err(e) => assert_eq!(e.kind, ConnectionRefused), + Err(e) => assert!((e.kind == ConnectionRefused) + || (e.kind == InvalidInput)), } } -- cgit 1.4.1-3-g733a5 From bad3bcbfc0382f2b0629da630482f4d27b88216d Mon Sep 17 00:00:00 2001 From: Markus Siemens Date: Tue, 17 Feb 2015 11:22:27 +0100 Subject: Fix a small typo in libstd/fs.rs --- src/libstd/fs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 5f91d173ed2..69791084e2f 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -114,7 +114,7 @@ impl File { /// Open a file in write-only mode. /// - /// This function will create a file it it does not exist, + /// This function will create a file if it does not exist, /// and will truncate it if it does. /// /// See the `OpenOptions::open` function for more details. -- cgit 1.4.1-3-g733a5 From 10f51fc412b36ac4456be01d549d7ecd247a517b Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 17 Feb 2015 20:32:22 +0530 Subject: fix windows --- src/libstd/sys/windows/os.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 6aa1ac04ca9..502d70d4e1a 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -18,7 +18,7 @@ use os::windows::*; use error::Error as StdError; use ffi::{OsString, OsStr, AsOsStr}; use fmt; -use iter::Range; +use ops::Range; use libc::types::os::arch::extra::LPWCH; use libc::{self, c_int, c_void}; use mem; @@ -319,7 +319,7 @@ pub fn args() -> Args { let lpCmdLine = c::GetCommandLineW(); let szArgList = c::CommandLineToArgvW(lpCmdLine, &mut nArgs); - Args { cur: szArgList, range: range(0, nArgs as isize) } + Args { cur: szArgList, range: 0..(nArgs as isize) } } } -- cgit 1.4.1-3-g733a5 From cc687869ab5f39816109625ba8d1787a25ff4abf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 10:06:24 -0800 Subject: std: Stabilize the IntoIterator trait Now that the necessary associated types exist for the `IntoIterator` trait this commit stabilizes the trait as-is as well as all existing implementations. --- src/libcollections/binary_heap.rs | 2 ++ src/libcollections/bit.rs | 2 ++ src/libcollections/btree/map.rs | 3 +++ src/libcollections/btree/set.rs | 2 ++ src/libcollections/dlist.rs | 2 ++ src/libcollections/enum_set.rs | 1 + src/libcollections/ring_buf.rs | 3 +++ src/libcollections/vec.rs | 3 +++ src/libcollections/vec_map.rs | 3 +++ src/libcore/array.rs | 2 ++ src/libcore/iter.rs | 5 +++++ src/libcore/slice.rs | 2 ++ src/libstd/collections/hash/map.rs | 3 +++ src/libstd/collections/hash/set.rs | 2 ++ 14 files changed, 35 insertions(+) (limited to 'src/libstd') diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 1d994839d99..2a701e67c53 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -666,6 +666,7 @@ impl IntoIterator for BinaryHeap { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for BinaryHeap { type Item = T; type IntoIter = IntoIter; @@ -686,6 +687,7 @@ impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { type Item = &'a T; type IntoIter = Iter<'a, T>; diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index ca598a8d4d2..df1a3416602 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -1081,6 +1081,7 @@ impl<'a> IntoIterator for &'a Bitv { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a> IntoIterator for &'a Bitv { type Item = bool; type IntoIter = Iter<'a>; @@ -1905,6 +1906,7 @@ impl<'a> IntoIterator for &'a BitvSet { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a> IntoIterator for &'a BitvSet { type Item = usize; type IntoIter = SetIter<'a>; diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 84f9825e989..a0c1c2d1854 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -473,6 +473,7 @@ impl IntoIterator for BTreeMap { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for BTreeMap { type Item = (K, V); type IntoIter = IntoIter; @@ -493,6 +494,7 @@ impl<'a, K, V> IntoIterator for &'a BTreeMap { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> IntoIterator for &'a BTreeMap { type Item = (&'a K, &'a V); type IntoIter = Iter<'a, K, V>; @@ -513,6 +515,7 @@ impl<'a, K, V> IntoIterator for &'a mut BTreeMap { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> IntoIterator for &'a mut BTreeMap { type Item = (&'a K, &'a mut V); type IntoIter = IterMut<'a, K, V>; diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index aecf5940311..8ac1b97de25 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -491,6 +491,7 @@ impl IntoIterator for BTreeSet { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for BTreeSet { type Item = T; type IntoIter = IntoIter; @@ -511,6 +512,7 @@ impl<'a, T> IntoIterator for &'a BTreeSet { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a BTreeSet { type Item = &'a T; type IntoIter = Iter<'a, T>; diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 27b282ee9a9..42c44c0d5c1 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -848,6 +848,7 @@ impl IntoIterator for DList { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for DList { type Item = T; type IntoIter = IntoIter; @@ -868,6 +869,7 @@ impl<'a, T> IntoIterator for &'a DList { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a DList { type Item = &'a T; type IntoIter = Iter<'a, T>; diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index 5c37be188fe..ec30933bd2e 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -268,6 +268,7 @@ impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { type Item = E; type IntoIter = Iter; diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index 0a4ccde9236..29ebb8963ba 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1710,6 +1710,7 @@ impl IntoIterator for RingBuf { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for RingBuf { type Item = T; type IntoIter = IntoIter; @@ -1730,6 +1731,7 @@ impl<'a, T> IntoIterator for &'a RingBuf { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a RingBuf { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -1750,6 +1752,7 @@ impl<'a, T> IntoIterator for &'a mut RingBuf { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut RingBuf { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index f294dd3c3e0..92df05d6ed4 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1425,6 +1425,7 @@ impl IntoIterator for Vec { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for Vec { type Item = T; type IntoIter = IntoIter; @@ -1445,6 +1446,7 @@ impl<'a, T> IntoIterator for &'a Vec { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a Vec { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -1465,6 +1467,7 @@ impl<'a, T> IntoIterator for &'a mut Vec { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut Vec { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 7f9484c58a1..7a2194f8110 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -679,6 +679,7 @@ impl IntoIterator for VecMap { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for VecMap { type Item = (usize, T); type IntoIter = IntoIter; @@ -699,6 +700,7 @@ impl<'a, T> IntoIterator for &'a VecMap { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a VecMap { type Item = (usize, &'a T); type IntoIter = Iter<'a, T>; @@ -719,6 +721,7 @@ impl<'a, T> IntoIterator for &'a mut VecMap { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut VecMap { type Item = (usize, &'a mut T); type IntoIter = IterMut<'a, T>; diff --git a/src/libcore/array.rs b/src/libcore/array.rs index abaa7594d04..886893e647e 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -59,6 +59,7 @@ macro_rules! array_impls { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a [T; $N] { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -79,6 +80,7 @@ macro_rules! array_impls { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut [T; $N] { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 03c473ed967..92a15a09cc0 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -131,8 +131,12 @@ pub trait IntoIterator { #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot /// Conversion into an `Iterator` +#[stable(feature = "rust1", since = "1.0.0")] pub trait IntoIterator { + #[stable(feature = "rust1", since = "1.0.0")] type Item; + + #[stable(feature = "rust1", since = "1.0.0")] type IntoIter: Iterator; /// Consumes `Self` and returns an iterator over it @@ -151,6 +155,7 @@ impl IntoIterator for I where I: Iterator { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for I { type Item = I::Item; type IntoIter = I; diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index cd91843f359..ded76f51b07 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -637,6 +637,7 @@ impl<'a, T> IntoIterator for &'a [T] { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a [T] { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -657,6 +658,7 @@ impl<'a, T> IntoIterator for &'a mut [T] { } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut [T] { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 241e409910f..e11bcec150c 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1387,6 +1387,7 @@ impl<'a, K, V, S, H> IntoIterator for &'a HashMap } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V, S, H> IntoIterator for &'a HashMap where K: Eq + Hash, S: HashState, @@ -1415,6 +1416,7 @@ impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap where K: Eq + Hash, S: HashState, @@ -1443,6 +1445,7 @@ impl IntoIterator for HashMap } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for HashMap where K: Eq + Hash, S: HashState, diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 300e2089317..fb01dc89e68 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -850,6 +850,7 @@ impl<'a, T, S, H> IntoIterator for &'a HashSet } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, S, H> IntoIterator for &'a HashSet where T: Eq + Hash, S: HashState, @@ -878,6 +879,7 @@ impl IntoIterator for HashSet } #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for HashSet where T: Eq + Hash, S: HashState, -- cgit 1.4.1-3-g733a5 From d7b5bc3c2f673ac3edd818cb7bd42555c2cbc2a2 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 13 Feb 2015 22:58:37 +1100 Subject: Update the libraries to reflect Send loosing the 'static bound. In most places this preserves the current API by adding an explicit `'static` bound. Notably absent are some impls like `unsafe impl Send for Foo` and the `std::thread` module. It is likely that it will be possible to remove these after auditing the code to ensure restricted lifetimes are safe. More progress on #22251. --- src/libstd/rt/at_exit_imp.rs | 4 ++-- src/libstd/rt/mod.rs | 2 +- src/libstd/rt/unwind.rs | 4 ++-- src/libstd/sync/future.rs | 8 ++++---- src/libstd/sync/mpsc/mod.rs | 30 +++++++++++++++--------------- src/libstd/sync/mpsc/mpsc_queue.rs | 6 +++--- src/libstd/sync/mpsc/oneshot.rs | 4 ++-- src/libstd/sync/mpsc/select.rs | 6 +++--- src/libstd/sync/mpsc/shared.rs | 4 ++-- src/libstd/sync/mpsc/spsc_queue.rs | 10 +++++----- src/libstd/sync/mpsc/stream.rs | 4 ++-- src/libstd/sync/mpsc/sync.rs | 12 ++++++------ src/libstd/sync/mutex.rs | 8 ++++---- src/libstd/sync/task_pool.rs | 10 +++++----- src/libstd/sys/common/helper_thread.rs | 2 +- src/libstd/thread.rs | 14 +++++++------- src/libstd/thunk.rs | 19 +++++++++++-------- src/libterm/terminfo/mod.rs | 7 +++---- src/libterm/win.rs | 6 +++--- src/libtest/lib.rs | 4 ++-- 20 files changed, 83 insertions(+), 81 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 3f15cf71ec3..72486fc55d4 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -20,7 +20,7 @@ use mem; use thunk::Thunk; use sys_common::mutex::{Mutex, MUTEX_INIT}; -type Queue = Vec; +type Queue = Vec>; // NB these are specifically not types from `std::sync` as they currently rely // on poisoning and this module needs to operate at a lower level than requiring @@ -65,7 +65,7 @@ pub fn cleanup() { } } -pub fn push(f: Thunk) { +pub fn push(f: Thunk<'static>) { unsafe { LOCK.lock(); init(); diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 00088d6d99a..42cca73e5e2 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -148,7 +148,7 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int { /// /// It is forbidden for procedures to register more `at_exit` handlers when they /// are running, and doing so will lead to a process abort. -pub fn at_exit(f: F) { +pub fn at_exit(f: F) { at_exit_imp::push(Thunk::new(f)); } diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index c9bbea27e4a..1f5eb3af695 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -74,7 +74,7 @@ use rt::libunwind as uw; struct Exception { uwe: uw::_Unwind_Exception, - cause: Option>, + cause: Option>, } pub type Callback = fn(msg: &(Any + Send), file: &'static str, line: uint); @@ -161,7 +161,7 @@ pub fn panicking() -> bool { #[inline(never)] #[no_mangle] #[allow(private_no_mangle_fns)] -fn rust_panic(cause: Box) -> ! { +fn rust_panic(cause: Box) -> ! { rtdebug!("begin_unwind()"); unsafe { diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index a230e35dac8..ae2a8db0342 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -46,7 +46,7 @@ pub struct Future { } enum FutureState { - Pending(Thunk<(),A>), + Pending(Thunk<'static,(),A>), Evaluating, Forced(A) } @@ -103,7 +103,7 @@ impl Future { } pub fn from_fn(f: F) -> Future - where F : FnOnce() -> A, F : Send + where F : FnOnce() -> A, F : Send + 'static { /*! * Create a future from a function. @@ -117,7 +117,7 @@ impl Future { } } -impl Future { +impl Future { pub fn from_receiver(rx: Receiver) -> Future { /*! * Create a future from a port @@ -132,7 +132,7 @@ impl Future { } pub fn spawn(blk: F) -> Future - where F : FnOnce() -> A, F : Send + where F : FnOnce() -> A, F : Send + 'static { /*! * Create a future from a unique closure. diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index d783acd57ac..4ba4e544764 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -345,7 +345,7 @@ pub struct Receiver { // The receiver port can be sent from place to place, so long as it // is not used to receive non-sendable things. -unsafe impl Send for Receiver { } +unsafe impl Send for Receiver { } /// An iterator over messages on a receiver, this iterator will block /// whenever `next` is called, waiting for a new message, and `None` will be @@ -364,7 +364,7 @@ pub struct Sender { // The send port can be sent from place to place, so long as it // is not used to send non-sendable things. -unsafe impl Send for Sender { } +unsafe impl Send for Sender { } /// The sending-half of Rust's synchronous channel type. This half can only be /// owned by one task, but it can be cloned to send to other tasks. @@ -373,7 +373,7 @@ pub struct SyncSender { inner: Arc>>, } -unsafe impl Send for SyncSender {} +unsafe impl Send for SyncSender {} impl !Sync for SyncSender {} @@ -485,7 +485,7 @@ impl UnsafeFlavor for Receiver { /// println!("{:?}", rx.recv().unwrap()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn channel() -> (Sender, Receiver) { +pub fn channel() -> (Sender, Receiver) { let a = Arc::new(UnsafeCell::new(oneshot::Packet::new())); (Sender::new(Flavor::Oneshot(a.clone())), Receiver::new(Flavor::Oneshot(a))) } @@ -525,7 +525,7 @@ pub fn channel() -> (Sender, Receiver) { /// assert_eq!(rx.recv().unwrap(), 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn sync_channel(bound: uint) -> (SyncSender, Receiver) { +pub fn sync_channel(bound: uint) -> (SyncSender, Receiver) { let a = Arc::new(UnsafeCell::new(sync::Packet::new(bound))); (SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a))) } @@ -534,7 +534,7 @@ pub fn sync_channel(bound: uint) -> (SyncSender, Receiver) { // Sender //////////////////////////////////////////////////////////////////////////////// -impl Sender { +impl Sender { fn new(inner: Flavor) -> Sender { Sender { inner: UnsafeCell::new(inner), @@ -616,7 +616,7 @@ impl Sender { } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Sender { +impl Clone for Sender { fn clone(&self) -> Sender { let (packet, sleeper, guard) = match *unsafe { self.inner() } { Flavor::Oneshot(ref p) => { @@ -662,7 +662,7 @@ impl Clone for Sender { #[unsafe_destructor] #[stable(feature = "rust1", since = "1.0.0")] -impl Drop for Sender { +impl Drop for Sender { fn drop(&mut self) { match *unsafe { self.inner_mut() } { Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_chan(); }, @@ -677,7 +677,7 @@ impl Drop for Sender { // SyncSender //////////////////////////////////////////////////////////////////////////////// -impl SyncSender { +impl SyncSender { fn new(inner: Arc>>) -> SyncSender { SyncSender { inner: inner } } @@ -717,7 +717,7 @@ impl SyncSender { } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for SyncSender { +impl Clone for SyncSender { fn clone(&self) -> SyncSender { unsafe { (*self.inner.get()).clone_chan(); } return SyncSender::new(self.inner.clone()); @@ -726,7 +726,7 @@ impl Clone for SyncSender { #[unsafe_destructor] #[stable(feature = "rust1", since = "1.0.0")] -impl Drop for SyncSender { +impl Drop for SyncSender { fn drop(&mut self) { unsafe { (*self.inner.get()).drop_chan(); } } @@ -736,7 +736,7 @@ impl Drop for SyncSender { // Receiver //////////////////////////////////////////////////////////////////////////////// -impl Receiver { +impl Receiver { fn new(inner: Flavor) -> Receiver { Receiver { inner: UnsafeCell::new(inner) } } @@ -855,7 +855,7 @@ impl Receiver { } } -impl select::Packet for Receiver { +impl select::Packet for Receiver { fn can_recv(&self) -> bool { loop { let new_port = match *unsafe { self.inner() } { @@ -942,7 +942,7 @@ impl select::Packet for Receiver { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T: Send> Iterator for Iter<'a, T> { +impl<'a, T: Send + 'static> Iterator for Iter<'a, T> { type Item = T; fn next(&mut self) -> Option { self.rx.recv().ok() } @@ -950,7 +950,7 @@ impl<'a, T: Send> Iterator for Iter<'a, T> { #[unsafe_destructor] #[stable(feature = "rust1", since = "1.0.0")] -impl Drop for Receiver { +impl Drop for Receiver { fn drop(&mut self) { match *unsafe { self.inner_mut() } { Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_port(); }, diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 3980d2a1fef..dceef683c2d 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -78,7 +78,7 @@ pub struct Queue { } unsafe impl Send for Queue { } -unsafe impl Sync for Queue { } +unsafe impl Sync for Queue { } impl Node { unsafe fn new(v: Option) -> *mut Node { @@ -89,7 +89,7 @@ impl Node { } } -impl Queue { +impl Queue { /// Creates a new queue that is safe to share among multiple producers and /// one consumer. pub fn new() -> Queue { @@ -140,7 +140,7 @@ impl Queue { #[unsafe_destructor] #[stable(feature = "rust1", since = "1.0.0")] -impl Drop for Queue { +impl Drop for Queue { fn drop(&mut self) { unsafe { let mut cur = *self.tail.get(); diff --git a/src/libstd/sync/mpsc/oneshot.rs b/src/libstd/sync/mpsc/oneshot.rs index eb45681fa62..55b2caf7c6d 100644 --- a/src/libstd/sync/mpsc/oneshot.rs +++ b/src/libstd/sync/mpsc/oneshot.rs @@ -88,7 +88,7 @@ enum MyUpgrade { GoUp(Receiver), } -impl Packet { +impl Packet { pub fn new() -> Packet { Packet { data: None, @@ -368,7 +368,7 @@ impl Packet { } #[unsafe_destructor] -impl Drop for Packet { +impl Drop for Packet { fn drop(&mut self) { assert_eq!(self.state.load(Ordering::SeqCst), DISCONNECTED); } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index 87b2fe8f100..820b2da15ac 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -134,7 +134,7 @@ impl Select { /// Creates a new handle into this receiver set for a new receiver. Note /// that this does *not* add the receiver to the receiver set, for that you /// must call the `add` method on the handle itself. - pub fn handle<'a, T: Send>(&'a self, rx: &'a Receiver) -> Handle<'a, T> { + pub fn handle<'a, T: Send + 'static>(&'a self, rx: &'a Receiver) -> Handle<'a, T> { let id = self.next_id.get(); self.next_id.set(id + 1); Handle { @@ -251,7 +251,7 @@ impl Select { fn iter(&self) -> Packets { Packets { cur: self.head } } } -impl<'rx, T: Send> Handle<'rx, T> { +impl<'rx, T: Send + 'static> Handle<'rx, T> { /// Retrieve the id of this handle. #[inline] pub fn id(&self) -> uint { self.id } @@ -322,7 +322,7 @@ impl Drop for Select { } #[unsafe_destructor] -impl<'rx, T: Send> Drop for Handle<'rx, T> { +impl<'rx, T: Send + 'static> Drop for Handle<'rx, T> { fn drop(&mut self) { unsafe { self.remove() } } diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index 6c31fb92591..3db98a44dd5 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -64,7 +64,7 @@ pub enum Failure { Disconnected, } -impl Packet { +impl Packet { // Creation of a packet *must* be followed by a call to postinit_lock // and later by inherit_blocker pub fn new() -> Packet { @@ -474,7 +474,7 @@ impl Packet { } #[unsafe_destructor] -impl Drop for Packet { +impl Drop for Packet { fn drop(&mut self) { // Note that this load is not only an assert for correctness about // disconnection, but also a proper fence before the read of diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index f0558c33d1e..8e9a14ffafd 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -74,11 +74,11 @@ pub struct Queue { cache_subtractions: AtomicUsize, } -unsafe impl Send for Queue { } +unsafe impl Send for Queue { } -unsafe impl Sync for Queue { } +unsafe impl Sync for Queue { } -impl Node { +impl Node { fn new() -> *mut Node { unsafe { mem::transmute(box Node { @@ -89,7 +89,7 @@ impl Node { } } -impl Queue { +impl Queue { /// Creates a new queue. /// /// This is unsafe as the type system doesn't enforce a single @@ -227,7 +227,7 @@ impl Queue { } #[unsafe_destructor] -impl Drop for Queue { +impl Drop for Queue { fn drop(&mut self) { unsafe { let mut cur = *self.first.get(); diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index ab9bd6b2ed7..395819404c8 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -74,7 +74,7 @@ enum Message { GoUp(Receiver), } -impl Packet { +impl Packet { pub fn new() -> Packet { Packet { queue: unsafe { spsc::Queue::new(128) }, @@ -472,7 +472,7 @@ impl Packet { } #[unsafe_destructor] -impl Drop for Packet { +impl Drop for Packet { fn drop(&mut self) { // Note that this load is not only an assert for correctness about // disconnection, but also a proper fence before the read of diff --git a/src/libstd/sync/mpsc/sync.rs b/src/libstd/sync/mpsc/sync.rs index da3ce51a652..ae96a2491dc 100644 --- a/src/libstd/sync/mpsc/sync.rs +++ b/src/libstd/sync/mpsc/sync.rs @@ -55,9 +55,9 @@ pub struct Packet { lock: Mutex>, } -unsafe impl Send for Packet { } +unsafe impl Send for Packet { } -unsafe impl Sync for Packet { } +unsafe impl Sync for Packet { } struct State { disconnected: bool, // Is the channel disconnected yet? @@ -75,7 +75,7 @@ struct State { canceled: Option<&'static mut bool>, } -unsafe impl Send for State {} +unsafe impl Send for State {} /// Possible flavors of threads who can be blocked on this channel. enum Blocker { @@ -113,7 +113,7 @@ pub enum Failure { /// Atomically blocks the current thread, placing it into `slot`, unlocking `lock` /// in the meantime. This re-locks the mutex upon returning. -fn wait<'a, 'b, T: Send>(lock: &'a Mutex>, +fn wait<'a, 'b, T: Send + 'static>(lock: &'a Mutex>, mut guard: MutexGuard<'b, State>, f: fn(SignalToken) -> Blocker) -> MutexGuard<'a, State> @@ -136,7 +136,7 @@ fn wakeup(token: SignalToken, guard: MutexGuard>) { token.signal(); } -impl Packet { +impl Packet { pub fn new(cap: uint) -> Packet { Packet { channels: AtomicUsize::new(1), @@ -412,7 +412,7 @@ impl Packet { } #[unsafe_destructor] -impl Drop for Packet { +impl Drop for Packet { fn drop(&mut self) { assert_eq!(self.channels.load(Ordering::SeqCst), 0); let mut guard = self.lock.lock().unwrap(); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 74692c1273c..7e27f13f515 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -120,9 +120,9 @@ pub struct Mutex { data: UnsafeCell, } -unsafe impl Send for Mutex { } +unsafe impl Send for Mutex { } -unsafe impl Sync for Mutex { } +unsafe impl Sync for Mutex { } /// The static mutex type is provided to allow for static allocation of mutexes. /// @@ -180,7 +180,7 @@ pub const MUTEX_INIT: StaticMutex = StaticMutex { poison: poison::FLAG_INIT, }; -impl Mutex { +impl Mutex { /// Creates a new mutex in an unlocked state ready for use. #[stable(feature = "rust1", since = "1.0.0")] pub fn new(t: T) -> Mutex { @@ -243,7 +243,7 @@ impl Mutex { #[unsafe_destructor] #[stable(feature = "rust1", since = "1.0.0")] -impl Drop for Mutex { +impl Drop for Mutex { fn drop(&mut self) { // This is actually safe b/c we know that there is no further usage of // this mutex (it's up to the user to arrange for a mutex to get diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 684a46fd6ff..831c4d315b1 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -24,12 +24,12 @@ use thread::Thread; use thunk::Thunk; struct Sentinel<'a> { - jobs: &'a Arc>>, + jobs: &'a Arc>>>, active: bool } impl<'a> Sentinel<'a> { - fn new(jobs: &Arc>>) -> Sentinel { + fn new(jobs: &'a Arc>>>) -> Sentinel<'a> { Sentinel { jobs: jobs, active: true @@ -80,7 +80,7 @@ pub struct TaskPool { // // This is the only such Sender, so when it is dropped all subthreads will // quit. - jobs: Sender + jobs: Sender> } impl TaskPool { @@ -105,13 +105,13 @@ impl TaskPool { /// Executes the function `job` on a thread in the pool. pub fn execute(&self, job: F) - where F : FnOnce(), F : Send + where F : FnOnce(), F : Send + 'static { self.jobs.send(Thunk::new(job)).unwrap(); } } -fn spawn_in_pool(jobs: Arc>>) { +fn spawn_in_pool(jobs: Arc>>>) { Thread::spawn(move || { // Will spawn a new thread on panic unless it is cancelled. let sentinel = Sentinel::new(&jobs); diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs index 255f474d4f4..ad2f733165e 100644 --- a/src/libstd/sys/common/helper_thread.rs +++ b/src/libstd/sys/common/helper_thread.rs @@ -81,7 +81,7 @@ impl Helper { /// /// This function is safe to be called many times. pub fn boot(&'static self, f: F, helper: fn(helper_signal::signal, Receiver, T)) where - T: Send, + T: Send + 'static, F: FnOnce() -> T, { unsafe { diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index cc9d7492441..3b758c83980 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -175,9 +175,9 @@ pub struct Builder { // The size of the stack for the spawned thread stack_size: Option, // Thread-local stdout - stdout: Option>, + stdout: Option>, // Thread-local stderr - stderr: Option>, + stderr: Option>, } impl Builder { @@ -211,7 +211,7 @@ impl Builder { /// Redirect thread-local stdout. #[unstable(feature = "std_misc", reason = "Will likely go away after proc removal")] - pub fn stdout(mut self, stdout: Box) -> Builder { + pub fn stdout(mut self, stdout: Box) -> Builder { self.stdout = Some(stdout); self } @@ -219,7 +219,7 @@ impl Builder { /// Redirect thread-local stderr. #[unstable(feature = "std_misc", reason = "Will likely go away after proc removal")] - pub fn stderr(mut self, stderr: Box) -> Builder { + pub fn stderr(mut self, stderr: Box) -> Builder { self.stderr = Some(stderr); self } @@ -469,11 +469,11 @@ impl thread_info::NewThread for Thread { /// /// A thread that completes without panicking is considered to exit successfully. #[stable(feature = "rust1", since = "1.0.0")] -pub type Result = ::result::Result>; +pub type Result = ::result::Result>; struct Packet(Arc>>>); -unsafe impl Send for Packet {} +unsafe impl Send for Packet {} unsafe impl Sync for Packet {} /// An RAII-style guard that will block until thread termination when dropped. @@ -515,7 +515,7 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> { } } -impl JoinGuard<'static, T> { +impl JoinGuard<'static, T> { /// Detaches the child thread, allowing it to outlive its parent. #[unstable(feature = "std_misc", reason = "unsure whether this API imposes limitations elsewhere")] diff --git a/src/libstd/thunk.rs b/src/libstd/thunk.rs index 0831242f954..1412dbd70b9 100644 --- a/src/libstd/thunk.rs +++ b/src/libstd/thunk.rs @@ -16,21 +16,24 @@ use alloc::boxed::Box; use core::marker::Send; use core::ops::FnOnce; -pub struct Thunk { - invoke: Box+Send> +pub struct Thunk<'a, A=(),R=()> { + #[cfg(stage0)] // // SNAP ac134f7 remove after stage0 + invoke: Box+Send>, + #[cfg(not(stage0))] + invoke: Box+Send + 'a>, } -impl Thunk<(),R> { - pub fn new(func: F) -> Thunk<(),R> - where F : FnOnce() -> R, F : Send +impl<'a, R> Thunk<'a,(),R> { + pub fn new(func: F) -> Thunk<'a,(),R> + where F : FnOnce() -> R, F : Send + 'a { Thunk::with_arg(move|()| func()) } } -impl Thunk { - pub fn with_arg(func: F) -> Thunk - where F : FnOnce(A) -> R, F : Send +impl<'a,A,R> Thunk<'a,A,R> { + pub fn with_arg(func: F) -> Thunk<'a,A,R> + where F : FnOnce(A) -> R, F : Send + 'a { Thunk { invoke: box func diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index 758191a6e11..b978d2d8054 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -72,7 +72,7 @@ pub struct TerminfoTerminal { ti: Box } -impl Terminal for TerminfoTerminal { +impl Terminal for TerminfoTerminal { fn fg(&mut self, color: color::Color) -> IoResult { let color = self.dim_if_necessary(color); if self.num_colors > color { @@ -164,11 +164,11 @@ impl Terminal for TerminfoTerminal { fn get_mut<'a>(&'a mut self) -> &'a mut T { &mut self.out } } -impl UnwrappableTerminal for TerminfoTerminal { +impl UnwrappableTerminal for TerminfoTerminal { fn unwrap(self) -> T { self.out } } -impl TerminfoTerminal { +impl TerminfoTerminal { /// Returns `None` whenever the terminal cannot be created for some /// reason. pub fn new(out: T) -> Option+Send+'static>> { @@ -229,4 +229,3 @@ impl Writer for TerminfoTerminal { self.out.flush() } } - diff --git a/src/libterm/win.rs b/src/libterm/win.rs index a56613681c8..e93b956dc7c 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -86,7 +86,7 @@ fn bits_to_color(bits: u16) -> color::Color { color | (bits & 0x8) // copy the hi-intensity bit } -impl WinConsole { +impl WinConsole { fn apply(&mut self) { let _unused = self.buf.flush(); let mut accum: libc::WORD = 0; @@ -139,7 +139,7 @@ impl Writer for WinConsole { } } -impl Terminal for WinConsole { +impl Terminal for WinConsole { fn fg(&mut self, color: color::Color) -> IoResult { self.foreground = color; self.apply(); @@ -192,6 +192,6 @@ impl Terminal for WinConsole { fn get_mut<'a>(&'a mut self) -> &'a mut T { &mut self.buf } } -impl UnwrappableTerminal for WinConsole { +impl UnwrappableTerminal for WinConsole { fn unwrap(self) -> T { self.buf } } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 860ce209d45..fea92256f9b 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -154,7 +154,7 @@ pub enum TestFn { StaticTestFn(fn()), StaticBenchFn(fn(&mut Bencher)), StaticMetricFn(fn(&mut MetricMap)), - DynTestFn(Thunk), + DynTestFn(Thunk<'static>), DynMetricFn(Box Invoke<&'a mut MetricMap>+'static>), DynBenchFn(Box) } @@ -878,7 +878,7 @@ pub fn run_test(opts: &TestOpts, fn run_test_inner(desc: TestDesc, monitor_ch: Sender, nocapture: bool, - testfn: Thunk) { + testfn: Thunk<'static>) { Thread::spawn(move || { let (tx, rx) = channel(); let mut reader = ChanReader::new(rx); -- cgit 1.4.1-3-g733a5 From adfcd93f0c3b624399934558f63d945b7b6b663a Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 17 Feb 2015 23:09:14 +1100 Subject: Add missing marker to std::thread::JoinGuard. The lifetime was previously, incorrectly unconstrained. --- src/libstd/thread.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 3b758c83980..c662a1dafa1 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -151,7 +151,7 @@ use any::Any; use boxed::Box; use cell::UnsafeCell; use clone::Clone; -use marker::{Send, Sync}; +use marker::{Send, Sync, CovariantType}; use ops::{Drop, FnOnce}; use option::Option::{self, Some, None}; use result::Result::{Err, Ok}; @@ -255,6 +255,7 @@ impl Builder { joined: false, packet: my_packet, thread: thread, + _marker: CovariantType, } } @@ -487,6 +488,7 @@ pub struct JoinGuard<'a, T: 'a> { thread: Thread, joined: bool, packet: Packet, + _marker: CovariantType<&'a T>, } #[stable(feature = "rust1", since = "1.0.0")] -- cgit 1.4.1-3-g733a5 From 235f35b0b724a38a5583112825d46f50c5dde980 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 13:58:34 -0800 Subject: std: Stabilize the `ascii` module This commit performs a stabilization pass over the `std::ascii` module taking the following actions: * the module name is now stable * `AsciiExt` is now stable after moving its type parameter to an `Owned` associated type * `AsciiExt::is_ascii` is now stable * `AsciiExt::to_ascii_uppercase` is now stable * `AsciiExt::to_ascii_lowercase` is now stable * `AsciiExt::eq_ignore_ascii_case` is now stable * `AsciiExt::make_ascii_uppercase` is added to possibly replace `OwnedAsciiExt::into_ascii_uppercase` (similarly for lowercase variants). * `escape_default` now returns an iterator and is stable * `EscapeDefault` is now stable Trait implementations are now also marked stable. Primarily it is still unstable to *implement* the `AsciiExt` trait due to it containing some unstable methods. [breaking-change] --- src/libstd/ascii.rs | 192 +++++++++++++++++++++++++++--------------- src/libstd/sys/common/wtf8.rs | 7 +- src/libsyntax/print/pprust.rs | 10 +-- src/libterm/lib.rs | 1 - 4 files changed, 132 insertions(+), 78 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 0a3abd5d1ac..4d38d17576d 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -12,15 +12,12 @@ //! Operations on ASCII strings and characters -#![unstable(feature = "std_misc", - reason = "unsure about placement and naming")] +#![stable(feature = "rust1", since = "1.0.0")] -use iter::IteratorExt; -use ops::FnMut; -use slice::SliceExt; -use str::StrExt; -use string::String; -use vec::Vec; +use prelude::v1::*; + +use mem; +use iter::Range; /// Extension methods for ASCII-subset only operations on owned strings #[unstable(feature = "std_misc", @@ -38,31 +35,50 @@ pub trait OwnedAsciiExt { } /// Extension methods for ASCII-subset only operations on string slices -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] -pub trait AsciiExt { +#[stable(feature = "rust1", since = "1.0.0")] +pub trait AsciiExt { + #[stable(feature = "rust1", since = "1.0.0")] + type Owned; + /// Check if within the ASCII range. + #[stable(feature = "rust1", since = "1.0.0")] fn is_ascii(&self) -> bool; /// Makes a copy of the string in ASCII upper case: /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', /// but non-ASCII letters are unchanged. - fn to_ascii_uppercase(&self) -> T; + #[stable(feature = "rust1", since = "1.0.0")] + fn to_ascii_uppercase(&self) -> Self::Owned; /// Makes a copy of the string in ASCII lower case: /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', /// but non-ASCII letters are unchanged. - fn to_ascii_lowercase(&self) -> T; + #[stable(feature = "rust1", since = "1.0.0")] + fn to_ascii_lowercase(&self) -> Self::Owned; /// Check that two strings are an ASCII case-insensitive match. /// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`, /// but without allocating and copying temporary strings. + #[stable(feature = "rust1", since = "1.0.0")] fn eq_ignore_ascii_case(&self, other: &Self) -> bool; + + /// Convert this type to its ASCII upper case equivalent in-place. + /// + /// See `to_ascii_uppercase` for more information. + #[unstable(feature = "ascii")] + fn make_ascii_uppercase(&mut self); + + /// Convert this type to its ASCII lower case equivalent in-place. + /// + /// See `to_ascii_lowercase` for more information. + #[unstable(feature = "ascii")] + fn make_ascii_lowercase(&mut self); } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] -impl AsciiExt for str { +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for str { + type Owned = String; + #[inline] fn is_ascii(&self) -> bool { self.bytes().all(|b| b.is_ascii()) @@ -70,20 +86,28 @@ impl AsciiExt for str { #[inline] fn to_ascii_uppercase(&self) -> String { - // Vec::to_ascii_uppercase() preserves the UTF-8 invariant. - unsafe { String::from_utf8_unchecked(self.as_bytes().to_ascii_uppercase()) } + self.to_string().into_ascii_uppercase() } #[inline] fn to_ascii_lowercase(&self) -> String { - // Vec::to_ascii_lowercase() preserves the UTF-8 invariant. - unsafe { String::from_utf8_unchecked(self.as_bytes().to_ascii_lowercase()) } + self.to_string().into_ascii_lowercase() } #[inline] fn eq_ignore_ascii_case(&self, other: &str) -> bool { self.as_bytes().eq_ignore_ascii_case(other.as_bytes()) } + + fn make_ascii_uppercase(&mut self) { + let me: &mut [u8] = unsafe { mem::transmute(self) }; + me.make_ascii_uppercase() + } + + fn make_ascii_lowercase(&mut self) { + let me: &mut [u8] = unsafe { mem::transmute(self) }; + me.make_ascii_lowercase() + } } #[unstable(feature = "std_misc", @@ -102,9 +126,9 @@ impl OwnedAsciiExt for String { } } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] -impl AsciiExt> for [u8] { +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for [u8] { + type Owned = Vec; #[inline] fn is_ascii(&self) -> bool { self.iter().all(|b| b.is_ascii()) @@ -112,12 +136,12 @@ impl AsciiExt> for [u8] { #[inline] fn to_ascii_uppercase(&self) -> Vec { - self.iter().map(|b| b.to_ascii_uppercase()).collect() + self.to_vec().into_ascii_uppercase() } #[inline] fn to_ascii_lowercase(&self) -> Vec { - self.iter().map(|b| b.to_ascii_lowercase()).collect() + self.to_vec().into_ascii_lowercase() } #[inline] @@ -127,6 +151,18 @@ impl AsciiExt> for [u8] { a.eq_ignore_ascii_case(b) }) } + + fn make_ascii_uppercase(&mut self) { + for byte in self { + byte.make_ascii_uppercase(); + } + } + + fn make_ascii_lowercase(&mut self) { + for byte in self { + byte.make_ascii_lowercase(); + } + } } #[unstable(feature = "std_misc", @@ -134,48 +170,39 @@ impl AsciiExt> for [u8] { impl OwnedAsciiExt for Vec { #[inline] fn into_ascii_uppercase(mut self) -> Vec { - for byte in &mut self { - *byte = byte.to_ascii_uppercase(); - } + self.make_ascii_uppercase(); self } #[inline] fn into_ascii_lowercase(mut self) -> Vec { - for byte in &mut self { - *byte = byte.to_ascii_lowercase(); - } + self.make_ascii_lowercase(); self } } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] +#[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for u8 { + type Owned = u8; #[inline] - fn is_ascii(&self) -> bool { - *self & 128 == 0u8 - } - + fn is_ascii(&self) -> bool { *self & 128 == 0u8 } #[inline] - fn to_ascii_uppercase(&self) -> u8 { - ASCII_UPPERCASE_MAP[*self as usize] - } - + fn to_ascii_uppercase(&self) -> u8 { ASCII_UPPERCASE_MAP[*self as usize] } #[inline] - fn to_ascii_lowercase(&self) -> u8 { - ASCII_LOWERCASE_MAP[*self as usize] - } - + fn to_ascii_lowercase(&self) -> u8 { ASCII_LOWERCASE_MAP[*self as usize] } #[inline] fn eq_ignore_ascii_case(&self, other: &u8) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() } + #[inline] + fn make_ascii_uppercase(&mut self) { *self = self.to_ascii_uppercase(); } + #[inline] + fn make_ascii_lowercase(&mut self) { *self = self.to_ascii_lowercase(); } } -#[unstable(feature = "std_misc", - reason = "would prefer to do this in a more general way")] +#[stable(feature = "rust1", since = "1.0.0")] impl AsciiExt for char { + type Owned = char; #[inline] fn is_ascii(&self) -> bool { *self as u32 <= 0x7F @@ -203,6 +230,19 @@ impl AsciiExt for char { fn eq_ignore_ascii_case(&self, other: &char) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() } + + #[inline] + fn make_ascii_uppercase(&mut self) { *self = self.to_ascii_uppercase(); } + #[inline] + fn make_ascii_lowercase(&mut self) { *self = self.to_ascii_lowercase(); } +} + +/// An iterator over the escaped version of a byte, constructed via +/// `std::ascii::escape_default`. +#[stable(feature = "rust1", since = "1.0.0")] +pub struct EscapeDefault { + range: Range, + data: [u8; 4], } /// Returns a 'default' ASCII and C++11-like literal escape of a `u8` @@ -214,34 +254,46 @@ impl AsciiExt for char { /// - Tab, CR and LF are escaped as '\t', '\r' and '\n' respectively. /// - Single-quote, double-quote and backslash chars are backslash-escaped. /// - Any other chars in the range [0x20,0x7e] are not escaped. -/// - Any other chars are given hex escapes. +/// - Any other chars are given hex escapes of the form '\xNN'. /// - Unicode escapes are never generated by this function. -#[unstable(feature = "std_misc", - reason = "needs to be updated to use an iterator")] -pub fn escape_default(c: u8, mut f: F) where - F: FnMut(u8), -{ - match c { - b'\t' => { f(b'\\'); f(b't'); } - b'\r' => { f(b'\\'); f(b'r'); } - b'\n' => { f(b'\\'); f(b'n'); } - b'\\' => { f(b'\\'); f(b'\\'); } - b'\'' => { f(b'\\'); f(b'\''); } - b'"' => { f(b'\\'); f(b'"'); } - b'\x20' ... b'\x7e' => { f(c); } - _ => { - f(b'\\'); - f(b'x'); - for &offset in &[4u, 0u] { - match ((c as i32) >> offset) & 0xf { - i @ 0 ... 9 => f(b'0' + (i as u8)), - i => f(b'a' + (i as u8 - 10)), - } - } +#[stable(feature = "rust1", since = "1.0.0")] +pub fn escape_default(c: u8) -> EscapeDefault { + let (data, len) = match c { + b'\t' => ([b'\\', b't', 0, 0], 2), + b'\r' => ([b'\\', b'r', 0, 0], 2), + b'\n' => ([b'\\', b'n', 0, 0], 2), + b'\\' => ([b'\\', b'\\', 0, 0], 2), + b'\'' => ([b'\\', b'\'', 0, 0], 2), + b'"' => ([b'\\', b'"', 0, 0], 2), + b'\x20' ... b'\x7e' => ([c, 0, 0, 0], 1), + _ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4), + }; + + return EscapeDefault { range: range(0, len), data: data }; + + fn hexify(b: u8) -> u8 { + match b { + 0 ... 9 => b'0' + b, + _ => b'a' + b - 10, } } } +#[stable(feature = "rust1", since = "1.0.0")] +impl Iterator for EscapeDefault { + type Item = u8; + fn next(&mut self) -> Option { self.range.next().map(|i| self.data[i]) } + fn size_hint(&self) -> (usize, Option) { self.range.size_hint() } +} +#[stable(feature = "rust1", since = "1.0.0")] +impl DoubleEndedIterator for EscapeDefault { + fn next_back(&mut self) -> Option { + self.range.next_back().map(|i| self.data[i]) + } +} +#[stable(feature = "rust1", since = "1.0.0")] +impl ExactSizeIterator for EscapeDefault {} + static ASCII_LOWERCASE_MAP: [u8; 256] = [ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 6047f94b3b4..b610f6c370b 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -817,7 +817,9 @@ impl<'a, S: Writer + Hasher> Hash for Wtf8 { } } -impl AsciiExt for Wtf8 { +impl AsciiExt for Wtf8 { + type Owned = Wtf8Buf; + fn is_ascii(&self) -> bool { self.bytes.is_ascii() } @@ -830,6 +832,9 @@ impl AsciiExt for Wtf8 { fn eq_ignore_ascii_case(&self, other: &Wtf8) -> bool { self.bytes.eq_ignore_ascii_case(&other.bytes) } + + fn make_ascii_uppercase(&mut self) { self.bytes.make_ascii_uppercase() } + fn make_ascii_lowercase(&mut self) { self.bytes.make_ascii_lowercase() } } #[cfg(test)] diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 583095e1574..4b021f2434f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2761,15 +2761,13 @@ impl<'a> State<'a> { ast::LitStr(ref st, style) => self.print_string(&st, style), ast::LitByte(byte) => { let mut res = String::from_str("b'"); - ascii::escape_default(byte, |c| res.push(c as char)); + res.extend(ascii::escape_default(byte).map(|c| c as char)); res.push('\''); word(&mut self.s, &res[]) } ast::LitChar(ch) => { let mut res = String::from_str("'"); - for c in ch.escape_default() { - res.push(c); - } + res.extend(ch.escape_default()); res.push('\''); word(&mut self.s, &res[]) } @@ -2809,8 +2807,8 @@ impl<'a> State<'a> { ast::LitBinary(ref v) => { let mut escaped: String = String::new(); for &ch in &**v { - ascii::escape_default(ch as u8, - |ch| escaped.push(ch as char)); + escaped.extend(ascii::escape_default(ch as u8) + .map(|c| c as char)); } word(&mut self.s, &format!("b\"{}\"", escaped)[]) } diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index c4b3d2813af..276e2f3ca38 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -58,7 +58,6 @@ #![feature(path)] #![feature(rustc_private)] #![feature(staged_api)] -#![feature(std_misc)] #![feature(unicode)] #![feature(env)] #![cfg_attr(windows, feature(libc))] -- cgit 1.4.1-3-g733a5 From a2ebb24ee6cc76791ef834cb2d17ecac95756499 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 11:05:44 -0800 Subject: std: Rename io/path features with old_ prefix This commit renames the features for the `std::old_io` and `std::old_path` modules to `old_io` and `old_path` to help facilitate migration to the new APIs. This is a breaking change as crates which mention the old feature names now need to be renamed to use the new feature names. [breaking-change] --- src/compiletest/compiletest.rs | 4 ++-- src/libgraphviz/lib.rs | 2 +- src/liblog/lib.rs | 2 +- src/librbml/lib.rs | 2 +- src/librustc/lib.rs | 4 ++-- src/librustc_back/lib.rs | 4 ++-- src/librustc_driver/lib.rs | 4 ++-- src/librustc_llvm/lib.rs | 2 +- src/librustc_trans/lib.rs | 4 ++-- src/librustdoc/lib.rs | 4 ++-- src/libserialize/lib.rs | 4 ++-- src/libstd/old_io/mod.rs | 2 +- src/libstd/old_path/mod.rs | 2 +- src/libsyntax/lib.rs | 4 ++-- src/libterm/lib.rs | 4 ++-- src/libtest/lib.rs | 4 ++-- src/rustbook/main.rs | 4 ++-- src/test/compile-fail/lint-uppercase-variables.rs | 17 ++++++++--------- 18 files changed, 36 insertions(+), 37 deletions(-) (limited to 'src/libstd') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 6b6251a96c9..df94f7613eb 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -13,8 +13,8 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(unboxed_closures)] #![feature(std_misc)] diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index a1a271bc5ab..230deabee00 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -276,7 +276,7 @@ #![feature(int_uint)] #![feature(collections)] #![feature(core)] -#![feature(io)] +#![feature(old_io)] use self::LabelText::*; diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 5edb4a96a7d..4dab07acfd2 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -171,7 +171,7 @@ #![feature(box_syntax)] #![feature(int_uint)] #![feature(core)] -#![feature(io)] +#![feature(old_io)] #![feature(std_misc)] #![feature(env)] diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 154dbbdb750..488d5999323 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -28,7 +28,7 @@ #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index abf70813d36..fe9a81bb7c9 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -29,10 +29,10 @@ #![feature(core)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] #![feature(env)] -#![feature(path)] +#![feature(old_path)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 54b3e8f2081..d589b063204 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -35,9 +35,9 @@ #![feature(core)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(env)] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 9b8ca398b12..6357a2b115b 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -28,10 +28,10 @@ #![feature(core)] #![feature(env)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 213e3565362..cc8ec4b40cb 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -29,7 +29,7 @@ #![feature(int_uint)] #![feature(libc)] #![feature(link_args)] -#![feature(path)] +#![feature(old_path)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 21557379e3a..4606200d058 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -30,10 +30,10 @@ #![feature(core)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(env)] #![feature(libc)] -#![feature(path)] +#![feature(old_path)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b09c3f730fc..883f10be3a1 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -25,10 +25,10 @@ #![feature(env)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 6cada2e5614..853da598ab5 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -29,8 +29,8 @@ Core encoding and decoding interfaces. #![feature(collections)] #![feature(core)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(hash)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/libstd/old_io/mod.rs b/src/libstd/old_io/mod.rs index 3673f590c0a..d3f31ed6b75 100644 --- a/src/libstd/old_io/mod.rs +++ b/src/libstd/old_io/mod.rs @@ -238,7 +238,7 @@ //! concerned with error handling; instead its caller is responsible for //! responding to errors that may occur while attempting to read the numbers. -#![unstable(feature = "io")] +#![unstable(feature = "old_io")] #![deny(unused_must_use)] pub use self::SeekStyle::*; diff --git a/src/libstd/old_path/mod.rs b/src/libstd/old_path/mod.rs index 17cfe1c8297..37de2993c4d 100644 --- a/src/libstd/old_path/mod.rs +++ b/src/libstd/old_path/mod.rs @@ -59,7 +59,7 @@ //! println!("path exists: {}", path.exists()); //! ``` -#![unstable(feature = "path")] +#![unstable(feature = "old_path")] use core::marker::Sized; use ffi::CString; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index f4b0c867f42..e8bdcd62b58 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -30,9 +30,9 @@ #![feature(env)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] +#![feature(old_io)] #![feature(libc)] -#![feature(path)] +#![feature(old_path)] #![feature(quote, unsafe_destructor)] #![feature(rustc_private)] #![feature(staged_api)] diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index c4b3d2813af..81534dbe4c4 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -54,8 +54,8 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 860ce209d45..0f90fbdfe0f 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -39,8 +39,8 @@ #![feature(env)] #![feature(hash)] #![feature(int_uint)] -#![feature(io)] -#![feature(path)] +#![feature(old_io)] +#![feature(old_path)] #![feature(rustc_private)] #![feature(staged_api)] #![feature(std_misc)] diff --git a/src/rustbook/main.rs b/src/rustbook/main.rs index a8466465f87..c0e9cac2813 100644 --- a/src/rustbook/main.rs +++ b/src/rustbook/main.rs @@ -11,9 +11,9 @@ #![feature(box_syntax)] #![feature(collections)] #![feature(core)] -#![feature(io)] +#![feature(old_io)] #![feature(os)] -#![feature(path)] +#![feature(old_path)] #![feature(rustdoc)] extern crate rustdoc; diff --git a/src/test/compile-fail/lint-uppercase-variables.rs b/src/test/compile-fail/lint-uppercase-variables.rs index 057b8e3acc6..b68d9dc4645 100644 --- a/src/test/compile-fail/lint-uppercase-variables.rs +++ b/src/test/compile-fail/lint-uppercase-variables.rs @@ -12,12 +12,14 @@ #![allow(dead_code)] #![deny(non_snake_case)] -#![feature(path)] -#![feature(io)] use std::old_io::File; use std::old_io::IoError; +mod foo { + pub enum Foo { Foo } +} + struct Something { X: usize //~ ERROR structure field `X` should have a snake case name such as `x` } @@ -30,13 +32,10 @@ fn main() { let Test: usize = 0; //~ ERROR variable `Test` should have a snake case name such as `test` println!("{}", Test); - let mut f = File::open(&Path::new("something.txt")); - let mut buff = [0u8; 16]; - match f.read(&mut buff) { - Ok(cnt) => println!("read this many bytes: {}", cnt), - Err(IoError{ kind: EndOfFile, .. }) => println!("Got end of file: {:?}", EndOfFile), -//~^ ERROR variable `EndOfFile` should have a snake case name such as `end_of_file` -//~^^ WARN `EndOfFile` is named the same as one of the variants of the type `std::old_io::IoErrorKind` + match foo::Foo::Foo { + Foo => {} +//~^ ERROR variable `Foo` should have a snake case name such as `foo` +//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo` } test(1); -- cgit 1.4.1-3-g733a5 From d8f8f7a58c7c8b3352c1c577347865f5a823fee3 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Tue, 17 Feb 2015 01:08:53 -0800 Subject: Revise std::thread semantics This commit makes several changes to `std::thread` in preparation for final stabilization: * It removes the ability to handle panics from `scoped` children; see #20807 for discussion * It adds a `JoinHandle` structure, now returned from `spawn`, which makes it possible to join on children that do not share data from their parent's stack. The child is automatically detached when the handle is dropped, and the handle cannot be copied due to Posix semantics. * It moves all static methods from `std::thread::Thread` to free functions in `std::thread`. This was done in part because, due to the above changes, there are effectively no direct `Thread` constructors, and the static methods have tended to feel a bit awkward. * Adds an `io::Result` around the `Builder` methods `scoped` and `spawn`, making it possible to handle OS errors when creating threads. The convenience free functions entail an unwrap. * Stabilizes the entire module. Despite the fact that the API is changing somewhat here, this is part of a long period of baking and the changes are addressing all known issues prior to alpha2. If absolutely necessary, further breaking changes can be made prior to beta. Closes #20807 [breaking-change] --- src/libstd/sys/unix/thread.rs | 8 +- src/libstd/sys/windows/thread.rs | 8 +- src/libstd/thread.rs | 370 ++++++++++++++++++++++++++++----------- 3 files changed, 273 insertions(+), 113 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 6f030ee91fe..82c52471d10 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -10,6 +10,7 @@ use core::prelude::*; +use io; use boxed::Box; use cmp; use mem; @@ -191,7 +192,7 @@ pub mod guard { } } -pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { +pub unsafe fn create(stack: uint, p: Thunk) -> io::Result { let mut native: libc::pthread_t = mem::zeroed(); let mut attr: libc::pthread_attr_t = mem::zeroed(); assert_eq!(pthread_attr_init(&mut attr), 0); @@ -226,9 +227,10 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { if ret != 0 { // be sure to not leak the closure let _p: Box> = mem::transmute(arg); - panic!("failed to spawn native thread: {}", ret); + Err(io::Error::from_os_error(ret)) + } else { + Ok(native) } - native } #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index a38dc9b2d34..d7f86e1842e 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -10,6 +10,7 @@ use boxed::Box; use cmp; +use io; use mem; use ptr; use libc; @@ -42,7 +43,7 @@ pub mod guard { } } -pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { +pub unsafe fn create(stack: uint, p: Thunk) -> io::Result { let arg: *mut libc::c_void = mem::transmute(box p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -60,9 +61,10 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { if ret as uint == 0 { // be sure to not leak the closure let _p: Box = mem::transmute(arg); - panic!("failed to spawn native thread: {:?}", ret); + Err(io::Error::last_os_error()) + } else { + Ok(ret) } - return ret; } pub unsafe fn set_name(_name: &str) { diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index cc9d7492441..4f667114d38 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -58,16 +58,16 @@ //! ```rust //! use std::thread::Thread; //! -//! let thread = Thread::spawn(move || { +//! Thread::spawn(move || { //! println!("Hello, World!"); //! // some computation here //! }); //! ``` //! -//! The spawned thread is "detached" from the current thread, meaning that it -//! can outlive the thread that spawned it. (Note, however, that when the main -//! thread terminates all detached threads are terminated as well.) The returned -//! `Thread` handle can be used for low-level synchronization as described below. +//! In this example, the spawned thread is "detached" from the current +//! thread, meaning that it can outlive the thread that spawned +//! it. (Note, however, that when the main thread terminates all +//! detached threads are terminated as well.) //! //! ## Scoped threads //! @@ -86,13 +86,13 @@ //! let result = guard.join(); //! ``` //! -//! The `scoped` function doesn't return a `Thread` directly; instead, it -//! returns a *join guard* from which a `Thread` can be extracted. The join -//! guard is an RAII-style guard that will automatically join the child thread -//! (block until it terminates) when it is dropped. You can join the child -//! thread in advance by calling the `join` method on the guard, which will also -//! return the result produced by the thread. A handle to the thread itself is -//! available via the `thread` method on the join guard. +//! The `scoped` function doesn't return a `Thread` directly; instead, +//! it returns a *join guard*. The join guard is an RAII-style guard +//! that will automatically join the child thread (block until it +//! terminates) when it is dropped. You can join the child thread in +//! advance by calling the `join` method on the guard, which will also +//! return the result produced by the thread. A handle to the thread +//! itself is available via the `thread` method on the join guard. //! //! (Note: eventually, the `scoped` constructor will allow the parent and child //! threads to data that lives on the parent thread's stack, but some language @@ -151,6 +151,8 @@ use any::Any; use boxed::Box; use cell::UnsafeCell; use clone::Clone; +use fmt; +use io; use marker::{Send, Sync}; use ops::{Drop, FnOnce}; use option::Option::{self, Some, None}; @@ -224,49 +226,58 @@ impl Builder { self } - /// Spawn a new detached thread, and return a handle to it. + /// Spawn a new thread, and return a join handle for it. /// - /// See `Thead::spawn` and the module doc for more details. - #[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] - pub fn spawn(self, f: F) -> Thread where F: FnOnce(), F: Send + 'static { - let (native, thread) = self.spawn_inner(Thunk::new(f), Thunk::with_arg(|_| {})); - unsafe { imp::detach(native) }; - thread + /// The child thread may outlive the parent (unless the parent thread + /// is the main thread; the whole process is terminated when the main + /// thread finishes.) The join handle can be used to block on + /// termination of the child thread, including recovering its panics. + /// + /// # Errors + /// + /// Unlike the `spawn` free function, this method yields an + /// `io::Result` to capture any failure to create the thread at + /// the OS level. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn spawn(self, f: F) -> io::Result where + F: FnOnce(), F: Send + 'static + { + self.spawn_inner(Thunk::new(f)).map(|i| JoinHandle(i)) } /// Spawn a new child thread that must be joined within a given /// scope, and return a `JoinGuard`. /// - /// See `Thead::scoped` and the module doc for more details. - #[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] - pub fn scoped<'a, T, F>(self, f: F) -> JoinGuard<'a, T> where + /// The join guard can be used to explicitly join the child thread (via + /// `join`), returning `Result`, or it will implicitly join the child + /// upon being dropped. Because the child thread may refer to data on the + /// current thread's stack (hence the "scoped" name), it cannot be detached; + /// it *must* be joined before the relevant stack frame is popped. See the + /// module documentation for additional details. + /// + /// # Errors + /// + /// Unlike the `scoped` free function, this method yields an + /// `io::Result` to capture any failure to create the thread at + /// the OS level. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn scoped<'a, T, F>(self, f: F) -> io::Result> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { - let my_packet = Packet(Arc::new(UnsafeCell::new(None))); - let their_packet = Packet(my_packet.0.clone()); - let (native, thread) = self.spawn_inner(Thunk::new(f), Thunk::with_arg(move |ret| unsafe { - *their_packet.0.get() = Some(ret); - })); - - JoinGuard { - native: native, - joined: false, - packet: my_packet, - thread: thread, - } + self.spawn_inner(Thunk::new(f)).map(JoinGuard) } - fn spawn_inner(self, f: Thunk<(), T>, finish: Thunk, ()>) - -> (imp::rust_thread, Thread) - { + fn spawn_inner(self, f: Thunk<(), T>) -> io::Result> { let Builder { name, stack_size, stdout, stderr } = self; let stack_size = stack_size.unwrap_or(rt::min_stack()); + let my_thread = Thread::new(name); let their_thread = my_thread.clone(); + let my_packet = Packet(Arc::new(UnsafeCell::new(None))); + let their_packet = Packet(my_packet.0.clone()); + // Spawning a new OS thread guarantees that __morestack will never get // triggered, but we must manually set up the actual stack bounds once // this function starts executing. This raises the lower limit by a bit @@ -316,17 +327,120 @@ impl Builder { unwind::try(move || *ptr = Some(f.invoke(()))) } }; - finish.invoke(match (output, try_result) { - (Some(data), Ok(_)) => Ok(data), - (None, Err(cause)) => Err(cause), - _ => unreachable!() - }); + unsafe { + *their_packet.0.get() = Some(match (output, try_result) { + (Some(data), Ok(_)) => Ok(data), + (None, Err(cause)) => Err(cause), + _ => unreachable!() + }); + } }; - (unsafe { imp::create(stack_size, Thunk::new(main)) }, my_thread) + Ok(JoinInner { + native: try!(unsafe { imp::create(stack_size, Thunk::new(main)) }), + thread: my_thread, + packet: my_packet, + joined: false, + }) + } +} + +/// Spawn a new, returning a join handle for it. +/// +/// The child thread may outlive the parent (unless the parent thread +/// is the main thread; the whole process is terminated when the main +/// thread finishes.) The join handle can be used to block on +/// termination of the child thread, including recovering its panics. +/// +/// # Panics +/// +/// Panicks if the OS fails to create a thread; use `Builder::spawn` +/// to recover from such errors. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn spawn(f: F) -> JoinHandle where F: FnOnce(), F: Send + 'static { + Builder::new().spawn(f).unwrap() +} + +/// Spawn a new *scoped* thread, returning a `JoinGuard` for it. +/// +/// The join guard can be used to explicitly join the child thread (via +/// `join`), returning `Result`, or it will implicitly join the child +/// upon being dropped. Because the child thread may refer to data on the +/// current thread's stack (hence the "scoped" name), it cannot be detached; +/// it *must* be joined before the relevant stack frame is popped. See the +/// module documentation for additional details. +/// +/// # Panics +/// +/// Panicks if the OS fails to create a thread; use `Builder::scoped` +/// to recover from such errors. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where + T: Send + 'a, F: FnOnce() -> T, F: Send + 'a +{ + Builder::new().scoped(f).unwrap() +} + +/// Gets a handle to the thread that invokes it. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn current() -> Thread { + thread_info::current_thread() +} + +/// Cooperatively give up a timeslice to the OS scheduler. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn yield_now() { + unsafe { imp::yield_now() } +} + +/// Determines whether the current thread is unwinding because of panic. +#[inline] +#[stable(feature = "rust1", since = "1.0.0")] +pub fn panicking() -> bool { + unwind::panicking() +} + +/// Block unless or until the current thread's token is made available (may wake spuriously). +/// +/// See the module doc for more detail. +// +// The implementation currently uses the trivial strategy of a Mutex+Condvar +// with wakeup flag, which does not actually allow spurious wakeups. In the +// future, this will be implemented in a more efficient way, perhaps along the lines of +// http://cr.openjdk.java.net/~stefank/6989984.1/raw_files/new/src/os/linux/vm/os_linux.cpp +// or futuxes, and in either case may allow spurious wakeups. +#[stable(feature = "rust1", since = "1.0.0")] +pub fn park() { + let thread = Thread::current(); + let mut guard = thread.inner.lock.lock().unwrap(); + while !*guard { + guard = thread.inner.cvar.wait(guard).unwrap(); } + *guard = false; } +/// Block unless or until the current thread's token is made available or +/// the specified duration has been reached (may wake spuriously). +/// +/// The semantics of this function are equivalent to `park()` except that the +/// thread will be blocked for roughly no longer than dur. This method +/// should not be used for precise timing due to anomalies such as +/// preemption or platform differences that may not cause the maximum +/// amount of time waited to be precisely dur +/// +/// See the module doc for more detail. +#[unstable(feature = "std_misc", reason = "recently introduced, depends on Duration")] +pub fn park_timeout(dur: Duration) { + let thread = Thread::current(); + let mut guard = thread.inner.lock.lock().unwrap(); + if !*guard { + let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap(); + guard = g; + } + *guard = false; +} + +/// The internal representation of a `Thread` handle struct Inner { name: Option, lock: Mutex, // true when there is a buffered unpark @@ -354,62 +468,48 @@ impl Thread { } } - /// Spawn a new detached thread, returning a handle to it. - /// - /// The child thread may outlive the parent (unless the parent thread is the - /// main thread; the whole process is terminated when the main thread - /// finishes.) The thread handle can be used for low-level - /// synchronization. See the module documentation for additional details. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "may change with specifics of new Send semantics")] pub fn spawn(f: F) -> Thread where F: FnOnce(), F: Send + 'static { - Builder::new().spawn(f) + Builder::new().spawn(f).unwrap().thread().clone() } - /// Spawn a new *scoped* thread, returning a `JoinGuard` for it. - /// - /// The join guard can be used to explicitly join the child thread (via - /// `join`), returning `Result`, or it will implicitly join the child - /// upon being dropped. Because the child thread may refer to data on the - /// current thread's stack (hence the "scoped" name), it cannot be detached; - /// it *must* be joined before the relevant stack frame is popped. See the - /// module documentation for additional details. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "may change with specifics of new Send semantics")] pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { - Builder::new().scoped(f) + Builder::new().scoped(f).unwrap() } - /// Gets a handle to the thread that invokes it. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[stable(feature = "rust1", since = "1.0.0")] pub fn current() -> Thread { thread_info::current_thread() } - /// Cooperatively give up a timeslice to the OS scheduler. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "name may change")] pub fn yield_now() { unsafe { imp::yield_now() } } - /// Determines whether the current thread is unwinding because of panic. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn panicking() -> bool { unwind::panicking() } - /// Block unless or until the current thread's token is made available (may wake spuriously). - /// - /// See the module doc for more detail. - // - // The implementation currently uses the trivial strategy of a Mutex+Condvar - // with wakeup flag, which does not actually allow spurious wakeups. In the - // future, this will be implemented in a more efficient way, perhaps along the lines of - // http://cr.openjdk.java.net/~stefank/6989984.1/raw_files/new/src/os/linux/vm/os_linux.cpp - // or futuxes, and in either case may allow spurious wakeups. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park() { let thread = Thread::current(); @@ -420,16 +520,8 @@ impl Thread { *guard = false; } - /// Block unless or until the current thread's token is made available or - /// the specified duration has been reached (may wake spuriously). - /// - /// The semantics of this function are equivalent to `park()` except that the - /// thread will be blocked for roughly no longer than dur. This method - /// should not be used for precise timing due to anomalies such as - /// preemption or platform differences that may not cause the maximum - /// amount of time waited to be precisely dur - /// - /// See the module doc for more detail. + /// Deprecated: use module-level free fucntion. + #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park_timeout(dur: Duration) { let thread = Thread::current(); @@ -444,7 +536,7 @@ impl Thread { /// Atomically makes the handle's token available if it is not already. /// /// See the module doc for more detail. - #[unstable(feature = "std_misc", reason = "recently introduced")] + #[stable(feature = "rust1", since = "1.0.0")] pub fn unpark(&self) { let mut guard = self.inner.lock.lock().unwrap(); if !*guard { @@ -460,6 +552,13 @@ impl Thread { } } +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for Thread { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.name(), f) + } +} + // a hack to get around privacy restrictions impl thread_info::NewThread for Thread { fn new(name: Option) -> Thread { Thread::new(name) } @@ -476,19 +575,76 @@ struct Packet(Arc>>>); unsafe impl Send for Packet {} unsafe impl Sync for Packet {} -/// An RAII-style guard that will block until thread termination when dropped. -/// -/// The type `T` is the return type for the thread's main function. -#[must_use] -#[unstable(feature = "std_misc", - reason = "may change with specifics of new Send semantics")] -pub struct JoinGuard<'a, T: 'a> { +/// Inner representation for JoinHandle and JoinGuard +struct JoinInner { native: imp::rust_thread, thread: Thread, - joined: bool, packet: Packet, + joined: bool, } +impl JoinInner { + fn join(&mut self) -> Result { + assert!(!self.joined); + unsafe { imp::join(self.native) }; + self.joined = true; + unsafe { + (*self.packet.0.get()).take().unwrap() + } + } +} + +/// An owned permission to join on a thread (block on its termination). +/// +/// Unlike a `JoinGuard`, a `JoinHandle` *detaches* the child thread +/// when it is dropped, rather than automatically joining on drop. +/// +/// Due to platform restrictions, it is not possible to `Clone` this +/// handle: the ability to join a child thread is a uniquely-owned +/// permission. +#[stable(feature = "rust1", since = "1.0.0")] +pub struct JoinHandle(JoinInner<()>); + +impl JoinHandle { + /// Extract a handle to the underlying thread + #[stable(feature = "rust1", since = "1.0.0")] + pub fn thread(&self) -> &Thread { + &self.0.thread + } + + /// Wait for the associated thread to finish. + /// + /// If the child thread panics, `Err` is returned with the parameter given + /// to `panic`. + #[stable(feature = "rust1", since = "1.0.0")] + pub fn join(mut self) -> Result<()> { + self.0.join() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl Drop for JoinHandle { + fn drop(&mut self) { + if !self.0.joined { + unsafe { imp::detach(self.0.native) } + } + } +} + +/// An RAII-style guard that will block until thread termination when dropped. +/// +/// The type `T` is the return type for the thread's main function. +/// +/// Joining on drop is necessary to ensure memory safety when stack +/// data is shared between a parent and child thread. +/// +/// Due to platform restrictions, it is not possible to `Clone` this +/// handle: the ability to join a child thread is a uniquely-owned +/// permission. +#[must_use] +#[stable(feature = "rust1", since = "1.0.0")] +pub struct JoinGuard<'a, T: 'a>(JoinInner); + #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<'a, T: Send + 'a> Sync for JoinGuard<'a, T> {} @@ -496,32 +652,32 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> { /// Extract a handle to the thread this guard will join on. #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { - &self.thread + &self.0.thread } /// Wait for the associated thread to finish, returning the result of the thread's /// calculation. /// - /// If the child thread panics, `Err` is returned with the parameter given - /// to `panic`. + /// # Panics + /// + /// Panics on the child thread are propagated by panicking the parent. #[stable(feature = "rust1", since = "1.0.0")] - pub fn join(mut self) -> Result { - assert!(!self.joined); - unsafe { imp::join(self.native) }; - self.joined = true; - unsafe { - (*self.packet.0.get()).take().unwrap() + pub fn join(mut self) -> T { + match self.0.join() { + Ok(res) => res, + Err(_) => panic!("child thread {:?} panicked", self.thread()), } } } +#[stable(feature = "rust1", since = "1.0.0")] impl JoinGuard<'static, T> { /// Detaches the child thread, allowing it to outlive its parent. - #[unstable(feature = "std_misc", - reason = "unsure whether this API imposes limitations elsewhere")] + #[deprecated(since = "1.0.0", reason = "use spawn instead")] + #[unstable(feature = "std_misc")] pub fn detach(mut self) { - unsafe { imp::detach(self.native) }; - self.joined = true; // avoid joining in the destructor + unsafe { imp::detach(self.0.native) }; + self.0.joined = true; // avoid joining in the destructor } } @@ -529,8 +685,8 @@ impl JoinGuard<'static, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> { fn drop(&mut self) { - if !self.joined { - unsafe { imp::join(self.native) }; + if !self.0.joined { + unsafe { imp::join(self.0.native) }; } } } -- cgit 1.4.1-3-g733a5 From d0de2b46e9bcca93971ef64d6ecdef872633f246 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Tue, 17 Feb 2015 15:10:25 -0800 Subject: Fallout from stabilization --- src/compiletest/runtest.rs | 4 +- src/liballoc/arc.rs | 16 +-- src/libcollections/dlist.rs | 4 +- src/libcore/atomic.rs | 4 +- src/libcore/cell.rs | 8 +- src/libcoretest/finally.rs | 6 +- src/librustdoc/lib.rs | 2 +- src/librustdoc/test.rs | 4 +- src/libstd/macros.rs | 6 +- src/libstd/net/tcp.rs | 76 +++++----- src/libstd/net/udp.rs | 16 +-- src/libstd/old_io/comm_adapters.rs | 8 +- src/libstd/old_io/mod.rs | 4 +- src/libstd/old_io/net/pipe.rs | 54 ++++---- src/libstd/old_io/net/tcp.rs | 128 ++++++++--------- src/libstd/old_io/net/udp.rs | 20 +-- src/libstd/old_io/pipe.rs | 4 +- src/libstd/old_io/process.rs | 10 +- src/libstd/old_io/stdio.rs | 6 +- src/libstd/old_io/timer.rs | 10 +- src/libstd/old_path/posix.rs | 8 +- src/libstd/old_path/windows.rs | 8 +- src/libstd/panicking.rs | 4 +- src/libstd/process.rs | 6 +- src/libstd/rand/os.rs | 12 +- src/libstd/rt/util.rs | 4 +- src/libstd/sync/barrier.rs | 8 +- src/libstd/sync/condvar.rs | 16 +-- src/libstd/sync/future.rs | 8 +- src/libstd/sync/mpsc/blocking.rs | 6 +- src/libstd/sync/mpsc/mod.rs | 154 ++++++++++----------- src/libstd/sync/mpsc/mpsc_queue.rs | 4 +- src/libstd/sync/mpsc/select.rs | 42 +++--- src/libstd/sync/mpsc/shared.rs | 8 +- src/libstd/sync/mpsc/spsc_queue.rs | 4 +- src/libstd/sync/mpsc/stream.rs | 4 +- src/libstd/sync/mutex.rs | 24 ++-- src/libstd/sync/once.rs | 6 +- src/libstd/sync/poison.rs | 6 +- src/libstd/sync/rwlock.rs | 20 +-- src/libstd/sync/semaphore.rs | 12 +- src/libstd/sync/task_pool.rs | 4 +- src/libstd/sys/common/helper_thread.rs | 4 +- src/libstd/sys/common/thread_info.rs | 4 +- src/libstd/sys/common/thread_local.rs | 2 +- src/libstd/thread.rs | 102 ++++++++------ src/libstd/thread_local/mod.rs | 18 +-- src/libstd/thread_local/scoped.rs | 12 +- src/libtest/lib.rs | 2 +- src/test/auxiliary/cci_capture_clause.rs | 4 +- src/test/bench/msgsend-pipes-shared.rs | 6 +- src/test/bench/msgsend-pipes.rs | 8 +- src/test/bench/rt-messaging-ping-pong.rs | 6 +- src/test/bench/rt-parfib.rs | 4 +- src/test/bench/shootout-binarytrees.rs | 2 +- src/test/bench/shootout-chameneos-redux.rs | 4 +- src/test/bench/shootout-fannkuch-redux.rs | 4 +- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +- src/test/bench/shootout-k-nucleotide.rs | 6 +- src/test/bench/shootout-mandelbrot.rs | 6 +- src/test/bench/shootout-meteor.rs | 4 +- src/test/bench/shootout-pfib.rs | 10 +- src/test/bench/shootout-reverse-complement.rs | 4 +- src/test/bench/shootout-spectralnorm.rs | 4 +- src/test/bench/shootout-threadring.rs | 6 +- src/test/bench/task-perf-alloc-unwind.rs | 4 +- src/test/bench/task-perf-jargon-metal-smoke.rs | 6 +- src/test/bench/task-perf-spawnalot.rs | 6 +- .../compile-fail/borrowck-loan-blocks-move-cc.rs | 6 +- .../compile-fail/borrowck-multiple-captures.rs | 10 +- src/test/compile-fail/issue-12041.rs | 4 +- src/test/compile-fail/issue-8460-const.rs | 42 +++--- src/test/compile-fail/missing-stability.rs | 2 +- .../moves-based-on-type-capture-clause-bad.rs | 4 +- src/test/compile-fail/no-capture-arc.rs | 4 +- src/test/compile-fail/no-reuse-move-arc.rs | 4 +- src/test/compile-fail/no-send-res-ports.rs | 4 +- src/test/run-fail/panic-task-name-none.rs | 4 +- src/test/run-fail/rt-set-exit-status-panic2.rs | 4 +- src/test/run-fail/task-spawn-barefn.rs | 4 +- src/test/run-pass/unique-send-2.rs | 4 +- src/test/run-pass/unit-like-struct-drop-run.rs | 4 +- src/test/run-pass/unwind-resource.rs | 4 +- src/test/run-pass/unwind-unique.rs | 4 +- src/test/run-pass/vector-sort-panic-safe.rs | 4 +- src/test/run-pass/weak-lang-item.rs | 4 +- src/test/run-pass/yield.rs | 10 +- src/test/run-pass/yield1.rs | 6 +- src/test/run-pass/yield2.rs | 4 +- 89 files changed, 578 insertions(+), 558 deletions(-) (limited to 'src/libstd') diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 5a372fd7cdc..a5aa480ab50 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -35,7 +35,7 @@ use std::env; use std::iter::repeat; use std::str; use std::string::String; -use std::thread::Thread; +use std::thread; use std::time::Duration; use test::MetricMap; @@ -447,7 +447,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) { loop { //waiting 1 second for gdbserver start timer::sleep(Duration::milliseconds(1000)); - let result = Thread::scoped(move || { + let result = thread::spawn(move || { tcp::TcpStream::connect("127.0.0.1:5039").unwrap(); }).join(); if result.is_err() { diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 0617c604121..3830d7fe295 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -35,14 +35,14 @@ //! //! ``` //! use std::sync::Arc; -//! use std::thread::Thread; +//! use std::thread; //! //! let five = Arc::new(5); //! //! for _ in 0..10 { //! let five = five.clone(); //! -//! Thread::spawn(move || { +//! thread::spawn(move || { //! println!("{:?}", five); //! }); //! } @@ -52,14 +52,14 @@ //! //! ``` //! use std::sync::{Arc, Mutex}; -//! use std::thread::Thread; +//! use std::thread; //! //! let five = Arc::new(Mutex::new(5)); //! //! for _ in 0..10 { //! let five = five.clone(); //! -//! Thread::spawn(move || { +//! thread::spawn(move || { //! let mut number = five.lock().unwrap(); //! //! *number += 1; @@ -95,7 +95,7 @@ use heap::deallocate; /// /// ```rust /// use std::sync::Arc; -/// use std::thread::Thread; +/// use std::thread; /// /// fn main() { /// let numbers: Vec<_> = (0..100u32).map(|i| i as f32).collect(); @@ -104,7 +104,7 @@ use heap::deallocate; /// for _ in 0..10 { /// let child_numbers = shared_numbers.clone(); /// -/// Thread::spawn(move || { +/// thread::spawn(move || { /// let local_numbers = child_numbers.as_slice(); /// /// // Work with the local numbers @@ -621,7 +621,7 @@ mod tests { use std::option::Option::{Some, None}; use std::sync::atomic; use std::sync::atomic::Ordering::{Acquire, SeqCst}; - use std::thread::Thread; + use std::thread; use std::vec::Vec; use super::{Arc, Weak, weak_count, strong_count}; use std::sync::Mutex; @@ -648,7 +648,7 @@ mod tests { let (tx, rx) = channel(); - let _t = Thread::spawn(move || { + let _t = thread::spawn(move || { let arc_v: Arc> = rx.recv().unwrap(); assert_eq!((*arc_v)[3], 4); }); diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 423646e5acd..7174b4d4665 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -935,7 +935,7 @@ mod tests { use prelude::*; use std::rand; use std::hash::{self, SipHasher}; - use std::thread::Thread; + use std::thread; use test::Bencher; use test; @@ -1284,7 +1284,7 @@ mod tests { #[test] fn test_send() { let n = list_from(&[1,2,3]); - Thread::scoped(move || { + thread::spawn(move || { check_links(&n); let a: &[_] = &[&1,&2,&3]; assert_eq!(a, n.iter().collect::>()); diff --git a/src/libcore/atomic.rs b/src/libcore/atomic.rs index 32e8cffcae4..05d864accc1 100644 --- a/src/libcore/atomic.rs +++ b/src/libcore/atomic.rs @@ -42,13 +42,13 @@ //! ``` //! use std::sync::Arc; //! use std::sync::atomic::{AtomicUsize, Ordering}; -//! use std::thread::Thread; +//! use std::thread; //! //! fn main() { //! let spinlock = Arc::new(AtomicUsize::new(1)); //! //! let spinlock_clone = spinlock.clone(); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! spinlock_clone.store(0, Ordering::SeqCst); //! }); //! diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index cf293ded13f..a1c3d58f235 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -375,9 +375,9 @@ impl RefCell { /// /// ``` /// use std::cell::RefCell; - /// use std::thread::Thread; + /// use std::thread; /// - /// let result = Thread::scoped(move || { + /// let result = thread::spawn(move || { /// let c = RefCell::new(5); /// let m = c.borrow_mut(); /// @@ -436,9 +436,9 @@ impl RefCell { /// /// ``` /// use std::cell::RefCell; - /// use std::thread::Thread; + /// use std::thread; /// - /// let result = Thread::scoped(move || { + /// let result = thread::spawn(move || { /// let c = RefCell::new(5); /// let m = c.borrow_mut(); /// diff --git a/src/libcoretest/finally.rs b/src/libcoretest/finally.rs index 42c2dfbda08..55fcb849851 100644 --- a/src/libcoretest/finally.rs +++ b/src/libcoretest/finally.rs @@ -11,7 +11,7 @@ #![allow(deprecated)] use core::finally::{try_finally, Finally}; -use std::thread::Thread; +use std::thread; #[test] fn test_success() { @@ -22,7 +22,7 @@ fn test_success() { *i = 10; }, |i| { - assert!(!Thread::panicking()); + assert!(!thread::panicking()); assert_eq!(*i, 10); *i = 20; }); @@ -40,7 +40,7 @@ fn test_fail() { panic!(); }, |i| { - assert!(Thread::panicking()); + assert!(thread::panicking()); assert_eq!(*i, 10); }) } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b09c3f730fc..91614409bfa 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -365,7 +365,7 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche let cr = Path::new(cratefile); info!("starting to run rustc"); - let (mut krate, analysis) = std::thread::Thread::scoped(move || { + let (mut krate, analysis) = std::thread::spawn(move || { use rustc::session::config::Input; let cr = cr; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 09df9fc8cbb..bf14b86ebd1 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -15,7 +15,7 @@ use std::old_io::{Command, TempDir}; use std::old_io; use std::env; use std::str; -use std::thread::Thread; +use std::thread; use std::thunk::Thunk; use std::collections::{HashSet, HashMap}; @@ -142,7 +142,7 @@ fn runtest(test: &str, cratename: &str, libs: SearchPaths, let w1 = old_io::ChanWriter::new(tx); let w2 = w1.clone(); let old = old_io::stdio::set_stderr(box w1); - Thread::spawn(move || { + thread::spawn(move || { let mut p = old_io::ChanReader::new(rx); let mut err = match old { Some(old) => { diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 6a2aafcf8f3..1b9b13d4bd4 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -126,7 +126,7 @@ macro_rules! try { /// # Examples /// /// ``` -/// use std::thread::Thread; +/// use std::thread; /// use std::sync::mpsc; /// /// // two placeholder functions for now @@ -136,8 +136,8 @@ macro_rules! try { /// let (tx1, rx1) = mpsc::channel(); /// let (tx2, rx2) = mpsc::channel(); /// -/// Thread::spawn(move|| { long_running_task(); tx1.send(()).unwrap(); }); -/// Thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); }); +/// thread::spawn(move|| { long_running_task(); tx1.send(()).unwrap(); }); +/// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); }); /// /// select! ( /// _ = rx1.recv() => println!("the long running task finished first"), diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 50eafdfc5c2..805239f6fa4 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -43,7 +43,7 @@ pub struct TcpStream(net_imp::TcpStream); /// /// ```no_run /// use std::net::{TcpListener, TcpStream}; -/// use std::thread::Thread; +/// use std::thread; /// /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); /// @@ -55,7 +55,7 @@ pub struct TcpStream(net_imp::TcpStream); /// for stream in listener.incoming() { /// match stream { /// Ok(stream) => { -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// // connection succeeded /// handle_client(stream) /// }); @@ -217,7 +217,7 @@ mod tests { use net::*; use net::test::{next_test_ip4, next_test_ip6}; use sync::mpsc::channel; - use thread::Thread; + use thread; fn each_ip(f: &mut FnMut(SocketAddr)) { f(next_test_ip4()); @@ -256,7 +256,7 @@ mod tests { let socket_addr = next_test_ip4(); let listener = t!(TcpListener::bind(&socket_addr)); - let _t = Thread::scoped(move || { + let _t = thread::spawn(move || { let mut stream = t!(TcpStream::connect(&("localhost", socket_addr.port()))); t!(stream.write(&[144])); @@ -273,7 +273,7 @@ mod tests { let addr = next_test_ip4(); let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&("127.0.0.1", addr.port()))); t!(stream.write(&[44])); }); @@ -289,7 +289,7 @@ mod tests { let addr = next_test_ip6(); let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&("::1", addr.port()))); t!(stream.write(&[66])); }); @@ -306,7 +306,7 @@ mod tests { let acceptor = t!(TcpListener::bind(&addr)); let (tx, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&addr)); t!(stream.write(&[99])); tx.send(t!(stream.socket_addr())).unwrap(); @@ -325,7 +325,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _stream = t!(TcpStream::connect(&addr)); // Close }); @@ -345,7 +345,7 @@ mod tests { let acceptor = t!(TcpListener::bind(&addr)); let (tx, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { drop(t!(TcpStream::connect(&addr))); tx.send(()).unwrap(); }); @@ -371,7 +371,7 @@ mod tests { let max = 10; let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { for _ in 0..max { let mut stream = t!(TcpStream::connect(&addr)); t!(stream.write(&[99])); @@ -393,11 +393,11 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let acceptor = acceptor; for (i, stream) in acceptor.incoming().enumerate().take(MAX) { // Start another task to handle the connection - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(stream); let mut buf = [0]; t!(stream.read(&mut buf)); @@ -412,7 +412,7 @@ mod tests { fn connect(i: usize, addr: SocketAddr) { if i == MAX { return } - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&addr)); // Connect again before writing connect(i + 1, addr); @@ -428,10 +428,10 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { for stream in acceptor.incoming().take(MAX) { // Start another task to handle the connection - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut stream = t!(stream); let mut buf = [0]; t!(stream.read(&mut buf)); @@ -446,7 +446,7 @@ mod tests { fn connect(i: usize, addr: SocketAddr) { if i == MAX { return } - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { let mut stream = t!(TcpStream::connect(&addr)); connect(i + 1, addr); t!(stream.write(&[99])); @@ -467,7 +467,7 @@ mod tests { let listener = t!(TcpListener::bind(&addr)); let so_name = t!(listener.socket_addr()); assert_eq!(addr, so_name); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { t!(listener.accept()); }); @@ -481,7 +481,7 @@ mod tests { each_ip(&mut |addr| { let (tx, rx) = channel(); let srv = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut cl = t!(srv.accept()).0; cl.write(&[10]).unwrap(); let mut b = [0]; @@ -517,7 +517,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { t!(TcpStream::connect(&addr)); }); @@ -532,7 +532,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s = t!(TcpStream::connect(&addr)); let mut buf = [0, 0]; assert_eq!(s.read(&mut buf), Ok(1)); @@ -545,7 +545,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; rx1.recv().unwrap(); t!(s2.write(&[1])); @@ -565,7 +565,7 @@ mod tests { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s = t!(TcpStream::connect(&addr)); t!(s.write(&[1])); rx.recv().unwrap(); @@ -577,7 +577,7 @@ mod tests { let s2 = t!(s1.try_clone()); let (done, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; let mut buf = [0, 0]; t!(s2.read(&mut buf)); @@ -597,7 +597,7 @@ mod tests { each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s = t!(TcpStream::connect(&addr)); let mut buf = [0, 1]; t!(s.read(&mut buf)); @@ -608,7 +608,7 @@ mod tests { let s2 = t!(s1.try_clone()); let (done, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; t!(s2.write(&[1])); done.send(()).unwrap(); @@ -623,7 +623,7 @@ mod tests { fn shutdown_smoke() { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut c = t!(a.accept()).0; let mut b = [0]; assert_eq!(c.read(&mut b), Ok(0)); @@ -644,7 +644,7 @@ mod tests { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); let (tx, rx) = channel::<()>(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _s = t!(a.accept()); let _ = rx.recv(); }); @@ -682,7 +682,7 @@ mod tests { each_ip(&mut |addr| { let a = t!(TcpListener::bind(&addr)); let (tx1, rx) = channel::<()>(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _s = t!(a.accept()); let _ = rx.recv(); }); @@ -690,7 +690,7 @@ mod tests { let s = t!(TcpStream::connect(&addr)); let s2 = t!(s.try_clone()); let (tx, rx) = channel(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert_eq!(t!(s2.read(&mut [0])), 0); tx.send(()).unwrap(); @@ -713,7 +713,7 @@ mod tests { let (tx, rx) = channel(); let (txdone, rxdone) = channel(); let txdone2 = txdone.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut tcp = t!(TcpStream::connect(&addr)); rx.recv().unwrap(); t!(tcp.write(&[0])); @@ -724,7 +724,7 @@ mod tests { let tcp = t!(accept.accept()).0; let tcp2 = t!(tcp.try_clone()); let txdone3 = txdone.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let mut tcp2 = tcp2; t!(tcp2.read(&mut [0])); txdone3.send(()).unwrap(); @@ -732,7 +732,7 @@ mod tests { // Try to ensure that the reading clone is indeed reading for _ in 0..50 { - Thread::yield_now(); + thread::yield_now(); } // clone the handle again while it's reading, then let it finish the @@ -750,10 +750,10 @@ mod tests { let a = t!(TcpListener::bind(&addr)); let a2 = t!(a.try_clone()); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); @@ -771,17 +771,17 @@ mod tests { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { tx.send(t!(a.accept())).unwrap(); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { tx2.send(t!(a2.accept())).unwrap(); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); - let _t = Thread::scoped(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(&addr); }); diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index d162a29790e..92f00599826 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -131,7 +131,7 @@ mod tests { use net::*; use net::test::{next_test_ip4, next_test_ip6}; use sync::mpsc::channel; - use thread::Thread; + use thread; fn each_ip(f: &mut FnMut(SocketAddr, SocketAddr)) { f(next_test_ip4(), next_test_ip4()); @@ -164,7 +164,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let client = t!(UdpSocket::bind(&client_ip)); rx1.recv().unwrap(); t!(client.send_to(&[99], &server_ip)); @@ -196,7 +196,7 @@ mod tests { let sock1 = t!(UdpSocket::bind(&addr1)); let sock2 = t!(UdpSocket::bind(&addr2)); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut buf = [0, 0]; assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1))); assert_eq!(buf[0], 1); @@ -207,7 +207,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx1.recv().unwrap(); t!(sock3.send_to(&[1], &addr2)); tx2.send(()).unwrap(); @@ -227,7 +227,7 @@ mod tests { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { t!(sock2.send_to(&[1], &addr1)); rx.recv().unwrap(); t!(sock2.send_to(&[2], &addr1)); @@ -237,7 +237,7 @@ mod tests { let sock3 = t!(sock1.try_clone()); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut buf = [0, 0]; t!(sock3.recv_from(&mut buf)); tx2.send(()).unwrap(); @@ -260,7 +260,7 @@ mod tests { let (tx, rx) = channel(); let (serv_tx, serv_rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut buf = [0, 1]; rx.recv().unwrap(); t!(sock2.recv_from(&mut buf)); @@ -271,7 +271,7 @@ mod tests { let (done, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match sock3.send_to(&[1], &addr2) { Ok(..) => { let _ = tx2.send(()); } Err(..) => {} diff --git a/src/libstd/old_io/comm_adapters.rs b/src/libstd/old_io/comm_adapters.rs index d8f9b1bb3fe..a75686369ad 100644 --- a/src/libstd/old_io/comm_adapters.rs +++ b/src/libstd/old_io/comm_adapters.rs @@ -161,12 +161,12 @@ mod test { use sync::mpsc::channel; use super::*; use old_io; - use thread::Thread; + use thread; #[test] fn test_rx_reader() { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(vec![1u8, 2u8]).unwrap(); tx.send(vec![]).unwrap(); tx.send(vec![3u8, 4u8]).unwrap(); @@ -208,7 +208,7 @@ mod test { #[test] fn test_rx_buffer() { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(b"he".to_vec()).unwrap(); tx.send(b"llo wo".to_vec()).unwrap(); tx.send(b"".to_vec()).unwrap(); @@ -234,7 +234,7 @@ mod test { writer.write_be_u32(42).unwrap(); let wanted = vec![0u8, 0u8, 0u8, 42u8]; - let got = match Thread::scoped(move|| { rx.recv().unwrap() }).join() { + let got = match thread::spawn(move|| { rx.recv().unwrap() }).join() { Ok(got) => got, Err(_) => panic!(), }; diff --git a/src/libstd/old_io/mod.rs b/src/libstd/old_io/mod.rs index 94f4af8e558..deed210a174 100644 --- a/src/libstd/old_io/mod.rs +++ b/src/libstd/old_io/mod.rs @@ -124,7 +124,7 @@ //! # #![allow(dead_code)] //! use std::old_io::{TcpListener, TcpStream}; //! use std::old_io::{Acceptor, Listener}; -//! use std::thread::Thread; +//! use std::thread; //! //! let listener = TcpListener::bind("127.0.0.1:80"); //! @@ -140,7 +140,7 @@ //! match stream { //! Err(e) => { /* connection failed */ } //! Ok(stream) => { -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! // connection succeeded //! handle_client(stream) //! }); diff --git a/src/libstd/old_io/net/pipe.rs b/src/libstd/old_io/net/pipe.rs index 8c4a10a55d4..8e0126d5ec8 100644 --- a/src/libstd/old_io/net/pipe.rs +++ b/src/libstd/old_io/net/pipe.rs @@ -282,7 +282,7 @@ mod tests { use old_io::test::*; use super::*; use sync::mpsc::channel; - use thread::Thread; + use thread; use time::Duration; pub fn smalltest(server: F, client: G) @@ -294,7 +294,7 @@ mod tests { let mut acceptor = UnixListener::bind(&path1).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match UnixStream::connect(&path2) { Ok(c) => client(c), Err(e) => panic!("failed connect: {}", e), @@ -389,7 +389,7 @@ mod tests { Err(e) => panic!("failed listen: {}", e), }; - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0u..times { let mut stream = UnixStream::connect(&path2); match stream.write(&[100]) { @@ -423,7 +423,7 @@ mod tests { let addr = next_test_unix(); let mut acceptor = UnixListener::bind(&addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = UnixStream::connect(&addr); let mut buf = [0, 0]; debug!("client reading"); @@ -439,7 +439,7 @@ mod tests { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; rx1.recv().unwrap(); debug!("writer writing"); @@ -462,7 +462,7 @@ mod tests { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = UnixStream::connect(&addr); s.write(&[1]).unwrap(); rx.recv().unwrap(); @@ -474,7 +474,7 @@ mod tests { let s2 = s1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; let mut buf = [0, 0]; s2.read(&mut buf).unwrap(); @@ -493,7 +493,7 @@ mod tests { let addr = next_test_unix(); let mut acceptor = UnixListener::bind(&addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = UnixStream::connect(&addr); let buf = &mut [0, 1]; s.read(buf).unwrap(); @@ -504,7 +504,7 @@ mod tests { let s2 = s1.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; s2.write(&[1]).unwrap(); tx.send(()).unwrap(); @@ -551,7 +551,7 @@ mod tests { // continue to receive any pending connections. let (tx, rx) = channel(); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(UnixStream::connect(&addr2).unwrap()).unwrap(); }); let l = rx.recv().unwrap(); @@ -561,7 +561,7 @@ mod tests { Err(ref e) if e.kind == TimedOut => {} Err(e) => panic!("error: {}", e), } - ::thread::Thread::yield_now(); + ::thread::yield_now(); if i == 1000 { panic!("should have a pending connection") } } drop(l); @@ -569,7 +569,7 @@ mod tests { // Unset the timeout and make sure that this always blocks. a.set_timeout(None); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(UnixStream::connect(&addr2).unwrap()); }); a.accept().unwrap(); @@ -607,7 +607,7 @@ mod tests { let addr = next_test_unix(); let a = UnixListener::bind(&addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv(); @@ -644,7 +644,7 @@ mod tests { let addr = next_test_unix(); let a = UnixListener::bind(&addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv(); @@ -653,7 +653,7 @@ mod tests { let mut s = UnixStream::connect(&addr).unwrap(); let s2 = s.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert!(s2.read(&mut [0]).is_err()); tx.send(()).unwrap(); @@ -670,7 +670,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -708,7 +708,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); let mut amt = 0; @@ -737,7 +737,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -764,7 +764,7 @@ mod tests { let addr = next_test_unix(); let mut a = UnixListener::bind(&addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = UnixStream::connect(&addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -774,7 +774,7 @@ mod tests { let mut s = a.accept().unwrap(); let s2 = s.clone(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert!(s2.read(&mut [0]).is_ok()); tx2.send(()).unwrap(); @@ -796,10 +796,10 @@ mod tests { let mut a2 = a.clone(); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr2); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr); }); @@ -819,20 +819,20 @@ mod tests { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap() }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()).unwrap() }); let addr2 = addr.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr2); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = UnixStream::connect(&addr); }); @@ -858,7 +858,7 @@ mod tests { let mut a2 = a.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap(); }); diff --git a/src/libstd/old_io/net/tcp.rs b/src/libstd/old_io/net/tcp.rs index ebf7f6cc0f2..5ab0880080b 100644 --- a/src/libstd/old_io/net/tcp.rs +++ b/src/libstd/old_io/net/tcp.rs @@ -137,12 +137,12 @@ impl TcpStream { /// use std::old_io::timer; /// use std::old_io::TcpStream; /// use std::time::Duration; - /// use std::thread::Thread; + /// use std::thread; /// /// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap(); /// let stream2 = stream.clone(); /// - /// let _t = Thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// // close this stream after one second /// timer::sleep(Duration::seconds(1)); /// let mut stream = stream2; @@ -282,7 +282,7 @@ impl sys_common::AsInner for TcpStream { /// # fn foo() { /// use std::old_io::{TcpListener, TcpStream}; /// use std::old_io::{Acceptor, Listener}; -/// use std::thread::Thread; +/// use std::thread; /// /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); /// @@ -298,7 +298,7 @@ impl sys_common::AsInner for TcpStream { /// match stream { /// Err(e) => { /* connection failed */ } /// Ok(stream) => { -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// // connection succeeded /// handle_client(stream) /// }); @@ -421,12 +421,12 @@ impl TcpAcceptor { /// /// ``` /// use std::old_io::{TcpListener, Listener, Acceptor, EndOfFile}; - /// use std::thread::Thread; + /// use std::thread; /// /// let mut a = TcpListener::bind("127.0.0.1:8482").listen().unwrap(); /// let a2 = a.clone(); /// - /// let _t = Thread::spawn(move|| { + /// let _t = thread::spawn(move|| { /// let mut a2 = a2; /// for socket in a2.incoming() { /// match socket { @@ -487,7 +487,7 @@ mod test { use prelude::v1::*; use sync::mpsc::channel; - use thread::Thread; + use thread; use old_io::net::tcp::*; use old_io::net::ip::*; use old_io::test::*; @@ -520,7 +520,7 @@ mod test { let listener = TcpListener::bind(socket_addr); let mut acceptor = listener.listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("localhost", socket_addr.port)); stream.write(&[144]).unwrap(); }); @@ -536,7 +536,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("localhost", addr.port)); stream.write(&[64]).unwrap(); }); @@ -552,7 +552,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("127.0.0.1", addr.port)); stream.write(&[44]).unwrap(); }); @@ -568,7 +568,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(("::1", addr.port)); stream.write(&[66]).unwrap(); }); @@ -584,7 +584,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); }); @@ -600,7 +600,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); }); @@ -616,7 +616,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -632,7 +632,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -648,7 +648,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -672,7 +672,7 @@ mod test { let addr = next_test_ip6(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _stream = TcpStream::connect(addr); // Close }); @@ -697,7 +697,7 @@ mod test { let mut acceptor = TcpListener::bind(addr).listen(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(TcpStream::connect(addr)); tx.send(()).unwrap(); }); @@ -722,7 +722,7 @@ mod test { let mut acceptor = TcpListener::bind(addr).listen(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(TcpStream::connect(addr)); tx.send(()).unwrap(); }); @@ -747,7 +747,7 @@ mod test { let max = 10u; let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..max { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); @@ -767,7 +767,7 @@ mod test { let max = 10u; let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0..max { let mut stream = TcpStream::connect(addr); stream.write(&[99]).unwrap(); @@ -787,11 +787,11 @@ mod test { static MAX: int = 10; let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -806,7 +806,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -823,11 +823,11 @@ mod test { static MAX: int = 10; let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for (i, stream) in acceptor.incoming().enumerate().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -842,7 +842,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -859,11 +859,11 @@ mod test { let addr = next_test_ip4(); let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for stream in acceptor.incoming().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -878,7 +878,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -895,11 +895,11 @@ mod test { let addr = next_test_ip6(); let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; for stream in acceptor.incoming().take(MAX as uint) { // Start another task to handle the connection - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut stream = stream; let mut buf = [0]; stream.read(&mut buf).unwrap(); @@ -914,7 +914,7 @@ mod test { fn connect(i: int, addr: SocketAddr) { if i == MAX { return } - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { debug!("connecting"); let mut stream = TcpStream::connect(addr); // Connect again before writing @@ -937,7 +937,7 @@ mod test { pub fn peer_name(addr: SocketAddr) { let acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acceptor = acceptor; acceptor.accept().unwrap(); }); @@ -972,7 +972,7 @@ mod test { fn partial_read() { let addr = next_test_ip4(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut srv = TcpListener::bind(addr).listen().unwrap(); tx.send(()).unwrap(); let mut cl = srv.accept().unwrap(); @@ -1009,7 +1009,7 @@ mod test { let addr = next_test_ip4(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); let _stream = TcpStream::connect(addr).unwrap(); // Close @@ -1034,7 +1034,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = TcpStream::connect(addr); let mut buf = [0, 0]; assert_eq!(s.read(&mut buf), Ok(1)); @@ -1047,7 +1047,7 @@ mod test { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; rx1.recv().unwrap(); s2.write(&[1]).unwrap(); @@ -1066,7 +1066,7 @@ mod test { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = TcpStream::connect(addr); s.write(&[1]).unwrap(); rx.recv().unwrap(); @@ -1078,7 +1078,7 @@ mod test { let s2 = s1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; let mut buf = [0, 0]; s2.read(&mut buf).unwrap(); @@ -1097,7 +1097,7 @@ mod test { let addr = next_test_ip4(); let mut acceptor = TcpListener::bind(addr).listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s = TcpStream::connect(addr); let mut buf = [0, 1]; s.read(&mut buf).unwrap(); @@ -1108,7 +1108,7 @@ mod test { let s2 = s1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; s2.write(&[1]).unwrap(); done.send(()).unwrap(); @@ -1122,7 +1122,7 @@ mod test { fn shutdown_smoke() { let addr = next_test_ip4(); let a = TcpListener::bind(addr).unwrap().listen(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; let mut c = a.accept().unwrap(); assert_eq!(c.read_to_end(), Ok(vec!())); @@ -1156,7 +1156,7 @@ mod test { // flakiness. if !cfg!(target_os = "freebsd") { let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(TcpStream::connect(addr).unwrap()).unwrap(); }); let _l = rx.recv().unwrap(); @@ -1166,14 +1166,14 @@ mod test { Err(ref e) if e.kind == TimedOut => {} Err(e) => panic!("error: {}", e), } - ::thread::Thread::yield_now(); + ::thread::yield_now(); if i == 1000 { panic!("should have a pending connection") } } } // Unset the timeout and make sure that this always blocks. a.set_timeout(None); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(TcpStream::connect(addr).unwrap()); }); a.accept().unwrap(); @@ -1184,7 +1184,7 @@ mod test { let addr = next_test_ip4(); let a = TcpListener::bind(addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv().unwrap(); @@ -1221,7 +1221,7 @@ mod test { let addr = next_test_ip4(); let a = TcpListener::bind(addr).listen().unwrap(); let (_tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut a = a; let _s = a.accept().unwrap(); let _ = rx.recv().unwrap(); @@ -1230,7 +1230,7 @@ mod test { let mut s = TcpStream::connect(addr).unwrap(); let s2 = s.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert!(s2.read(&mut [0]).is_err()); tx.send(()).unwrap(); @@ -1247,7 +1247,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -1280,7 +1280,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); let mut amt = 0; @@ -1309,7 +1309,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); assert!(s.write(&[0]).is_ok()); @@ -1337,7 +1337,7 @@ mod test { let addr = next_test_ip6(); let mut a = TcpListener::bind(addr).listen().unwrap(); let (tx, rx) = channel::<()>(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut s = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); assert_eq!(s.write(&[0]), Ok(())); @@ -1347,7 +1347,7 @@ mod test { let mut s = a.accept().unwrap(); let s2 = s.clone(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut s2 = s2; assert_eq!(s2.read(&mut [0]), Ok(1)); tx2.send(()).unwrap(); @@ -1370,7 +1370,7 @@ mod test { let (tx, rx) = channel(); let (txdone, rxdone) = channel(); let txdone2 = txdone.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut tcp = TcpStream::connect(addr).unwrap(); rx.recv().unwrap(); tcp.write_u8(0).unwrap(); @@ -1381,7 +1381,7 @@ mod test { let tcp = accept.accept().unwrap(); let tcp2 = tcp.clone(); let txdone3 = txdone.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut tcp2 = tcp2; tcp2.read_u8().unwrap(); txdone3.send(()).unwrap(); @@ -1389,7 +1389,7 @@ mod test { // Try to ensure that the reading clone is indeed reading for _ in 0..50 { - ::thread::Thread::yield_now(); + ::thread::yield_now(); } // clone the handle again while it's reading, then let it finish the @@ -1407,10 +1407,10 @@ mod test { let mut a = l.listen().unwrap(); let mut a2 = a.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); @@ -1428,19 +1428,19 @@ mod test { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a2; tx2.send(a.accept()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _ = TcpStream::connect(addr); }); @@ -1466,7 +1466,7 @@ mod test { let mut a2 = a.clone(); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a; tx.send(a.accept()).unwrap(); }); diff --git a/src/libstd/old_io/net/udp.rs b/src/libstd/old_io/net/udp.rs index 8dc19047de0..7171198e7a4 100644 --- a/src/libstd/old_io/net/udp.rs +++ b/src/libstd/old_io/net/udp.rs @@ -186,7 +186,7 @@ mod test { use old_io::test::*; use old_io::{IoError, TimedOut, PermissionDenied, ShortWrite}; use super::*; - use thread::Thread; + use thread; // FIXME #11530 this fails on android because tests are run as root #[cfg_attr(any(windows, target_os = "android"), ignore)] @@ -206,7 +206,7 @@ mod test { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match UdpSocket::bind(client_ip) { Ok(ref mut client) => { rx1.recv().unwrap(); @@ -241,7 +241,7 @@ mod test { let client_ip = next_test_ip6(); let (tx, rx) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { match UdpSocket::bind(client_ip) { Ok(ref mut client) => { rx.recv().unwrap(); @@ -298,7 +298,7 @@ mod test { let mut sock1 = UdpSocket::bind(addr1).unwrap(); let sock2 = UdpSocket::bind(addr2).unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock2 = sock2; let mut buf = [0, 0]; assert_eq!(sock2.recv_from(&mut buf), Ok((1, addr1))); @@ -310,7 +310,7 @@ mod test { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock3 = sock3; rx1.recv().unwrap(); sock3.send_to(&[1], addr2).unwrap(); @@ -331,7 +331,7 @@ mod test { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock2 = sock2; sock2.send_to(&[1], addr1).unwrap(); rx.recv().unwrap(); @@ -342,7 +342,7 @@ mod test { let sock3 = sock1.clone(); let (done, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock3 = sock3; let mut buf = [0, 0]; sock3.recv_from(&mut buf).unwrap(); @@ -366,7 +366,7 @@ mod test { let (tx, rx) = channel(); let (serv_tx, serv_rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock2 = sock2; let mut buf = [0, 1]; @@ -382,7 +382,7 @@ mod test { let (done, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut sock3 = sock3; match sock3.send_to(&[1], addr2) { Ok(..) => { let _ = tx2.send(()); } @@ -410,7 +410,7 @@ mod test { let (tx, rx) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut a = a2; assert_eq!(a.recv_from(&mut [0]), Ok((1, addr1))); assert_eq!(a.send_to(&[0], addr1), Ok(())); diff --git a/src/libstd/old_io/pipe.rs b/src/libstd/old_io/pipe.rs index 5843b1ba1b1..b7b626db034 100644 --- a/src/libstd/old_io/pipe.rs +++ b/src/libstd/old_io/pipe.rs @@ -115,7 +115,7 @@ mod test { use prelude::v1::*; use sync::mpsc::channel; - use thread::Thread; + use thread; #[test] fn partial_read() { @@ -126,7 +126,7 @@ mod test { let out = PipeStream::open(writer); let mut input = PipeStream::open(reader); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut out = out; out.write(&[10]).unwrap(); rx.recv().unwrap(); // don't close the pipe until the other read has finished diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs index 195d33c41a6..8ed0946d857 100644 --- a/src/libstd/old_io/process.rs +++ b/src/libstd/old_io/process.rs @@ -30,7 +30,7 @@ use sync::mpsc::{channel, Receiver}; use sys::fs::FileDesc; use sys::process::Process as ProcessImp; use sys; -use thread::Thread; +use thread; #[cfg(windows)] use hash; #[cfg(windows)] use str; @@ -703,7 +703,7 @@ impl Process { let (tx, rx) = channel(); match stream { Some(stream) => { - Thread::spawn(move || { + thread::spawn(move || { let mut stream = stream; tx.send(stream.read_to_end()).unwrap(); }); @@ -764,7 +764,7 @@ mod tests { use super::{CreatePipe}; use super::{InheritFd, Process, PleaseExitSignal, Command, ProcessOutput}; use sync::mpsc::channel; - use thread::Thread; + use thread; use time::Duration; // FIXME(#10380) these tests should not all be ignored on android. @@ -1169,14 +1169,14 @@ mod tests { fn wait_timeout2() { let (tx, rx) = channel(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut p = sleeper(); p.set_timeout(Some(10)); assert_eq!(p.wait().err().unwrap().kind, TimedOut); p.signal_kill().unwrap(); tx.send(()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut p = sleeper(); p.set_timeout(Some(10)); assert_eq!(p.wait().err().unwrap().kind, TimedOut); diff --git a/src/libstd/old_io/stdio.rs b/src/libstd/old_io/stdio.rs index 70cce1f7e76..e3d0232684f 100644 --- a/src/libstd/old_io/stdio.rs +++ b/src/libstd/old_io/stdio.rs @@ -530,7 +530,7 @@ mod tests { use super::*; use sync::mpsc::channel; - use thread::Thread; + use thread; #[test] fn smoke() { @@ -546,7 +546,7 @@ mod tests { let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { set_stdout(box w); println!("hello!"); }); @@ -559,7 +559,7 @@ mod tests { let (tx, rx) = channel(); let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); - let _t = Thread::spawn(move || -> () { + let _t = thread::spawn(move || -> () { set_stderr(box w); panic!("my special message"); }); diff --git a/src/libstd/old_io/timer.rs b/src/libstd/old_io/timer.rs index 35f0bcb21d9..8b84e27eae1 100644 --- a/src/libstd/old_io/timer.rs +++ b/src/libstd/old_io/timer.rs @@ -224,13 +224,13 @@ fn in_ms_u64(d: Duration) -> u64 { #[cfg(test)] mod test { use super::Timer; - use thread::Thread; + use thread; use time::Duration; #[test] fn test_timer_send() { let mut timer = Timer::new().unwrap(); - Thread::spawn(move || timer.sleep(Duration::milliseconds(1))); + thread::spawn(move || timer.sleep(Duration::milliseconds(1))); } #[test] @@ -360,7 +360,7 @@ mod test { let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); - Thread::spawn(move|| { + thread::spawn(move|| { let _ = timer_rx.recv(); }); @@ -374,7 +374,7 @@ mod test { let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); - Thread::spawn(move|| { + thread::spawn(move|| { let _ = timer_rx.recv(); }); @@ -387,7 +387,7 @@ mod test { let mut timer = Timer::new().unwrap(); let timer_rx = timer.periodic(Duration::milliseconds(1000)); - Thread::spawn(move|| { + thread::spawn(move|| { let _ = timer_rx.recv(); }); diff --git a/src/libstd/old_path/posix.rs b/src/libstd/old_path/posix.rs index 6bf2a30b7b1..9bbce1934b0 100644 --- a/src/libstd/old_path/posix.rs +++ b/src/libstd/old_path/posix.rs @@ -518,18 +518,18 @@ mod tests { #[test] fn test_null_byte() { - use thread::Thread; - let result = Thread::scoped(move|| { + use thread; + let result = thread::spawn(move|| { Path::new(b"foo/bar\0") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move|| { + let result = thread::spawn(move|| { Path::new("test").set_filename(b"f\0o") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move|| { + let result = thread::spawn(move|| { Path::new("test").push(b"f\0o"); }).join(); assert!(result.is_err()); diff --git a/src/libstd/old_path/windows.rs b/src/libstd/old_path/windows.rs index 54c070e1b7d..8362e9a9530 100644 --- a/src/libstd/old_path/windows.rs +++ b/src/libstd/old_path/windows.rs @@ -1305,18 +1305,18 @@ mod tests { #[test] fn test_null_byte() { - use thread::Thread; - let result = Thread::scoped(move|| { + use thread; + let result = thread::spawn(move|| { Path::new(b"foo/bar\0") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move|| { + let result = thread::spawn(move|| { Path::new("test").set_filename(b"f\0o") }).join(); assert!(result.is_err()); - let result = Thread::scoped(move || { + let result = thread::spawn(move || { Path::new("test").push(b"f\0o"); }).join(); assert!(result.is_err()); diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index e485c6a63c6..35221a7e647 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -17,7 +17,7 @@ use cell::RefCell; use old_io::IoResult; use rt::{backtrace, unwind}; use rt::util::{Stderr, Stdio}; -use thread::Thread; +use thread; // Defined in this module instead of old_io::stdio so that the unwinding thread_local! { @@ -42,7 +42,7 @@ pub fn on_panic(obj: &(Any+Send), file: &'static str, line: uint) { } }; let mut err = Stderr; - let thread = Thread::current(); + let thread = thread::current(); let name = thread.name().unwrap_or(""); let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take()); match prev { diff --git a/src/libstd/process.rs b/src/libstd/process.rs index d2b98ec8939..4843138a104 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -27,7 +27,7 @@ use sys::process2::Process as ProcessImp; use sys::process2::Command as CommandImp; use sys::process2::ExitStatus as ExitStatusImp; use sys_common::{AsInner, AsInnerMut}; -use thread::Thread; +use thread; /// Representation of a running or exited child process. /// @@ -462,7 +462,7 @@ impl Child { let (tx, rx) = channel(); match stream { Some(stream) => { - Thread::spawn(move || { + thread::spawn(move || { let mut stream = stream; let mut ret = Vec::new(); let res = stream.read_to_end(&mut ret); @@ -499,7 +499,7 @@ mod tests { use str; use super::{Child, Command, Output, ExitStatus, Stdio}; use sync::mpsc::channel; - use thread::Thread; + use thread; use time::Duration; // FIXME(#10380) these tests should not all be ignored on android. diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 535af08c96c..0feacf5581c 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -360,7 +360,7 @@ mod test { use sync::mpsc::channel; use rand::Rng; use super::OsRng; - use thread::Thread; + use thread; #[test] fn test_os_rng() { @@ -381,23 +381,23 @@ mod test { let (tx, rx) = channel(); txs.push(tx); - Thread::spawn(move|| { + thread::spawn(move|| { // wait until all the tasks are ready to go. rx.recv().unwrap(); // deschedule to attempt to interleave things as much // as possible (XXX: is this a good test?) let mut r = OsRng::new().unwrap(); - Thread::yield_now(); + thread::yield_now(); let mut v = [0u8; 1000]; for _ in 0u..100 { r.next_u32(); - Thread::yield_now(); + thread::yield_now(); r.next_u64(); - Thread::yield_now(); + thread::yield_now(); r.fill_bytes(&mut v); - Thread::yield_now(); + thread::yield_now(); } }); } diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index bb57d19ed26..4868da5e69f 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -149,7 +149,7 @@ pub fn abort(args: fmt::Arguments) -> ! { } pub unsafe fn report_overflow() { - use thread::Thread; + use thread; // See the message below for why this is not emitted to the // ^ Where did the message below go? @@ -159,5 +159,5 @@ pub unsafe fn report_overflow() { // and the FFI call needs 2MB of stack when we just ran out. rterrln!("\nthread '{}' has overflowed its stack", - Thread::current().name().unwrap_or("")); + thread::current().name().unwrap_or("")); } diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index cca376f7b6d..fc781eb4bec 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -15,14 +15,14 @@ use sync::{Mutex, Condvar}; /// /// ```rust /// use std::sync::{Arc, Barrier}; -/// use std::thread::Thread; +/// use std::thread; /// /// let barrier = Arc::new(Barrier::new(10)); /// for _ in 0u..10 { /// let c = barrier.clone(); /// // The same messages will be printed together. /// // You will NOT see any interleaving. -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// println!("before wait"); /// c.wait(); /// println!("after wait"); @@ -111,7 +111,7 @@ mod tests { use sync::{Arc, Barrier}; use sync::mpsc::{channel, TryRecvError}; - use thread::Thread; + use thread; #[test] fn test_barrier() { @@ -123,7 +123,7 @@ mod tests { for _ in 0u..N - 1 { let c = barrier.clone(); let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(c.wait().is_leader()).unwrap(); }); } diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index d4d722cab3d..52561d482c3 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -38,13 +38,13 @@ use sync::{mutex, MutexGuard, PoisonError}; /// /// ``` /// use std::sync::{Arc, Mutex, Condvar}; -/// use std::thread::Thread; +/// use std::thread; /// /// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair2 = pair.clone(); /// /// // Inside of our lock, spawn a new thread, and then wait for it to start -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// let &(ref lock, ref cvar) = &*pair2; /// let mut started = lock.lock().unwrap(); /// *started = true; @@ -353,7 +353,7 @@ mod tests { use sync::mpsc::channel; use sync::{StaticMutex, MUTEX_INIT, Condvar, Mutex, Arc}; use sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; - use thread::Thread; + use thread; use time::Duration; #[test] @@ -377,7 +377,7 @@ mod tests { static M: StaticMutex = MUTEX_INIT; let g = M.lock().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = M.lock().unwrap(); C.notify_one(); }); @@ -395,7 +395,7 @@ mod tests { for _ in 0..N { let data = data.clone(); let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { let &(ref lock, ref cond) = &*data; let mut cnt = lock.lock().unwrap(); *cnt += 1; @@ -431,7 +431,7 @@ mod tests { let (g, _no_timeout) = C.wait_timeout(g, Duration::nanoseconds(1000)).unwrap(); // spurious wakeups mean this isn't necessarily true // assert!(!no_timeout); - let _t = Thread::spawn(move || { + let _t = thread::spawn(move || { let _g = M.lock().unwrap(); C.notify_one(); }); @@ -452,7 +452,7 @@ mod tests { assert!(!success); let (tx, rx) = channel(); - let _t = Thread::scoped(move || { + let _t = thread::spawn(move || { rx.recv().unwrap(); let g = M.lock().unwrap(); S.store(1, Ordering::SeqCst); @@ -492,7 +492,7 @@ mod tests { static C: StaticCondvar = CONDVAR_INIT; let mut g = M1.lock().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = M1.lock().unwrap(); C.notify_one(); }); diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index a230e35dac8..ae5c1e1b4a5 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -38,7 +38,7 @@ use core::mem::replace; use self::FutureState::*; use sync::mpsc::{Receiver, channel}; use thunk::{Thunk}; -use thread::Thread; +use thread; /// A type encapsulating the result of a computation which may not be complete pub struct Future { @@ -143,7 +143,7 @@ impl Future { let (tx, rx) = channel(); - Thread::spawn(move || { + thread::spawn(move || { // Don't panic if the other end has hung up let _ = tx.send(blk()); }); @@ -157,7 +157,7 @@ mod test { use prelude::v1::*; use sync::mpsc::channel; use sync::Future; - use thread::Thread; + use thread; #[test] fn test_from_value() { @@ -215,7 +215,7 @@ mod test { let expected = "schlorf"; let (tx, rx) = channel(); let f = Future::spawn(move|| { expected }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut f = f; tx.send(f.get()).unwrap(); }); diff --git a/src/libstd/sync/mpsc/blocking.rs b/src/libstd/sync/mpsc/blocking.rs index 61ffb532d36..69b1e242b15 100644 --- a/src/libstd/sync/mpsc/blocking.rs +++ b/src/libstd/sync/mpsc/blocking.rs @@ -10,7 +10,7 @@ //! Generic support for building blocking abstractions. -use thread::Thread; +use thread::{self, Thread}; use sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT, Ordering}; use sync::Arc; use marker::{Sync, Send}; @@ -40,7 +40,7 @@ impl !Sync for WaitToken {} pub fn tokens() -> (WaitToken, SignalToken) { let inner = Arc::new(Inner { - thread: Thread::current(), + thread: thread::current(), woken: ATOMIC_BOOL_INIT, }); let wait_token = WaitToken { @@ -80,7 +80,7 @@ impl SignalToken { impl WaitToken { pub fn wait(self) { while !self.inner.woken.load(Ordering::SeqCst) { - Thread::park() + thread::park() } } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index d783acd57ac..862745a05eb 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -53,12 +53,12 @@ //! Simple usage: //! //! ``` -//! use std::thread::Thread; +//! use std::thread; //! use std::sync::mpsc::channel; //! //! // Create a simple streaming channel //! let (tx, rx) = channel(); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! tx.send(10).unwrap(); //! }); //! assert_eq!(rx.recv().unwrap(), 10); @@ -67,7 +67,7 @@ //! Shared usage: //! //! ``` -//! use std::thread::Thread; +//! use std::thread; //! use std::sync::mpsc::channel; //! //! // Create a shared channel that can be sent along from many threads @@ -76,7 +76,7 @@ //! let (tx, rx) = channel(); //! for i in 0..10 { //! let tx = tx.clone(); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! tx.send(i).unwrap(); //! }); //! } @@ -102,11 +102,11 @@ //! Synchronous channels: //! //! ``` -//! use std::thread::Thread; +//! use std::thread; //! use std::sync::mpsc::sync_channel; //! //! let (tx, rx) = sync_channel::(0); -//! Thread::spawn(move|| { +//! thread::spawn(move|| { //! // This will wait for the parent task to start receiving //! tx.send(53).unwrap(); //! }); @@ -467,14 +467,14 @@ impl UnsafeFlavor for Receiver { /// /// ``` /// use std::sync::mpsc::channel; -/// use std::thread::Thread; +/// use std::thread; /// /// // tx is is the sending half (tx for transmission), and rx is the receiving /// // half (rx for receiving). /// let (tx, rx) = channel(); /// /// // Spawn off an expensive computation -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// # fn expensive_computation() {} /// tx.send(expensive_computation()).unwrap(); /// }); @@ -509,14 +509,14 @@ pub fn channel() -> (Sender, Receiver) { /// /// ``` /// use std::sync::mpsc::sync_channel; -/// use std::thread::Thread; +/// use std::thread; /// /// let (tx, rx) = sync_channel(1); /// /// // this returns immediately /// tx.send(1).unwrap(); /// -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// // this will block until the previous message has been received /// tx.send(2).unwrap(); /// }); @@ -1026,7 +1026,7 @@ mod test { use std::env; use super::*; - use thread::Thread; + use thread; pub fn stress_factor() -> uint { match env::var("RUST_TEST_STRESS") { @@ -1069,7 +1069,7 @@ mod test { #[test] fn smoke_threads() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(1).unwrap(); }); assert_eq!(rx.recv().unwrap(), 1); @@ -1101,7 +1101,7 @@ mod test { #[test] fn port_gone_concurrent() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() {} @@ -1111,7 +1111,7 @@ mod test { fn port_gone_concurrent_shared() { let (tx, rx) = channel::(); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() && tx2.send(1).is_ok() {} @@ -1136,7 +1136,7 @@ mod test { #[test] fn chan_gone_concurrent() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(1).unwrap(); tx.send(1).unwrap(); }); @@ -1146,7 +1146,7 @@ mod test { #[test] fn stress() { let (tx, rx) = channel::(); - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { for _ in 0u..10000 { tx.send(1).unwrap(); } }); for _ in 0u..10000 { @@ -1161,7 +1161,7 @@ mod test { static NTHREADS: uint = 8; let (tx, rx) = channel::(); - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { for _ in 0..AMT * NTHREADS { assert_eq!(rx.recv().unwrap(), 1); } @@ -1173,7 +1173,7 @@ mod test { for _ in 0..NTHREADS { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0..AMT { tx.send(1).unwrap(); } }); } @@ -1185,14 +1185,14 @@ mod test { fn send_from_outside_runtime() { let (tx1, rx1) = channel::<()>(); let (tx2, rx2) = channel::(); - let t1 = Thread::scoped(move|| { + let t1 = thread::spawn(move|| { tx1.send(()).unwrap(); for _ in 0..40 { assert_eq!(rx2.recv().unwrap(), 1); } }); rx1.recv().unwrap(); - let t2 = Thread::scoped(move|| { + let t2 = thread::spawn(move|| { for _ in 0..40 { tx2.send(1).unwrap(); } @@ -1204,7 +1204,7 @@ mod test { #[test] fn recv_from_outside_runtime() { let (tx, rx) = channel::(); - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { for _ in 0..40 { assert_eq!(rx.recv().unwrap(), 1); } @@ -1219,11 +1219,11 @@ mod test { fn no_runtime() { let (tx1, rx1) = channel::(); let (tx2, rx2) = channel::(); - let t1 = Thread::scoped(move|| { + let t1 = thread::spawn(move|| { assert_eq!(rx1.recv().unwrap(), 1); tx2.send(2).unwrap(); }); - let t2 = Thread::scoped(move|| { + let t2 = thread::spawn(move|| { tx1.send(1).unwrap(); assert_eq!(rx2.recv().unwrap(), 2); }); @@ -1256,7 +1256,7 @@ mod test { #[test] fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { let (tx, rx) = channel::(); drop(tx); rx.recv().unwrap(); @@ -1325,7 +1325,7 @@ mod test { #[test] fn oneshot_multi_task_recv_then_send() { let (tx, rx) = channel::>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }); @@ -1335,10 +1335,10 @@ mod test { #[test] fn oneshot_multi_task_recv_then_close() { let (tx, rx) = channel::>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(tx); }); - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }).join(); assert!(res.is_err()); @@ -1348,7 +1348,7 @@ mod test { fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); drop(tx); @@ -1359,10 +1359,10 @@ mod test { fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { tx.send(1).unwrap(); }).join(); } @@ -1372,14 +1372,14 @@ mod test { fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel::(); - Thread::spawn(move|| { - let res = Thread::scoped(move|| { + thread::spawn(move|| { + let res = thread::spawn(move|| { rx.recv().unwrap(); }).join(); assert!(res.is_err()); }); - let _t = Thread::spawn(move|| { - Thread::spawn(move|| { + let _t = thread::spawn(move|| { + thread::spawn(move|| { drop(tx); }); }); @@ -1390,7 +1390,7 @@ mod test { fn oneshot_multi_thread_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(box 10).unwrap(); }); assert!(rx.recv().unwrap() == box 10); @@ -1408,7 +1408,7 @@ mod test { fn send(tx: Sender>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(box i).unwrap(); send(tx, i + 1); }); @@ -1417,7 +1417,7 @@ mod test { fn recv(rx: Receiver>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { assert!(rx.recv().unwrap() == box i); recv(rx, i + 1); }); @@ -1439,7 +1439,7 @@ mod test { let total = stress_factor() + 100; for _ in 0..total { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); } @@ -1454,7 +1454,7 @@ mod test { let (tx, rx) = channel::(); let (total_tx, total_rx) = channel::(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acc = 0; for x in rx.iter() { acc += x; @@ -1474,7 +1474,7 @@ mod test { let (tx, rx) = channel::(); let (count_tx, count_rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut count = 0; for x in rx.iter() { if count >= 3 { @@ -1499,7 +1499,7 @@ mod test { let (tx1, rx1) = channel::(); let (tx2, rx2) = channel::<()>(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx2.recv().unwrap(); tx1.send(1).unwrap(); tx3.send(()).unwrap(); @@ -1524,13 +1524,13 @@ mod test { fn destroy_upgraded_shared_port_when_sender_still_active() { let (tx, rx) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); // wait on a oneshot drop(rx); // destroy a shared tx2.send(()).unwrap(); }); // make sure the other task has gone to sleep - for _ in 0u..5000 { Thread::yield_now(); } + for _ in 0u..5000 { thread::yield_now(); } // upgrade to a shared chan and send a message let t = tx.clone(); @@ -1547,7 +1547,7 @@ mod sync_tests { use prelude::v1::*; use std::env; - use thread::Thread; + use thread; use super::*; pub fn stress_factor() -> uint { @@ -1583,7 +1583,7 @@ mod sync_tests { #[test] fn smoke_threads() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(1).unwrap(); }); assert_eq!(rx.recv().unwrap(), 1); @@ -1608,7 +1608,7 @@ mod sync_tests { #[test] fn port_gone_concurrent() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() {} @@ -1618,7 +1618,7 @@ mod sync_tests { fn port_gone_concurrent_shared() { let (tx, rx) = sync_channel::(0); let tx2 = tx.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); while tx.send(1).is_ok() && tx2.send(1).is_ok() {} @@ -1643,7 +1643,7 @@ mod sync_tests { #[test] fn chan_gone_concurrent() { let (tx, rx) = sync_channel::(0); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(1).unwrap(); tx.send(1).unwrap(); }); @@ -1653,7 +1653,7 @@ mod sync_tests { #[test] fn stress() { let (tx, rx) = sync_channel::(0); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0u..10000 { tx.send(1).unwrap(); } }); for _ in 0u..10000 { @@ -1668,7 +1668,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (dtx, drx) = sync_channel::<()>(0); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0..AMT * NTHREADS { assert_eq!(rx.recv().unwrap(), 1); } @@ -1681,7 +1681,7 @@ mod sync_tests { for _ in 0..NTHREADS { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { for _ in 0..AMT { tx.send(1).unwrap(); } }); } @@ -1714,7 +1714,7 @@ mod sync_tests { #[test] fn oneshot_single_thread_recv_chan_close() { // Receiving on a closed chan will panic - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { let (tx, rx) = sync_channel::(0); drop(tx); rx.recv().unwrap(); @@ -1789,7 +1789,7 @@ mod sync_tests { #[test] fn oneshot_multi_task_recv_then_send() { let (tx, rx) = sync_channel::>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }); @@ -1799,10 +1799,10 @@ mod sync_tests { #[test] fn oneshot_multi_task_recv_then_close() { let (tx, rx) = sync_channel::>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(tx); }); - let res = Thread::scoped(move|| { + let res = thread::spawn(move|| { assert!(rx.recv().unwrap() == box 10); }).join(); assert!(res.is_err()); @@ -1812,7 +1812,7 @@ mod sync_tests { fn oneshot_multi_thread_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); drop(tx); @@ -1823,10 +1823,10 @@ mod sync_tests { fn oneshot_multi_thread_send_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { drop(rx); }); - let _ = Thread::scoped(move || { + let _ = thread::spawn(move || { tx.send(1).unwrap(); }).join(); } @@ -1836,14 +1836,14 @@ mod sync_tests { fn oneshot_multi_thread_recv_close_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { - let res = Thread::scoped(move|| { + let _t = thread::spawn(move|| { + let res = thread::spawn(move|| { rx.recv().unwrap(); }).join(); assert!(res.is_err()); }); - let _t = Thread::spawn(move|| { - Thread::spawn(move|| { + let _t = thread::spawn(move|| { + thread::spawn(move|| { drop(tx); }); }); @@ -1854,7 +1854,7 @@ mod sync_tests { fn oneshot_multi_thread_send_recv_stress() { for _ in 0..stress_factor() { let (tx, rx) = sync_channel::>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { tx.send(box 10).unwrap(); }); assert!(rx.recv().unwrap() == box 10); @@ -1872,7 +1872,7 @@ mod sync_tests { fn send(tx: SyncSender>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(box i).unwrap(); send(tx, i + 1); }); @@ -1881,7 +1881,7 @@ mod sync_tests { fn recv(rx: Receiver>, i: int) { if i == 10 { return } - Thread::spawn(move|| { + thread::spawn(move|| { assert!(rx.recv().unwrap() == box i); recv(rx, i + 1); }); @@ -1903,7 +1903,7 @@ mod sync_tests { let total = stress_factor() + 100; for _ in 0..total { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); } @@ -1918,7 +1918,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (total_tx, total_rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut acc = 0; for x in rx.iter() { acc += x; @@ -1938,7 +1938,7 @@ mod sync_tests { let (tx, rx) = sync_channel::(0); let (count_tx, count_rx) = sync_channel(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let mut count = 0; for x in rx.iter() { if count >= 3 { @@ -1963,7 +1963,7 @@ mod sync_tests { let (tx1, rx1) = sync_channel::(1); let (tx2, rx2) = sync_channel::<()>(1); let (tx3, rx3) = sync_channel::<()>(1); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx2.recv().unwrap(); tx1.send(1).unwrap(); tx3.send(()).unwrap(); @@ -1988,13 +1988,13 @@ mod sync_tests { fn destroy_upgraded_shared_port_when_sender_still_active() { let (tx, rx) = sync_channel::<()>(0); let (tx2, rx2) = sync_channel::<()>(0); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx.recv().unwrap(); // wait on a oneshot drop(rx); // destroy a shared tx2.send(()).unwrap(); }); // make sure the other task has gone to sleep - for _ in 0u..5000 { Thread::yield_now(); } + for _ in 0u..5000 { thread::yield_now(); } // upgrade to a shared chan and send a message let t = tx.clone(); @@ -2008,14 +2008,14 @@ mod sync_tests { #[test] fn send1() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { rx.recv().unwrap(); }); + let _t = thread::spawn(move|| { rx.recv().unwrap(); }); assert_eq!(tx.send(1), Ok(())); } #[test] fn send2() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { drop(rx); }); + let _t = thread::spawn(move|| { drop(rx); }); assert!(tx.send(1).is_err()); } @@ -2023,7 +2023,7 @@ mod sync_tests { fn send3() { let (tx, rx) = sync_channel::(1); assert_eq!(tx.send(1), Ok(())); - let _t =Thread::spawn(move|| { drop(rx); }); + let _t =thread::spawn(move|| { drop(rx); }); assert!(tx.send(1).is_err()); } @@ -2033,11 +2033,11 @@ mod sync_tests { let tx2 = tx.clone(); let (done, donerx) = channel(); let done2 = done.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(tx.send(1).is_err()); done.send(()).unwrap(); }); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { assert!(tx2.send(2).is_err()); done2.send(()).unwrap(); }); @@ -2073,7 +2073,7 @@ mod sync_tests { let (tx1, rx1) = sync_channel::<()>(3); let (tx2, rx2) = sync_channel::<()>(3); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx1.recv().unwrap(); tx2.try_send(()).unwrap(); }); diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 3980d2a1fef..c374f8bbcee 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -160,7 +160,7 @@ mod tests { use sync::mpsc::channel; use super::{Queue, Data, Empty, Inconsistent}; use sync::Arc; - use thread::Thread; + use thread; #[test] fn test_full() { @@ -184,7 +184,7 @@ mod tests { for _ in 0..nthreads { let tx = tx.clone(); let q = q.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { for i in 0..nmsgs { q.push(i); } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index 87b2fe8f100..652a9ebb020 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -347,7 +347,7 @@ impl Iterator for Packets { mod test { use prelude::v1::*; - use thread::Thread; + use thread; use sync::mpsc::*; // Don't use the libstd version so we can pull in the right Select structure @@ -427,11 +427,11 @@ mod test { let (_tx2, rx2) = channel::(); let (tx3, rx3) = channel::(); - let _t = Thread::spawn(move|| { - for _ in 0u..20 { Thread::yield_now(); } + let _t = thread::spawn(move|| { + for _ in 0u..20 { thread::yield_now(); } tx1.send(1).unwrap(); rx3.recv().unwrap(); - for _ in 0u..20 { Thread::yield_now(); } + for _ in 0u..20 { thread::yield_now(); } }); select! { @@ -451,8 +451,8 @@ mod test { let (tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { - for _ in 0u..20 { Thread::yield_now(); } + let _t = thread::spawn(move|| { + for _ in 0u..20 { thread::yield_now(); } tx1.send(1).unwrap(); tx2.send(2).unwrap(); rx3.recv().unwrap(); @@ -478,7 +478,7 @@ mod test { let (tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for i in 0..AMT { if i % 2 == 0 { tx1.send(i).unwrap(); @@ -504,7 +504,7 @@ mod test { let (_tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx3.recv().unwrap(); tx1.clone(); assert_eq!(rx3.try_recv(), Err(TryRecvError::Empty)); @@ -526,7 +526,7 @@ mod test { let (_tx2, rx2) = channel::(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { rx3.recv().unwrap(); tx1.clone(); assert_eq!(rx3.try_recv(), Err(TryRecvError::Empty)); @@ -547,7 +547,7 @@ mod test { let (tx1, rx1) = channel::<()>(); let (tx2, rx2) = channel::<()>(); let (tx3, rx3) = channel::<()>(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let s = Select::new(); let mut h1 = s.handle(&rx1); let mut h2 = s.handle(&rx2); @@ -557,7 +557,7 @@ mod test { tx3.send(()).unwrap(); }); - for _ in 0u..1000 { Thread::yield_now(); } + for _ in 0u..1000 { thread::yield_now(); } drop(tx1.clone()); tx2.send(()).unwrap(); rx3.recv().unwrap(); @@ -663,14 +663,14 @@ mod test { fn oneshot_data_waiting() { let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { select! { _n = rx1.recv() => {} } tx2.send(()).unwrap(); }); - for _ in 0u..100 { Thread::yield_now() } + for _ in 0u..100 { thread::yield_now() } tx1.send(()).unwrap(); rx2.recv().unwrap(); } @@ -683,14 +683,14 @@ mod test { tx1.send(()).unwrap(); rx1.recv().unwrap(); rx1.recv().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { select! { _n = rx1.recv() => {} } tx2.send(()).unwrap(); }); - for _ in 0u..100 { Thread::yield_now() } + for _ in 0u..100 { thread::yield_now() } tx1.send(()).unwrap(); rx2.recv().unwrap(); } @@ -702,14 +702,14 @@ mod test { drop(tx1.clone()); tx1.send(()).unwrap(); rx1.recv().unwrap(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { select! { _n = rx1.recv() => {} } tx2.send(()).unwrap(); }); - for _ in 0u..100 { Thread::yield_now() } + for _ in 0u..100 { thread::yield_now() } tx1.send(()).unwrap(); rx2.recv().unwrap(); } @@ -726,8 +726,8 @@ mod test { #[test] fn sync2() { let (tx, rx) = sync_channel::(0); - let _t = Thread::spawn(move|| { - for _ in 0u..100 { Thread::yield_now() } + let _t = thread::spawn(move|| { + for _ in 0u..100 { thread::yield_now() } tx.send(1).unwrap(); }); select! { @@ -739,8 +739,8 @@ mod test { fn sync3() { let (tx1, rx1) = sync_channel::(0); let (tx2, rx2): (Sender, Receiver) = channel(); - let _t = Thread::spawn(move|| { tx1.send(1).unwrap(); }); - let _t = Thread::spawn(move|| { tx2.send(2).unwrap(); }); + let _t = thread::spawn(move|| { tx1.send(1).unwrap(); }); + let _t = thread::spawn(move|| { tx2.send(2).unwrap(); }); select! { n = rx1.recv() => { let n = n.unwrap(); diff --git a/src/libstd/sync/mpsc/shared.rs b/src/libstd/sync/mpsc/shared.rs index 6c31fb92591..729e7991f97 100644 --- a/src/libstd/sync/mpsc/shared.rs +++ b/src/libstd/sync/mpsc/shared.rs @@ -31,7 +31,7 @@ use sync::mpsc::mpsc_queue as mpsc; use sync::mpsc::select::StartResult::*; use sync::mpsc::select::StartResult; use sync::{Mutex, MutexGuard}; -use thread::Thread; +use thread; const DISCONNECTED: isize = isize::MIN; const FUDGE: isize = 1024; @@ -194,7 +194,7 @@ impl Packet { match self.queue.pop() { mpsc::Data(..) => {} mpsc::Empty => break, - mpsc::Inconsistent => Thread::yield_now(), + mpsc::Inconsistent => thread::yield_now(), } } // maybe we're done, if we're not the last ones @@ -283,7 +283,7 @@ impl Packet { mpsc::Inconsistent => { let data; loop { - Thread::yield_now(); + thread::yield_now(); match self.queue.pop() { mpsc::Data(t) => { data = t; break } mpsc::Empty => panic!("inconsistent => empty"), @@ -460,7 +460,7 @@ impl Packet { drop(self.take_to_wake()); } else { while self.to_wake.load(Ordering::SeqCst) != 0 { - Thread::yield_now(); + thread::yield_now(); } } // if the number of steals is -1, it was the pre-emptive -1 steal diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index f0558c33d1e..c03bf024818 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -246,7 +246,7 @@ mod test { use sync::Arc; use super::Queue; - use thread::Thread; + use thread; use sync::mpsc::channel; #[test] @@ -324,7 +324,7 @@ mod test { let (tx, rx) = channel(); let q2 = q.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { for _ in 0u..100000 { loop { match q2.pop() { diff --git a/src/libstd/sync/mpsc/stream.rs b/src/libstd/sync/mpsc/stream.rs index ab9bd6b2ed7..2d528662f64 100644 --- a/src/libstd/sync/mpsc/stream.rs +++ b/src/libstd/sync/mpsc/stream.rs @@ -26,7 +26,7 @@ use core::prelude::*; use core::cmp; use core::isize; -use thread::Thread; +use thread; use sync::atomic::{AtomicIsize, AtomicUsize, Ordering, AtomicBool}; use sync::mpsc::Receiver; @@ -440,7 +440,7 @@ impl Packet { drop(self.take_to_wake()); } else { while self.to_wake.load(Ordering::SeqCst) != 0 { - Thread::yield_now(); + thread::yield_now(); } } assert_eq!(self.steals, 0); diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 74692c1273c..d7e8419f19f 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -47,7 +47,7 @@ use sys_common::mutex as sys; /// /// ```rust /// use std::sync::{Arc, Mutex}; -/// use std::thread::Thread; +/// use std::thread; /// use std::sync::mpsc::channel; /// /// const N: uint = 10; @@ -62,7 +62,7 @@ use sys_common::mutex as sys; /// let (tx, rx) = channel(); /// for _ in 0u..10 { /// let (data, tx) = (data.clone(), tx.clone()); -/// Thread::spawn(move || { +/// thread::spawn(move || { /// // The shared static can only be accessed once the lock is held. /// // Our non-atomic increment is safe because we're the only thread /// // which can access the shared state when the lock is held. @@ -85,12 +85,12 @@ use sys_common::mutex as sys; /// /// ```rust /// use std::sync::{Arc, Mutex}; -/// use std::thread::Thread; +/// use std::thread; /// /// let lock = Arc::new(Mutex::new(0u)); /// let lock2 = lock.clone(); /// -/// let _ = Thread::scoped(move || -> () { +/// let _ = thread::spawn(move || -> () { /// // This thread will acquire the mutex first, unwrapping the result of /// // `lock` because the lock has not been poisoned. /// let _lock = lock2.lock().unwrap(); @@ -350,7 +350,7 @@ mod test { use sync::mpsc::channel; use sync::{Arc, Mutex, StaticMutex, MUTEX_INIT, Condvar}; - use thread::Thread; + use thread; struct Packet(Arc<(Mutex, Condvar)>); @@ -393,9 +393,9 @@ mod test { let (tx, rx) = channel(); for _ in 0..K { let tx2 = tx.clone(); - Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); + thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); let tx2 = tx.clone(); - Thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); + thread::spawn(move|| { inc(); tx2.send(()).unwrap(); }); } drop(tx); @@ -419,7 +419,7 @@ mod test { let packet = Packet(Arc::new((Mutex::new(false), Condvar::new()))); let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { // wait until parent gets in rx.recv().unwrap(); let &(ref lock, ref cvar) = &*packet2.0; @@ -443,7 +443,7 @@ mod test { let packet2 = Packet(packet.0.clone()); let (tx, rx) = channel(); - let _t = Thread::spawn(move || -> () { + let _t = thread::spawn(move || -> () { rx.recv().unwrap(); let &(ref lock, ref cvar) = &*packet2.0; let _g = lock.lock().unwrap(); @@ -471,7 +471,7 @@ mod test { let arc = Arc::new(Mutex::new(1)); assert!(!arc.is_poisoned()); let arc2 = arc.clone(); - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { let lock = arc2.lock().unwrap(); assert_eq!(*lock, 2); }).join(); @@ -486,7 +486,7 @@ mod test { let arc = Arc::new(Mutex::new(1)); let arc2 = Arc::new(Mutex::new(arc)); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let lock = arc2.lock().unwrap(); let lock2 = lock.lock().unwrap(); assert_eq!(*lock2, 1); @@ -499,7 +499,7 @@ mod test { fn test_mutex_arc_access_in_unwind() { let arc = Arc::new(Mutex::new(1)); let arc2 = arc.clone(); - let _ = Thread::scoped(move|| -> () { + let _ = thread::spawn(move|| -> () { struct Unwinder { i: Arc>, } diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 29c2051e5ad..1e87c0d612b 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -127,7 +127,7 @@ impl Once { mod test { use prelude::v1::*; - use thread::Thread; + use thread; use super::{ONCE_INIT, Once}; use sync::mpsc::channel; @@ -149,8 +149,8 @@ mod test { let (tx, rx) = channel(); for _ in 0u..10 { let tx = tx.clone(); - Thread::spawn(move|| { - for _ in 0u..4 { Thread::yield_now() } + thread::spawn(move|| { + for _ in 0u..4 { thread::yield_now() } unsafe { O.call_once(|| { assert!(!run); diff --git a/src/libstd/sync/poison.rs b/src/libstd/sync/poison.rs index a93bd31f5ae..32c8150ba40 100644 --- a/src/libstd/sync/poison.rs +++ b/src/libstd/sync/poison.rs @@ -13,7 +13,7 @@ use prelude::v1::*; use cell::UnsafeCell; use error::{Error, FromError}; use fmt; -use thread::Thread; +use thread; pub struct Flag { failed: UnsafeCell } pub const FLAG_INIT: Flag = Flag { failed: UnsafeCell { value: false } }; @@ -21,7 +21,7 @@ pub const FLAG_INIT: Flag = Flag { failed: UnsafeCell { value: false } }; impl Flag { #[inline] pub fn borrow(&self) -> LockResult { - let ret = Guard { panicking: Thread::panicking() }; + let ret = Guard { panicking: thread::panicking() }; if unsafe { *self.failed.get() } { Err(PoisonError::new(ret)) } else { @@ -31,7 +31,7 @@ impl Flag { #[inline] pub fn done(&self, guard: &Guard) { - if !guard.panicking && Thread::panicking() { + if !guard.panicking && thread::panicking() { unsafe { *self.failed.get() = true; } } } diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index c4f1f2ccadd..402542b8bdc 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -400,7 +400,7 @@ mod tests { use rand::{self, Rng}; use sync::mpsc::channel; - use thread::Thread; + use thread; use sync::{Arc, RwLock, StaticRwLock, RW_LOCK_INIT}; #[test] @@ -431,7 +431,7 @@ mod tests { let (tx, rx) = channel::<()>(); for _ in 0..N { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut rng = rand::thread_rng(); for _ in 0..M { if rng.gen_weighted_bool(N) { @@ -452,7 +452,7 @@ mod tests { fn test_rw_arc_poison_wr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -464,7 +464,7 @@ mod tests { let arc = Arc::new(RwLock::new(1)); assert!(!arc.is_poisoned()); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -476,7 +476,7 @@ mod tests { fn test_rw_arc_no_poison_rr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.read().unwrap(); panic!(); }).join(); @@ -487,7 +487,7 @@ mod tests { fn test_rw_arc_no_poison_rw() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = Thread::scoped(move|| { + let _: Result = thread::spawn(move|| { let _lock = arc2.read().unwrap(); panic!() }).join(); @@ -501,12 +501,12 @@ mod tests { let arc2 = arc.clone(); let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { let mut lock = arc2.write().unwrap(); for _ in 0u..10 { let tmp = *lock; *lock = -1; - Thread::yield_now(); + thread::yield_now(); *lock = tmp + 1; } tx.send(()).unwrap(); @@ -516,7 +516,7 @@ mod tests { let mut children = Vec::new(); for _ in 0u..5 { let arc3 = arc.clone(); - children.push(Thread::scoped(move|| { + children.push(thread::spawn(move|| { let lock = arc3.read().unwrap(); assert!(*lock >= 0); })); @@ -537,7 +537,7 @@ mod tests { fn test_rw_arc_access_in_unwind() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _ = Thread::scoped(move|| -> () { + let _ = thread::spawn(move|| -> () { struct Unwinder { i: Arc>, } diff --git a/src/libstd/sync/semaphore.rs b/src/libstd/sync/semaphore.rs index 0304b898884..410e1c11bb9 100644 --- a/src/libstd/sync/semaphore.rs +++ b/src/libstd/sync/semaphore.rs @@ -114,7 +114,7 @@ mod tests { use sync::Arc; use super::Semaphore; use sync::mpsc::channel; - use thread::Thread; + use thread; #[test] fn test_sem_acquire_release() { @@ -134,7 +134,7 @@ mod tests { fn test_sem_as_mutex() { let s = Arc::new(Semaphore::new(1)); let s2 = s.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = s2.access(); }); let _g = s.access(); @@ -146,7 +146,7 @@ mod tests { let (tx, rx) = channel(); let s = Arc::new(Semaphore::new(0)); let s2 = s.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { s2.acquire(); tx.send(()).unwrap(); }); @@ -157,7 +157,7 @@ mod tests { let (tx, rx) = channel(); let s = Arc::new(Semaphore::new(0)); let s2 = s.clone(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { s2.release(); let _ = rx.recv(); }); @@ -173,7 +173,7 @@ mod tests { let s2 = s.clone(); let (tx1, rx1) = channel(); let (tx2, rx2) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _g = s2.access(); let _ = rx2.recv(); tx1.send(()).unwrap(); @@ -190,7 +190,7 @@ mod tests { let (tx, rx) = channel(); { let _g = s.access(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); drop(s2.access()); tx.send(()).unwrap(); diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index 684a46fd6ff..06c0c84c418 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -20,7 +20,7 @@ use core::prelude::*; use sync::{Arc, Mutex}; use sync::mpsc::{channel, Sender, Receiver}; -use thread::Thread; +use thread; use thunk::Thunk; struct Sentinel<'a> { @@ -112,7 +112,7 @@ impl TaskPool { } fn spawn_in_pool(jobs: Arc>>) { - Thread::spawn(move || { + thread::spawn(move || { // Will spawn a new thread on panic unless it is cancelled. let sentinel = Sentinel::new(&jobs); diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs index 255f474d4f4..d3273646b3f 100644 --- a/src/libstd/sys/common/helper_thread.rs +++ b/src/libstd/sys/common/helper_thread.rs @@ -30,7 +30,7 @@ use sync::{StaticMutex, StaticCondvar}; use sync::mpsc::{channel, Sender, Receiver}; use sys::helper_signal; -use thread::Thread; +use thread; /// A structure for management of a helper thread. /// @@ -95,7 +95,7 @@ impl Helper { let receive = RaceBox(receive); let t = f(); - Thread::spawn(move || { + thread::spawn(move || { helper(receive.0, rx, t); let _g = self.lock.lock().unwrap(); *self.shutdown.get() = true; diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index 92b936e74f6..65c706033f2 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -29,7 +29,7 @@ thread_local! { static THREAD_INFO: RefCell> = RefCell::new(N impl ThreadInfo { fn with(f: F) -> R where F: FnOnce(&mut ThreadInfo) -> R { if THREAD_INFO.state() == State::Destroyed { - panic!("Use of std::thread::Thread::current() is not possible after \ + panic!("Use of std::thread::current() is not possible after \ the thread's local data has been destroyed"); } @@ -63,7 +63,7 @@ pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) { })); } -// a hack to get around privacy restrictions; implemented by `std::thread::Thread` +// a hack to get around privacy restrictions; implemented by `std::thread` pub trait NewThread { fn new(name: Option) -> Self; } diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index 905fac07c5d..27b8784e394 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -24,7 +24,7 @@ //! # Usage //! //! This module should likely not be used directly unless other primitives are -//! being built on. types such as `thread_local::scoped::Key` are likely much +//! being built on. types such as `thread_local::spawn::Key` are likely much //! more useful in practice than this OS-based version which likely requires //! unsafe code to interoperate with. //! diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 4f667114d38..d0fde8344b2 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -42,23 +42,23 @@ //! Already-running threads are represented via the `Thread` type, which you can //! get in one of two ways: //! -//! * By spawning a new thread, e.g. using the `Thread::spawn` constructor; -//! * By requesting the current thread, using the `Thread::current` function. +//! * By spawning a new thread, e.g. using the `thread::spawn` constructor; +//! * By requesting the current thread, using the `thread::current` function. //! //! Threads can be named, and provide some built-in support for low-level //! synchronization described below. //! -//! The `Thread::current()` function is available even for threads not spawned +//! The `thread::current()` function is available even for threads not spawned //! by the APIs of this module. //! //! ## Spawning a thread //! -//! A new thread can be spawned using the `Thread::spawn` function: +//! A new thread can be spawned using the `thread::spawn` function: //! //! ```rust -//! use std::thread::Thread; +//! use std::thread; //! -//! Thread::spawn(move || { +//! thread::spawn(move || { //! println!("Hello, World!"); //! // some computation here //! }); @@ -76,14 +76,14 @@ //! For this scenario, use the `scoped` constructor: //! //! ```rust -//! use std::thread::Thread; +//! use std::thread; //! -//! let guard = Thread::scoped(move || { +//! let guard = thread::scoped(move || { //! println!("Hello, World!"); //! // some computation here //! }); //! // do some other work in the meantime -//! let result = guard.join(); +//! let output = guard.join(); //! ``` //! //! The `scoped` function doesn't return a `Thread` directly; instead, @@ -120,10 +120,10 @@ //! Conceptually, each `Thread` handle has an associated token, which is //! initially not present: //! -//! * The `Thread::park()` function blocks the current thread unless or until +//! * The `thread::park()` function blocks the current thread unless or until //! the token is available for its thread handle, at which point It atomically //! consumes the token. It may also return *spuriously*, without consuming the -//! token. `Thread::park_timeout()` does the same, but allows specifying a +//! token. `thread::park_timeout()` does the same, but allows specifying a //! maximum time to block the thread for. //! //! * The `unpark()` method on a `Thread` atomically makes the token available @@ -411,7 +411,7 @@ pub fn panicking() -> bool { // or futuxes, and in either case may allow spurious wakeups. #[stable(feature = "rust1", since = "1.0.0")] pub fn park() { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); while !*guard { guard = thread.inner.cvar.wait(guard).unwrap(); @@ -431,7 +431,7 @@ pub fn park() { /// See the module doc for more detail. #[unstable(feature = "std_misc", reason = "recently introduced, depends on Duration")] pub fn park_timeout(dur: Duration) { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); if !*guard { let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap(); @@ -512,7 +512,7 @@ impl Thread { #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park() { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); while !*guard { guard = thread.inner.cvar.wait(guard).unwrap(); @@ -524,7 +524,7 @@ impl Thread { #[deprecated(since = "1.0.0", reason = "use module-level free fucntion")] #[unstable(feature = "std_misc", reason = "recently introduced")] pub fn park_timeout(dur: Duration) { - let thread = Thread::current(); + let thread = current(); let mut guard = thread.inner.lock.lock().unwrap(); if !*guard { let (g, _) = thread.inner.cvar.wait_timeout(guard, dur).unwrap(); @@ -700,7 +700,7 @@ mod test { use boxed::BoxAny; use result; use std::old_io::{ChanReader, ChanWriter}; - use super::{Thread, Builder}; + use super::{self, Thread, Builder}; use thunk::Thunk; use time::Duration; @@ -709,22 +709,22 @@ mod test { #[test] fn test_unnamed_thread() { - Thread::scoped(move|| { - assert!(Thread::current().name().is_none()); + thread::spawn(move|| { + assert!(thread::current().name().is_none()); }).join().ok().unwrap(); } #[test] fn test_named_thread() { Builder::new().name("ada lovelace".to_string()).scoped(move|| { - assert!(Thread::current().name().unwrap() == "ada lovelace".to_string()); + assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); }).join().ok().unwrap(); } #[test] fn test_run_basic() { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); rx.recv().unwrap(); @@ -732,7 +732,7 @@ mod test { #[test] fn test_join_success() { - match Thread::scoped(move|| -> String { + match thread::spawn(move|| -> String { "Success!".to_string() }).join().as_ref().map(|s| &**s) { result::Result::Ok("Success!") => (), @@ -742,7 +742,7 @@ mod test { #[test] fn test_join_panic() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!() }).join() { result::Result::Err(_) => (), @@ -750,6 +750,26 @@ mod test { } } + #[test] + fn test_scoped_success() { + let res = thread::scoped(move|| -> String { + "Success!".to_string() + }).join(); + assert!(res == "Success!"); + } + + #[test] + #[should_fail] + fn test_scoped_panic() { + thread::scoped(|| panic!()).join(); + } + + #[test] + #[should_fail] + fn test_scoped_implicit_panic() { + thread::scoped(|| panic!()); + } + #[test] fn test_spawn_sched() { use clone::Clone; @@ -758,7 +778,7 @@ mod test { fn f(i: int, tx: Sender<()>) { let tx = tx.clone(); - Thread::spawn(move|| { + thread::spawn(move|| { if i == 0 { tx.send(()).unwrap(); } else { @@ -775,8 +795,8 @@ mod test { fn test_spawn_sched_childs_on_default_sched() { let (tx, rx) = channel(); - Thread::spawn(move|| { - Thread::spawn(move|| { + thread::spawn(move|| { + thread::spawn(move|| { tx.send(()).unwrap(); }); }); @@ -802,14 +822,14 @@ mod test { #[test] fn test_avoid_copying_the_body_spawn() { avoid_copying_the_body(|v| { - Thread::spawn(move || v.invoke(())); + thread::spawn(move || v.invoke(())); }); } #[test] fn test_avoid_copying_the_body_thread_spawn() { avoid_copying_the_body(|f| { - Thread::spawn(move|| { + thread::spawn(move|| { f.invoke(()); }); }) @@ -818,7 +838,7 @@ mod test { #[test] fn test_avoid_copying_the_body_join() { avoid_copying_the_body(|f| { - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { f.invoke(()) }).join(); }) @@ -834,21 +854,21 @@ mod test { fn child_no(x: uint) -> Thunk { return Thunk::new(move|| { if x < GENERATIONS { - Thread::spawn(move|| child_no(x+1).invoke(())); + thread::spawn(move|| child_no(x+1).invoke(())); } }); } - Thread::spawn(|| child_no(0).invoke(())); + thread::spawn(|| child_no(0).invoke(())); } #[test] fn test_simple_newsched_spawn() { - Thread::spawn(move || {}); + thread::spawn(move || {}); } #[test] fn test_try_panic_message_static_str() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!("static string"); }).join() { Err(e) => { @@ -862,7 +882,7 @@ mod test { #[test] fn test_try_panic_message_owned_str() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!("owned string".to_string()); }).join() { Err(e) => { @@ -876,7 +896,7 @@ mod test { #[test] fn test_try_panic_message_any() { - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!(box 413u16 as Box); }).join() { Err(e) => { @@ -894,7 +914,7 @@ mod test { fn test_try_panic_message_unit_struct() { struct Juju; - match Thread::scoped(move|| { + match thread::spawn(move|| { panic!(Juju) }).join() { Err(ref e) if e.is::() => {} @@ -920,15 +940,15 @@ mod test { #[test] fn test_park_timeout_unpark_before() { for _ in 0..10 { - Thread::current().unpark(); - Thread::park_timeout(Duration::seconds(10_000_000)); + thread::current().unpark(); + thread::park_timeout(Duration::seconds(10_000_000)); } } #[test] fn test_park_timeout_unpark_not_called() { for _ in 0..10 { - Thread::park_timeout(Duration::milliseconds(10)); + thread::park_timeout(Duration::milliseconds(10)); } } @@ -937,14 +957,14 @@ mod test { use std::old_io; for _ in 0..10 { - let th = Thread::current(); + let th = thread::current(); - let _guard = Thread::scoped(move || { + let _guard = thread::spawn(move || { old_io::timer::sleep(Duration::milliseconds(50)); th.unpark(); }); - Thread::park_timeout(Duration::seconds(10_000_000)); + thread::park_timeout(Duration::seconds(10_000_000)); } } diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index eab9cd84539..2ed296e081c 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -72,7 +72,7 @@ pub mod __impl { /// /// ``` /// use std::cell::RefCell; -/// use std::thread::Thread; +/// use std::thread; /// /// thread_local!(static FOO: RefCell = RefCell::new(1)); /// @@ -82,7 +82,7 @@ pub mod __impl { /// }); /// /// // each thread starts out with the initial value of 1 -/// Thread::spawn(move|| { +/// thread::spawn(move|| { /// FOO.with(|f| { /// assert_eq!(*f.borrow(), 1); /// *f.borrow_mut() = 3; @@ -548,7 +548,7 @@ mod tests { use sync::mpsc::{channel, Sender}; use cell::UnsafeCell; use super::State; - use thread::Thread; + use thread; struct Foo(Sender<()>); @@ -568,7 +568,7 @@ mod tests { *f.get() = 2; }); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { FOO.with(|f| unsafe { assert_eq!(*f.get(), 1); }); @@ -595,7 +595,7 @@ mod tests { } thread_local!(static FOO: Foo = foo()); - Thread::scoped(|| { + thread::spawn(|| { assert!(FOO.state() == State::Uninitialized); FOO.with(|_| { assert!(FOO.state() == State::Valid); @@ -611,7 +611,7 @@ mod tests { }); let (tx, rx) = channel(); - let _t = Thread::spawn(move|| unsafe { + let _t = thread::spawn(move|| unsafe { let mut tx = Some(tx); FOO.with(|f| { *f.get() = Some(Foo(tx.take().unwrap())); @@ -659,7 +659,7 @@ mod tests { } } - Thread::scoped(move|| { + thread::spawn(move|| { drop(S1); }).join().ok().unwrap(); } @@ -677,7 +677,7 @@ mod tests { } } - Thread::scoped(move|| unsafe { + thread::spawn(move|| unsafe { K1.with(|s| *s.get() = Some(S1)); }).join().ok().unwrap(); } @@ -704,7 +704,7 @@ mod tests { } let (tx, rx) = channel(); - let _t = Thread::spawn(move|| unsafe { + let _t = thread::spawn(move|| unsafe { let mut tx = Some(tx); K1.with(|s| *s.get() = Some(S1(tx.take().unwrap()))); }); diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index 01220e7bc1f..e4633ea0f76 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -84,7 +84,7 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")), thread_local)] - static $name: ::std::thread_local::scoped::Key<$t> = + static $name: ::std::thread_local::spawn::Key<$t> = __scoped_thread_local_inner!($t); ); (pub static $name:ident: $t:ty) => ( @@ -94,11 +94,11 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")), thread_local)] - pub static $name: ::std::thread_local::scoped::Key<$t> = + pub static $name: ::std::thread_local::spawn::Key<$t> = __scoped_thread_local_inner!($t); ); ($t:ty) => ({ - use std::thread_local::scoped::Key as __Key; + use std::thread_local::spawn::Key as __Key; #[cfg(not(any(windows, target_os = "android", @@ -106,7 +106,7 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")))] const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::scoped::__impl::KeyInner { + inner: ::std::thread_local::spawn::__impl::KeyInner { inner: ::std::cell::UnsafeCell { value: 0 as *mut _ }, } }; @@ -117,8 +117,8 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64"))] const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::scoped::__impl::KeyInner { - inner: ::std::thread_local::scoped::__impl::OS_INIT, + inner: ::std::thread_local::spawn::__impl::KeyInner { + inner: ::std::thread_local::spawn::__impl::OS_INIT, marker: ::std::marker::InvariantType, } }; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 860ce209d45..5e1b8a3fc90 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -879,7 +879,7 @@ pub fn run_test(opts: &TestOpts, monitor_ch: Sender, nocapture: bool, testfn: Thunk) { - Thread::spawn(move || { + thread::spawn(move || { let (tx, rx) = channel(); let mut reader = ChanReader::new(rx); let stdout = ChanWriter::new(tx.clone()); diff --git a/src/test/auxiliary/cci_capture_clause.rs b/src/test/auxiliary/cci_capture_clause.rs index 673c38697b7..29a6ce59658 100644 --- a/src/test/auxiliary/cci_capture_clause.rs +++ b/src/test/auxiliary/cci_capture_clause.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; use std::sync::mpsc::{Receiver, channel}; pub fn foo(x: T) -> Receiver { let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(x.clone()); }); rx diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 4e9c2fe99bd..3a8d65d73c9 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -21,7 +21,7 @@ use std::sync::mpsc::{channel, Sender, Receiver}; use std::os; use std::env; -use std::thread::Thread; +use std::thread; use std::time::Duration; fn move_out(_x: T) {} @@ -64,7 +64,7 @@ fn run(args: &[String]) { let mut worker_results = Vec::new(); for _ in 0u..workers { let to_child = to_child.clone(); - worker_results.push(Thread::scoped(move|| { + worker_results.push(thread::spawn(move|| { for _ in 0u..size / workers { //println!("worker {}: sending {} bytes", i, num_bytes); to_child.send(request::bytes(num_bytes)).unwrap(); @@ -72,7 +72,7 @@ fn run(args: &[String]) { //println!("worker {} exiting", i); })); } - Thread::spawn(move|| { + thread::spawn(move|| { server(&from_parent, &to_parent); }); diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 2530e8bd907..3f05b46aa71 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -17,7 +17,7 @@ use std::sync::mpsc::{channel, Sender, Receiver}; use std::os; use std::env; -use std::thread::Thread; +use std::thread; use std::time::Duration; enum request { @@ -57,7 +57,7 @@ fn run(args: &[String]) { let mut worker_results = Vec::new(); let from_parent = if workers == 1 { let (to_child, from_parent) = channel(); - worker_results.push(Thread::scoped(move|| { + worker_results.push(thread::spawn(move|| { for _ in 0u..size / workers { //println!("worker {}: sending {} bytes", i, num_bytes); to_child.send(request::bytes(num_bytes)); @@ -69,7 +69,7 @@ fn run(args: &[String]) { let (to_child, from_parent) = channel(); for _ in 0u..workers { let to_child = to_child.clone(); - worker_results.push(Thread::scoped(move|| { + worker_results.push(thread::spawn(move|| { for _ in 0u..size / workers { //println!("worker {}: sending {} bytes", i, num_bytes); to_child.send(request::bytes(num_bytes)); @@ -79,7 +79,7 @@ fn run(args: &[String]) { } from_parent }; - Thread::spawn(move|| { + thread::spawn(move|| { server(&from_parent, &to_parent); }); diff --git a/src/test/bench/rt-messaging-ping-pong.rs b/src/test/bench/rt-messaging-ping-pong.rs index e4e8b4a6e6e..1ecd983a5c5 100644 --- a/src/test/bench/rt-messaging-ping-pong.rs +++ b/src/test/bench/rt-messaging-ping-pong.rs @@ -19,7 +19,7 @@ use std::sync::mpsc::channel; use std::os; -use std::thread::Thread; +use std::thread; // This is a simple bench that creates M pairs of tasks. These // tasks ping-pong back and forth over a pair of streams. This is a @@ -35,7 +35,7 @@ fn ping_pong_bench(n: uint, m: uint) { // Create a channel: B->A let (btx, brx) = channel(); - let guard_a = Thread::scoped(move|| { + let guard_a = thread::spawn(move|| { let (tx, rx) = (atx, brx); for _ in 0..n { tx.send(()).unwrap(); @@ -43,7 +43,7 @@ fn ping_pong_bench(n: uint, m: uint) { } }); - let guard_b = Thread::scoped(move|| { + let guard_b = thread::spawn(move|| { let (tx, rx) = (btx, arx); for _ in 0..n { rx.recv().unwrap(); diff --git a/src/test/bench/rt-parfib.rs b/src/test/bench/rt-parfib.rs index 13b8a5ca763..4ab937d47e3 100644 --- a/src/test/bench/rt-parfib.rs +++ b/src/test/bench/rt-parfib.rs @@ -10,7 +10,7 @@ use std::sync::mpsc::channel; use std::os; -use std::thread::Thread; +use std::thread; // A simple implementation of parfib. One subtree is found in a new // task and communicated over a oneshot pipe, the other is found @@ -22,7 +22,7 @@ fn parfib(n: uint) -> uint { } let (tx, rx) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { tx.send(parfib(n-1)).unwrap(); }); let m2 = parfib(n-2); diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 0311a1ac7c4..b10d22e5d68 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -111,7 +111,7 @@ fn main() { let messages = range_step(min_depth, max_depth + 1, 2).map(|depth| { use std::num::Int; let iterations = 2.pow((max_depth - depth + min_depth) as usize); - Thread::scoped(move || inner(depth, iterations)) + thread::spawn(move || inner(depth, iterations)) }).collect::>(); for message in messages { diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index 628206986c5..8fc62098361 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -43,7 +43,7 @@ use self::Color::{Red, Yellow, Blue}; use std::sync::mpsc::{channel, Sender, Receiver}; use std::fmt; -use std::thread::Thread; +use std::thread; fn print_complements() { let all = [Blue, Red, Yellow]; @@ -187,7 +187,7 @@ fn rendezvous(nn: uint, set: Vec) { let to_rendezvous = to_rendezvous.clone(); let to_rendezvous_log = to_rendezvous_log.clone(); let (to_creature, from_rendezvous) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { creature(ii, col, from_rendezvous, diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 92e1bc1a922..8509a86e47d 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -39,7 +39,7 @@ // OF THE POSSIBILITY OF SUCH DAMAGE. use std::{cmp, iter, mem}; -use std::thread::Thread; +use std::thread; fn rotate(x: &mut [i32]) { let mut prev = x[0]; @@ -164,7 +164,7 @@ fn fannkuch(n: i32) -> (i32, i32) { for (_, j) in (0..N).zip(iter::count(0, k)) { let max = cmp::min(j+k, perm.max()); - futures.push(Thread::scoped(move|| { + futures.push(thread::spawn(move|| { work(perm, j as uint, max as uint) })) } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 3c96878179f..4d6ef3d533e 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -24,7 +24,7 @@ use std::option; use std::os; use std::env; use std::sync::mpsc::{channel, Sender, Receiver}; -use std::thread::Thread; +use std::thread; fn f64_cmp(x: f64, y: f64) -> Ordering { // arbitrarily decide that NaNs are larger than everything. @@ -172,7 +172,7 @@ fn main() { let (to_child, from_parent) = channel(); - Thread::spawn(move|| { + thread::spawn(move|| { make_sequence_processor(sz, &from_parent, &to_parent_); }); diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index ca920b2fa82..e6beb952603 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -45,7 +45,7 @@ use std::ascii::OwnedAsciiExt; use std::slice; use std::sync::Arc; -use std::thread::Thread; +use std::thread; static TABLE: [u8;4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ]; static TABLE_SIZE: uint = 2 << 16; @@ -303,11 +303,11 @@ fn main() { let nb_freqs: Vec<_> = (1u..3).map(|i| { let input = input.clone(); - (i, Thread::scoped(move|| generate_frequencies(&input, i))) + (i, thread::spawn(move|| generate_frequencies(&input, i))) }).collect(); let occ_freqs: Vec<_> = OCCURRENCES.iter().map(|&occ| { let input = input.clone(); - Thread::scoped(move|| generate_frequencies(&input, occ.len())) + thread::spawn(move|| generate_frequencies(&input, occ.len())) }).collect(); for (i, freq) in nb_freqs { diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index e2d51fbf411..fa5ddb1567a 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -46,7 +46,7 @@ use std::old_io; use std::os; use std::simd::f64x2; use std::sync::Arc; -use std::thread::Thread; +use std::thread; const ITER: usize = 50; const LIMIT: f64 = 2.0; @@ -81,7 +81,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let mut precalc_i = Vec::with_capacity(h); let precalc_futures = (0..WORKERS).map(|i| { - Thread::scoped(move|| { + thread::spawn(move|| { let mut rs = Vec::with_capacity(w / WORKERS); let mut is = Vec::with_capacity(w / WORKERS); @@ -122,7 +122,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let vec_init_r = arc_init_r.clone(); let vec_init_i = arc_init_i.clone(); - Thread::scoped(move|| { + thread::spawn(move|| { let mut res: Vec = Vec::with_capacity((chunk_size * w) / 8); let init_r_slice = vec_init_r; diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index d061403d590..a9c4bb99a0e 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -43,7 +43,7 @@ use std::iter::repeat; use std::sync::Arc; use std::sync::mpsc::channel; -use std::thread::Thread; +use std::thread; // // Utilities. @@ -317,7 +317,7 @@ fn par_search(masks: Vec>>) -> Data { let masks = masks.clone(); let tx = tx.clone(); let m = *m; - Thread::spawn(move|| { + thread::spawn(move|| { let mut data = Data::new(); search(&*masks, m, 1, List::Cons(m, &List::Nil), &mut data); tx.send(data).unwrap(); diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 9abc808f887..97e5533f2de 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -24,7 +24,7 @@ use std::sync::mpsc::{channel, Sender}; use std::os; use std::env; use std::result::Result::{Ok, Err}; -use std::thread::Thread; +use std::thread; use std::time::Duration; fn fib(n: int) -> int { @@ -36,15 +36,15 @@ fn fib(n: int) -> int { } else { let (tx1, rx) = channel(); let tx2 = tx1.clone(); - Thread::spawn(move|| pfib(&tx2, n - 1)); + thread::spawn(move|| pfib(&tx2, n - 1)); let tx2 = tx1.clone(); - Thread::spawn(move|| pfib(&tx2, n - 2)); + thread::spawn(move|| pfib(&tx2, n - 2)); tx.send(rx.recv().unwrap() + rx.recv().unwrap()); } } let (tx, rx) = channel(); - Thread::spawn(move|| pfib(&tx, n) ); + thread::spawn(move|| pfib(&tx, n) ); rx.recv().unwrap() } @@ -79,7 +79,7 @@ fn stress_task(id: int) { fn stress(num_tasks: int) { let mut results = Vec::new(); for i in 0..num_tasks { - results.push(Thread::scoped(move|| { + results.push(thread::spawn(move|| { stress_task(i); })); } diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index 94438319954..3d8b6e82848 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -47,7 +47,7 @@ extern crate libc; use std::old_io::stdio::{stdin_raw, stdout_raw}; use std::old_io::{IoResult, EndOfFile}; use std::ptr::{copy_memory, Unique}; -use std::thread::Thread; +use std::thread; struct Tables { table8: [u8;1 << 8], @@ -241,7 +241,7 @@ fn parallel<'a, I, T, F>(iter: I, f: F) // boundary. let f = Racy(&f as *const F as *const uint); let raw = Racy(chunk.repr()); - Thread::scoped(move|| { + thread::spawn(move|| { let f = f.0 as *const F; unsafe { (*f)(mem::transmute(raw.0)) } }) diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 8356df8d8a1..a8a90120ebb 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -44,7 +44,7 @@ #![feature(unboxed_closures)] use std::iter::{repeat, AdditiveIterator}; -use std::thread::Thread; +use std::thread; use std::mem; use std::num::Float; use std::os; @@ -129,7 +129,7 @@ fn parallel(v: &mut [T], f: F) // boundary. let f = Racy(&f as *const _ as *const uint); let raw = Racy(chunk.repr()); - Thread::scoped(move|| { + thread::spawn(move|| { let f = f.0 as *const F; unsafe { (*f)(i * size, mem::transmute(raw.0)) } }) diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 8614f94da89..29b9938b77b 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -39,7 +39,7 @@ // OF THE POSSIBILITY OF SUCH DAMAGE. use std::sync::mpsc::{channel, Sender, Receiver}; -use std::thread::Thread; +use std::thread; fn start(n_tasks: i32, token: i32) { let (tx, mut rx) = channel(); @@ -48,9 +48,9 @@ fn start(n_tasks: i32, token: i32) { for i in 2 .. n_tasks + 1 { let (tx, next_rx) = channel(); let cur_rx = std::mem::replace(&mut rx, next_rx); - guards.push(Thread::scoped(move|| roundtrip(i, tx, cur_rx))); + guards.push(thread::spawn(move|| roundtrip(i, tx, cur_rx))); } - let guard = Thread::scoped(move|| roundtrip(1, tx, rx)); + let guard = thread::spawn(move|| roundtrip(1, tx, rx)); } fn roundtrip(id: i32, tx: Sender, rx: Receiver) { diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index c45efe5f54b..6b412c47cd7 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -11,7 +11,7 @@ #![feature(unsafe_destructor, box_syntax)] use std::env; -use std::thread::Thread; +use std::thread; use std::time::Duration; #[derive(Clone)] @@ -32,7 +32,7 @@ fn main() { fn run(repeat: int, depth: int) { for _ in 0..repeat { let dur = Duration::span(|| { - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { recurse_or_panic(depth, None) }).join(); }); diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 9edb4201098..923be213fd3 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -20,15 +20,15 @@ use std::sync::mpsc::{channel, Sender}; use std::os; use std::env; -use std::thread::Thread; +use std::thread; fn child_generation(gens_left: uint, tx: Sender<()>) { // This used to be O(n^2) in the number of generations that ever existed. // With this code, only as many generations are alive at a time as tasks // alive at a time, - Thread::spawn(move|| { + thread::spawn(move|| { if gens_left & 1 == 1 { - Thread::yield_now(); // shake things up a bit + thread::yield_now(); // shake things up a bit } if gens_left > 0 { child_generation(gens_left - 1, tx); // recurse diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index 279b3fa432a..d10d9cb460f 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -10,12 +10,12 @@ use std::os; use std::env; -use std::thread::Thread; +use std::thread; fn f(n: uint) { let mut i = 0u; while i < n { - let _ = Thread::scoped(move|| g()).join(); + let _ = thread::spawn(move|| g()).join(); i += 1u; } } @@ -33,5 +33,5 @@ fn main() { }; let n = args[1].parse().unwrap(); let mut i = 0u; - while i < n { Thread::spawn(move|| f(n) ); i += 1u; } + while i < n { thread::spawn(move|| f(n) ); i += 1u; } } diff --git a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs index 980c498e39b..7f676f5166f 100644 --- a/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs +++ b/src/test/compile-fail/borrowck-loan-blocks-move-cc.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; fn borrow(v: &isize, f: F) where F: FnOnce(&isize) { f(v); @@ -19,7 +19,7 @@ fn borrow(v: &isize, f: F) where F: FnOnce(&isize) { fn box_imm() { let v = box 3; let _w = &v; - Thread::spawn(move|| { + thread::spawn(move|| { println!("v={}", *v); //~^ ERROR cannot move `v` into closure }); @@ -28,7 +28,7 @@ fn box_imm() { fn box_imm_explicit() { let v = box 3; let _w = &v; - Thread::spawn(move|| { + thread::spawn(move|| { println!("v={}", *v); //~^ ERROR cannot move }); diff --git a/src/test/compile-fail/borrowck-multiple-captures.rs b/src/test/compile-fail/borrowck-multiple-captures.rs index 94e213ae1ae..9db05d76284 100644 --- a/src/test/compile-fail/borrowck-multiple-captures.rs +++ b/src/test/compile-fail/borrowck-multiple-captures.rs @@ -10,7 +10,7 @@ #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; fn borrow(_: &T) { } @@ -19,7 +19,7 @@ fn different_vars_after_borrows() { let p1 = &x1; let x2 = box 2; let p2 = &x2; - Thread::spawn(move|| { + thread::spawn(move|| { drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed }); @@ -32,7 +32,7 @@ fn different_vars_after_moves() { drop(x1); let x2 = box 2; drop(x2); - Thread::spawn(move|| { + thread::spawn(move|| { drop(x1); //~ ERROR capture of moved value: `x1` drop(x2); //~ ERROR capture of moved value: `x2` }); @@ -41,7 +41,7 @@ fn different_vars_after_moves() { fn same_var_after_borrow() { let x = box 1; let p = &x; - Thread::spawn(move|| { + thread::spawn(move|| { drop(x); //~ ERROR cannot move `x` into closure because it is borrowed drop(x); //~ ERROR use of moved value: `x` }); @@ -51,7 +51,7 @@ fn same_var_after_borrow() { fn same_var_after_move() { let x = box 1; drop(x); - Thread::spawn(move|| { + thread::spawn(move|| { drop(x); //~ ERROR capture of moved value: `x` drop(x); //~ ERROR use of moved value: `x` }); diff --git a/src/test/compile-fail/issue-12041.rs b/src/test/compile-fail/issue-12041.rs index 236142a6919..735f529277c 100644 --- a/src/test/compile-fail/issue-12041.rs +++ b/src/test/compile-fail/issue-12041.rs @@ -9,11 +9,11 @@ // except according to those terms. use std::sync::mpsc::channel; -use std::thread::Thread; +use std::thread; fn main() { let (tx, rx) = channel(); - let _t = Thread::spawn(move|| -> () { + let _t = thread::spawn(move|| -> () { loop { let tx = tx; //~^ ERROR: use of moved value: `tx` diff --git a/src/test/compile-fail/issue-8460-const.rs b/src/test/compile-fail/issue-8460-const.rs index 01bed69fb1d..4e44b4dcdce 100644 --- a/src/test/compile-fail/issue-8460-const.rs +++ b/src/test/compile-fail/issue-8460-const.rs @@ -9,47 +9,47 @@ // except according to those terms. use std::{int, i8, i16, i32, i64}; -use std::thread::Thread; +use std::thread; fn main() { - assert!(Thread::scoped(move|| int::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| int::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i8::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i8::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i16::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i16::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i32::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i32::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| i64::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| i64::MIN / -1).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(Thread::scoped(move|| 1is / 0).join().is_err()); + assert!(thread::spawn(move|| 1is / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i8 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i8 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i16 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i16 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i32 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i32 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| 1i64 / 0).join().is_err()); + assert!(thread::spawn(move|| 1i64 / 0).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(Thread::scoped(move|| int::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| int::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i8::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i8::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i16::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i16::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i32::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i32::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| i64::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| i64::MIN % -1).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(Thread::scoped(move|| 1is % 0).join().is_err()); + assert!(thread::spawn(move|| 1is % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i8 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i8 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i16 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i16 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i32 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i32 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(Thread::scoped(move|| 1i64 % 0).join().is_err()); + assert!(thread::spawn(move|| 1i64 % 0).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression } diff --git a/src/test/compile-fail/missing-stability.rs b/src/test/compile-fail/missing-stability.rs index 14dd983161b..cf7a8378b9a 100644 --- a/src/test/compile-fail/missing-stability.rs +++ b/src/test/compile-fail/missing-stability.rs @@ -30,4 +30,4 @@ pub mod bar { // #[stable] is not inherited pub fn unmarked() {} //~^ ERROR This node does not have a stability attribute -} \ No newline at end of file +} diff --git a/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs b/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs index dc90994fcc1..32fa773ec80 100644 --- a/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-capture-clause-bad.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; fn main() { let x = "Hello world!".to_string(); - Thread::spawn(move|| { + thread::spawn(move|| { println!("{}", x); }); println!("{}", x); //~ ERROR use of moved value diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index 939d7c7a534..7b7b3c414dd 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -11,13 +11,13 @@ // error-pattern: use of moved value use std::sync::Arc; -use std::thread::Thread; +use std::thread; fn main() { let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); - Thread::spawn(move|| { + thread::spawn(move|| { assert_eq!((*arc_v)[3], 4); }); diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index 730ba9ab9ea..1720b40c83b 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -9,13 +9,13 @@ // except according to those terms. use std::sync::Arc; -use std::thread::Thread; +use std::thread; fn main() { let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); - Thread::spawn(move|| { + thread::spawn(move|| { assert_eq!((*arc_v)[3], 4); }); diff --git a/src/test/compile-fail/no-send-res-ports.rs b/src/test/compile-fail/no-send-res-ports.rs index ae2847aab09..5ebc386109a 100644 --- a/src/test/compile-fail/no-send-res-ports.rs +++ b/src/test/compile-fail/no-send-res-ports.rs @@ -10,7 +10,7 @@ #![feature(unsafe_destructor)] -use std::thread::Thread; +use std::thread; use std::rc::Rc; #[derive(Debug)] @@ -35,7 +35,7 @@ fn main() { let x = foo(Port(Rc::new(()))); - Thread::spawn(move|| { + thread::spawn(move|| { //~^ ERROR `core::marker::Send` is not implemented let y = x; println!("{:?}", y); diff --git a/src/test/run-fail/panic-task-name-none.rs b/src/test/run-fail/panic-task-name-none.rs index 816ee84a841..40a881852f5 100644 --- a/src/test/run-fail/panic-task-name-none.rs +++ b/src/test/run-fail/panic-task-name-none.rs @@ -10,10 +10,10 @@ // error-pattern:thread '' panicked at 'test' -use std::thread::Thread; +use std::thread; fn main() { - let r: Result = Thread::scoped(move|| { + let r: Result = thread::spawn(move|| { panic!("test"); 1 }).join(); diff --git a/src/test/run-fail/rt-set-exit-status-panic2.rs b/src/test/run-fail/rt-set-exit-status-panic2.rs index 446ef6f97e2..775d38c8b30 100644 --- a/src/test/run-fail/rt-set-exit-status-panic2.rs +++ b/src/test/run-fail/rt-set-exit-status-panic2.rs @@ -12,7 +12,7 @@ #[macro_use] extern crate log; use std::os; -use std::thread::Thread; +use std::thread; struct r { x:int, @@ -35,7 +35,7 @@ fn r(x:int) -> r { fn main() { error!("whatever"); - let _t = Thread::spawn(move|| { + let _t = thread::spawn(move|| { let _i = r(5); }); panic!(); diff --git a/src/test/run-fail/task-spawn-barefn.rs b/src/test/run-fail/task-spawn-barefn.rs index d58148810da..406f7dbcb67 100644 --- a/src/test/run-fail/task-spawn-barefn.rs +++ b/src/test/run-fail/task-spawn-barefn.rs @@ -10,12 +10,12 @@ // error-pattern:Ensure that the child task runs by panicking -use std::thread::Thread; +use std::thread; fn main() { // the purpose of this test is to make sure that task::spawn() // works when provided with a bare function: - let r = Thread::scoped(startfn).join(); + let r = thread::spawn(startfn).join(); if r.is_err() { panic!() } diff --git a/src/test/run-pass/unique-send-2.rs b/src/test/run-pass/unique-send-2.rs index f0b634c0d44..08ffe403696 100644 --- a/src/test/run-pass/unique-send-2.rs +++ b/src/test/run-pass/unique-send-2.rs @@ -12,7 +12,7 @@ #![feature(box_syntax)] use std::sync::mpsc::{channel, Sender}; -use std::thread::Thread; +use std::thread; fn child(tx: &Sender>, i: uint) { tx.send(box i).unwrap(); @@ -25,7 +25,7 @@ pub fn main() { let _t = (0u..n).map(|i| { expected += i; let tx = tx.clone(); - Thread::scoped(move|| { + thread::spawn(move|| { child(&tx, i) }) }).collect::>(); diff --git a/src/test/run-pass/unit-like-struct-drop-run.rs b/src/test/run-pass/unit-like-struct-drop-run.rs index 0acf736e2ab..ac46187f03a 100644 --- a/src/test/run-pass/unit-like-struct-drop-run.rs +++ b/src/test/run-pass/unit-like-struct-drop-run.rs @@ -11,7 +11,7 @@ // Make sure the destructor is run for unit-like structs. use std::boxed::BoxAny; -use std::thread::Thread; +use std::thread; struct Foo; @@ -22,7 +22,7 @@ impl Drop for Foo { } pub fn main() { - let x = Thread::scoped(move|| { + let x = thread::spawn(move|| { let _b = Foo; }).join(); diff --git a/src/test/run-pass/unwind-resource.rs b/src/test/run-pass/unwind-resource.rs index 159bac10183..52c09aadfbd 100644 --- a/src/test/run-pass/unwind-resource.rs +++ b/src/test/run-pass/unwind-resource.rs @@ -9,7 +9,7 @@ // except according to those terms. use std::sync::mpsc::{channel, Sender}; -use std::thread::Thread; +use std::thread; struct complainer { tx: Sender, @@ -37,7 +37,7 @@ fn f(tx: Sender) { pub fn main() { let (tx, rx) = channel(); - let _t = Thread::scoped(move|| f(tx.clone())); + let _t = thread::spawn(move|| f(tx.clone())); println!("hiiiiiiiii"); assert!(rx.recv().unwrap()); } diff --git a/src/test/run-pass/unwind-unique.rs b/src/test/run-pass/unwind-unique.rs index ea52802d245..d38b6e79eba 100644 --- a/src/test/run-pass/unwind-unique.rs +++ b/src/test/run-pass/unwind-unique.rs @@ -11,7 +11,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; fn f() { let _a = box 0; @@ -19,5 +19,5 @@ fn f() { } pub fn main() { - let _t = Thread::scoped(f); + let _t = thread::spawn(f); } diff --git a/src/test/run-pass/vector-sort-panic-safe.rs b/src/test/run-pass/vector-sort-panic-safe.rs index d13369b1f52..da9cf35813b 100644 --- a/src/test/run-pass/vector-sort-panic-safe.rs +++ b/src/test/run-pass/vector-sort-panic-safe.rs @@ -10,7 +10,7 @@ use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use std::rand::{thread_rng, Rng, Rand}; -use std::thread::Thread; +use std::thread; const REPEATS: usize = 5; const MAX_LEN: usize = 32; @@ -79,7 +79,7 @@ pub fn main() { let v = main.clone(); - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { let mut v = v; let mut panic_countdown = panic_countdown; v.sort_by(|a, b| { diff --git a/src/test/run-pass/weak-lang-item.rs b/src/test/run-pass/weak-lang-item.rs index b1c65d322ab..741e8be02f7 100644 --- a/src/test/run-pass/weak-lang-item.rs +++ b/src/test/run-pass/weak-lang-item.rs @@ -12,10 +12,10 @@ extern crate "weak-lang-items" as other; -use std::thread::Thread; +use std::thread; fn main() { - let _ = Thread::scoped(move|| { + let _ = thread::spawn(move|| { other::foo() }); } diff --git a/src/test/run-pass/yield.rs b/src/test/run-pass/yield.rs index 9ad6dd9d2b1..45a74750958 100644 --- a/src/test/run-pass/yield.rs +++ b/src/test/run-pass/yield.rs @@ -8,18 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { - let mut result = Thread::scoped(child); + let mut result = thread::spawn(child); println!("1"); - Thread::yield_now(); + thread::yield_now(); println!("2"); - Thread::yield_now(); + thread::yield_now(); println!("3"); result.join(); } fn child() { - println!("4"); Thread::yield_now(); println!("5"); Thread::yield_now(); println!("6"); + println!("4"); thread::yield_now(); println!("5"); thread::yield_now(); println!("6"); } diff --git a/src/test/run-pass/yield1.rs b/src/test/run-pass/yield1.rs index 3d3a36021da..69d8431082c 100644 --- a/src/test/run-pass/yield1.rs +++ b/src/test/run-pass/yield1.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { - let mut result = Thread::scoped(child); + let mut result = thread::spawn(child); println!("1"); - Thread::yield_now(); + thread::yield_now(); result.join(); } diff --git a/src/test/run-pass/yield2.rs b/src/test/run-pass/yield2.rs index 66ad7de0296..56dc02c6d2e 100644 --- a/src/test/run-pass/yield2.rs +++ b/src/test/run-pass/yield2.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { let mut i: int = 0; - while i < 100 { i = i + 1; println!("{}", i); Thread::yield_now(); } + while i < 100 { i = i + 1; println!("{}", i); thread::yield_now(); } } -- cgit 1.4.1-3-g733a5 From 7a14f4994eb4527a38d02c61fa83822df02f7b5d Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Tue, 17 Feb 2015 23:48:32 +1100 Subject: Update tests for the Send - 'static change. --- src/libstd/old_io/net/pipe.rs | 2 +- src/libstd/process.rs | 2 +- src/libstd/thread.rs | 4 +- src/test/auxiliary/cci_capture_clause.rs | 2 +- src/test/bench/shootout-reverse-complement.rs | 19 ++--- src/test/bench/shootout-spectralnorm.rs | 18 ++--- src/test/compile-fail/builtin-superkinds-simple.rs | 4 +- src/test/compile-fail/coherence-impls-builtin.rs | 9 ++- src/test/compile-fail/kindck-impl-type-params.rs | 2 +- src/test/compile-fail/kindck-send-object.rs | 4 +- src/test/compile-fail/kindck-send-object1.rs | 8 +-- src/test/compile-fail/kindck-send-object2.rs | 4 +- src/test/compile-fail/kindck-send-owned.rs | 4 +- .../compile-fail/kindck-send-region-pointers.rs | 34 --------- src/test/compile-fail/regions-bounded-by-send.rs | 83 ---------------------- .../regions-pattern-typing-issue-19552.rs | 4 +- src/test/compile-fail/trait-bounds-cant-coerce.rs | 2 +- .../builtin-superkinds-capabilities-transitive.rs | 2 +- .../run-pass/builtin-superkinds-capabilities-xc.rs | 2 +- .../run-pass/builtin-superkinds-capabilities.rs | 2 +- src/test/run-pass/builtin-superkinds-self-type.rs | 4 +- src/test/run-pass/issue-18188.rs | 10 +-- src/test/run-pass/issue-21058.rs | 4 +- src/test/run-pass/issue-2190-1.rs | 4 +- src/test/run-pass/send-type-inference.rs | 2 +- 25 files changed, 52 insertions(+), 183 deletions(-) delete mode 100644 src/test/compile-fail/kindck-send-region-pointers.rs delete mode 100644 src/test/compile-fail/regions-bounded-by-send.rs (limited to 'src/libstd') diff --git a/src/libstd/old_io/net/pipe.rs b/src/libstd/old_io/net/pipe.rs index 8c4a10a55d4..6dd73273122 100644 --- a/src/libstd/old_io/net/pipe.rs +++ b/src/libstd/old_io/net/pipe.rs @@ -287,7 +287,7 @@ mod tests { pub fn smalltest(server: F, client: G) where F : FnOnce(UnixStream), F : Send, - G : FnOnce(UnixStream), G : Send + G : FnOnce(UnixStream), G : Send + 'static { let path1 = next_test_unix(); let path2 = path1.clone(); diff --git a/src/libstd/process.rs b/src/libstd/process.rs index d2b98ec8939..05b5e47103f 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -458,7 +458,7 @@ impl Child { /// the parent waits for the child to exit. pub fn wait_with_output(mut self) -> io::Result { drop(self.stdin.take()); - fn read(stream: Option) -> Receiver>> { + fn read(stream: Option) -> Receiver>> { let (tx, rx) = channel(); match stream { Some(stream) => { diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index c662a1dafa1..d5dcdca5fbf 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -630,7 +630,7 @@ mod test { rx.recv().unwrap(); } - fn avoid_copying_the_body(spawnfn: F) where F: FnOnce(Thunk) { + fn avoid_copying_the_body(spawnfn: F) where F: FnOnce(Thunk<'static>) { let (tx, rx) = channel::(); let x = box 1; @@ -677,7 +677,7 @@ mod test { // (well, it would if the constant were 8000+ - I lowered it to be more // valgrind-friendly. try this at home, instead..!) static GENERATIONS: uint = 16; - fn child_no(x: uint) -> Thunk { + fn child_no(x: uint) -> Thunk<'static> { return Thunk::new(move|| { if x < GENERATIONS { Thread::spawn(move|| child_no(x+1).invoke(())); diff --git a/src/test/auxiliary/cci_capture_clause.rs b/src/test/auxiliary/cci_capture_clause.rs index 673c38697b7..2053f635c44 100644 --- a/src/test/auxiliary/cci_capture_clause.rs +++ b/src/test/auxiliary/cci_capture_clause.rs @@ -11,7 +11,7 @@ use std::thread::Thread; use std::sync::mpsc::{Receiver, channel}; -pub fn foo(x: T) -> Receiver { +pub fn foo(x: T) -> Receiver { let (tx, rx) = channel(); Thread::spawn(move|| { tx.send(x.clone()); diff --git a/src/test/bench/shootout-reverse-complement.rs b/src/test/bench/shootout-reverse-complement.rs index 94438319954..469923d80b6 100644 --- a/src/test/bench/shootout-reverse-complement.rs +++ b/src/test/bench/shootout-reverse-complement.rs @@ -229,21 +229,12 @@ unsafe impl Send for Racy {} /// Executes a closure in parallel over the given iterator over mutable slice. /// The closure `f` is run in parallel with an element of `iter`. -fn parallel<'a, I, T, F>(iter: I, f: F) - where T: 'a+Send + Sync, - I: Iterator, - F: Fn(&mut [T]) + Sync { - use std::mem; - use std::raw::Repr; - - iter.map(|chunk| { - // Need to convert `f` and `chunk` to something that can cross the task - // boundary. - let f = Racy(&f as *const F as *const uint); - let raw = Racy(chunk.repr()); +fn parallel<'a, I: Iterator, F>(iter: I, ref f: F) + where I::Item: Send + 'a, + F: Fn(I::Item) + Sync + 'a { + iter.map(|x| { Thread::scoped(move|| { - let f = f.0 as *const F; - unsafe { (*f)(mem::transmute(raw.0)) } + f(x) }) }).collect::>(); } diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 8356df8d8a1..0c77120e506 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -112,26 +112,16 @@ fn dot(v: &[f64], u: &[f64]) -> f64 { } -struct Racy(T); - -unsafe impl Send for Racy {} - // Executes a closure in parallel over the given mutable slice. The closure `f` // is run in parallel and yielded the starting index within `v` as well as a // sub-slice of `v`. -fn parallel(v: &mut [T], f: F) - where T: Send + Sync, - F: Fn(uint, &mut [T]) + Sync { +fn parallel<'a,T, F>(v: &mut [T], ref f: F) + where T: Send + Sync + 'a, + F: Fn(uint, &mut [T]) + Sync + 'a { let size = v.len() / os::num_cpus() + 1; - v.chunks_mut(size).enumerate().map(|(i, chunk)| { - // Need to convert `f` and `chunk` to something that can cross the task - // boundary. - let f = Racy(&f as *const _ as *const uint); - let raw = Racy(chunk.repr()); Thread::scoped(move|| { - let f = f.0 as *const F; - unsafe { (*f)(i * size, mem::transmute(raw.0)) } + f(i * size, chunk) }) }).collect::>(); } diff --git a/src/test/compile-fail/builtin-superkinds-simple.rs b/src/test/compile-fail/builtin-superkinds-simple.rs index c7b75ade555..c3fb6a1be87 100644 --- a/src/test/compile-fail/builtin-superkinds-simple.rs +++ b/src/test/compile-fail/builtin-superkinds-simple.rs @@ -13,7 +13,7 @@ trait Foo : Send { } -impl <'a> Foo for &'a mut () { } -//~^ ERROR the type `&'a mut ()` does not fulfill the required lifetime +impl Foo for std::rc::Rc { } +//~^ ERROR the trait `core::marker::Send` is not implemented fn main() { } diff --git a/src/test/compile-fail/coherence-impls-builtin.rs b/src/test/compile-fail/coherence-impls-builtin.rs index 2ca288b60a3..38730d241f6 100644 --- a/src/test/compile-fail/coherence-impls-builtin.rs +++ b/src/test/compile-fail/coherence-impls-builtin.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(optin_builtin_traits)] + use std::marker::Send; enum TestE { @@ -16,18 +18,21 @@ enum TestE { struct MyType; +struct NotSync; +impl !Sync for NotSync {} + unsafe impl Send for TestE {} unsafe impl Send for MyType {} unsafe impl Send for (MyType, MyType) {} //~^ ERROR builtin traits can only be implemented on structs or enums -unsafe impl Send for &'static MyType {} +unsafe impl Send for &'static NotSync {} //~^ ERROR builtin traits can only be implemented on structs or enums unsafe impl Send for [MyType] {} //~^ ERROR builtin traits can only be implemented on structs or enums -unsafe impl Send for &'static [MyType] {} +unsafe impl Send for &'static [NotSync] {} //~^ ERROR builtin traits can only be implemented on structs or enums fn is_send() {} diff --git a/src/test/compile-fail/kindck-impl-type-params.rs b/src/test/compile-fail/kindck-impl-type-params.rs index de7639c6213..d5276efa8be 100644 --- a/src/test/compile-fail/kindck-impl-type-params.rs +++ b/src/test/compile-fail/kindck-impl-type-params.rs @@ -17,7 +17,7 @@ struct S; trait Gettable {} -impl Gettable for S {} +impl Gettable for S {} fn f(val: T) { let t: S = S; diff --git a/src/test/compile-fail/kindck-send-object.rs b/src/test/compile-fail/kindck-send-object.rs index 7984b3b32c2..570f7ad7fe3 100644 --- a/src/test/compile-fail/kindck-send-object.rs +++ b/src/test/compile-fail/kindck-send-object.rs @@ -20,7 +20,7 @@ trait Message : Send { } fn object_ref_with_static_bound_not_ok() { assert_send::<&'static (Dummy+'static)>(); - //~^ ERROR the trait `core::marker::Send` is not implemented + //~^ ERROR the trait `core::marker::Sync` is not implemented } fn box_object_with_no_bound_not_ok<'a>() { @@ -28,7 +28,7 @@ fn box_object_with_no_bound_not_ok<'a>() { } fn object_with_send_bound_ok() { - assert_send::<&'static (Dummy+Send)>(); + assert_send::<&'static (Dummy+Sync)>(); assert_send::>(); } diff --git a/src/test/compile-fail/kindck-send-object1.rs b/src/test/compile-fail/kindck-send-object1.rs index 3d47d33d7c3..48d5215b708 100644 --- a/src/test/compile-fail/kindck-send-object1.rs +++ b/src/test/compile-fail/kindck-send-object1.rs @@ -12,22 +12,22 @@ // is broken into two parts because some errors occur in distinct // phases in the compiler. See kindck-send-object2.rs as well! -fn assert_send() { } +fn assert_send() { } trait Dummy { } // careful with object types, who knows what they close over... fn test51<'a>() { assert_send::<&'a Dummy>(); - //~^ ERROR the trait `core::marker::Send` is not implemented + //~^ ERROR the trait `core::marker::Sync` is not implemented } fn test52<'a>() { - assert_send::<&'a (Dummy+Send)>(); + assert_send::<&'a (Dummy+Sync)>(); //~^ ERROR does not fulfill the required lifetime } // ...unless they are properly bounded fn test60() { - assert_send::<&'static (Dummy+Send)>(); + assert_send::<&'static (Dummy+Sync)>(); } fn test61() { assert_send::>(); diff --git a/src/test/compile-fail/kindck-send-object2.rs b/src/test/compile-fail/kindck-send-object2.rs index 75bae09b37f..d3d166e2a69 100644 --- a/src/test/compile-fail/kindck-send-object2.rs +++ b/src/test/compile-fail/kindck-send-object2.rs @@ -14,7 +14,7 @@ fn assert_send() { } trait Dummy { } fn test50() { - assert_send::<&'static Dummy>(); //~ ERROR the trait `core::marker::Send` is not implemented + assert_send::<&'static Dummy>(); //~ ERROR the trait `core::marker::Sync` is not implemented } fn test53() { @@ -23,7 +23,7 @@ fn test53() { // ...unless they are properly bounded fn test60() { - assert_send::<&'static (Dummy+Send)>(); + assert_send::<&'static (Dummy+Sync)>(); } fn test61() { assert_send::>(); diff --git a/src/test/compile-fail/kindck-send-owned.rs b/src/test/compile-fail/kindck-send-owned.rs index 266b6156656..406711902a5 100644 --- a/src/test/compile-fail/kindck-send-owned.rs +++ b/src/test/compile-fail/kindck-send-owned.rs @@ -18,8 +18,8 @@ fn test31() { assert_send::(); } fn test32() { assert_send:: >(); } // but not if they own a bad thing -fn test40<'a>(_: &'a isize) { - assert_send::>(); //~ ERROR does not fulfill the required lifetime +fn test40() { + assert_send::>(); //~ ERROR `core::marker::Send` is not implemented } fn main() { } diff --git a/src/test/compile-fail/kindck-send-region-pointers.rs b/src/test/compile-fail/kindck-send-region-pointers.rs deleted file mode 100644 index e2a5b0678a6..00000000000 --- a/src/test/compile-fail/kindck-send-region-pointers.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that borrowed pointers are not sendable unless 'static. - -fn assert_send() { } - -// lifetime pointers with 'static lifetime are ok -fn test01() { assert_send::<&'static isize>(); } -fn test02() { assert_send::<&'static str>(); } -fn test03() { assert_send::<&'static [isize]>(); } - -// whether or not they are mutable -fn test10() { assert_send::<&'static mut isize>(); } - -// otherwise lifetime pointers are not ok -fn test20<'a>(_: &'a isize) { - assert_send::<&'a isize>(); //~ ERROR does not fulfill the required lifetime -} -fn test21<'a>(_: &'a isize) { - assert_send::<&'a str>(); //~ ERROR does not fulfill the required lifetime -} -fn test22<'a>(_: &'a isize) { - assert_send::<&'a [isize]>(); //~ ERROR does not fulfill the required lifetime -} - -fn main() { } diff --git a/src/test/compile-fail/regions-bounded-by-send.rs b/src/test/compile-fail/regions-bounded-by-send.rs deleted file mode 100644 index 71254e15d32..00000000000 --- a/src/test/compile-fail/regions-bounded-by-send.rs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2012 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test which of the builtin types are considered sendable. The tests -// in this file all test region bound and lifetime violations that are -// detected during type check. - -extern crate core; -use core::ptr::Unique; - -fn assert_send() { } -trait Dummy:Send { } - -// lifetime pointers with 'static lifetime are ok - -fn static_lifime_ok<'a,T,U:Send>(_: &'a isize) { - assert_send::<&'static isize>(); - assert_send::<&'static str>(); - assert_send::<&'static [isize]>(); - - // whether or not they are mutable - assert_send::<&'static mut isize>(); -} - -// otherwise lifetime pointers are not ok - -fn param_not_ok<'a>(x: &'a isize) { - assert_send::<&'a isize>(); //~ ERROR does not fulfill the required lifetime -} - -fn param_not_ok1<'a>(_: &'a isize) { - assert_send::<&'a str>(); //~ ERROR does not fulfill the required lifetime -} - -fn param_not_ok2<'a>(_: &'a isize) { - assert_send::<&'a [isize]>(); //~ ERROR does not fulfill the required lifetime -} - -// boxes are ok - -fn box_ok() { - assert_send::>(); - assert_send::(); - assert_send::>(); -} - -// but not if they own a bad thing - -fn box_with_region_not_ok<'a>() { - assert_send::>(); //~ ERROR does not fulfill the required lifetime -} - -// objects with insufficient bounds no ok - -fn object_with_random_bound_not_ok<'a>() { - assert_send::<&'a (Dummy+'a)>(); - //~^ ERROR reference has a longer lifetime -} - -fn object_with_send_bound_not_ok<'a>() { - assert_send::<&'a (Dummy+Send)>(); - //~^ ERROR does not fulfill the required lifetime -} - -// unsafe pointers are ok unless they point at unsendable things - -struct UniqueUnsafePtr(Unique<*const isize>); - -unsafe impl Send for UniqueUnsafePtr {} - -fn unsafe_ok1<'a>(_: &'a isize) { - assert_send::(); -} - -fn main() { -} diff --git a/src/test/compile-fail/regions-pattern-typing-issue-19552.rs b/src/test/compile-fail/regions-pattern-typing-issue-19552.rs index 57ea607cbf6..3401dd1becd 100644 --- a/src/test/compile-fail/regions-pattern-typing-issue-19552.rs +++ b/src/test/compile-fail/regions-pattern-typing-issue-19552.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn assert_send(_t: T) {} +fn assert_static(_t: T) {} fn main() { let line = String::new(); match [&*line] { //~ ERROR `line` does not live long enough - [ word ] => { assert_send(word); } + [ word ] => { assert_static(word); } } } diff --git a/src/test/compile-fail/trait-bounds-cant-coerce.rs b/src/test/compile-fail/trait-bounds-cant-coerce.rs index 89e89cf8246..79174552ae0 100644 --- a/src/test/compile-fail/trait-bounds-cant-coerce.rs +++ b/src/test/compile-fail/trait-bounds-cant-coerce.rs @@ -22,7 +22,7 @@ fn c(x: Box) { fn d(x: Box) { a(x); //~ ERROR mismatched types //~| expected `Box` - //~| found `Box` + //~| found `Box` //~| expected bounds `Send` //~| found no bounds } diff --git a/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs b/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs index 3df9dd25d86..379ac12a954 100644 --- a/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs +++ b/src/test/run-pass/builtin-superkinds-capabilities-transitive.rs @@ -22,7 +22,7 @@ trait Foo : Bar { } impl Foo for T { } impl Bar for T { } -fn foo(val: T, chan: Sender) { +fn foo(val: T, chan: Sender) { chan.send(val).unwrap(); } diff --git a/src/test/run-pass/builtin-superkinds-capabilities-xc.rs b/src/test/run-pass/builtin-superkinds-capabilities-xc.rs index 52b826393e9..cd019c21a3d 100644 --- a/src/test/run-pass/builtin-superkinds-capabilities-xc.rs +++ b/src/test/run-pass/builtin-superkinds-capabilities-xc.rs @@ -25,7 +25,7 @@ struct X(T); impl RequiresShare for X { } impl RequiresRequiresShareAndSend for X { } -fn foo(val: T, chan: Sender) { +fn foo(val: T, chan: Sender) { chan.send(val).unwrap(); } diff --git a/src/test/run-pass/builtin-superkinds-capabilities.rs b/src/test/run-pass/builtin-superkinds-capabilities.rs index 034e5ff2d3a..dc61508eec4 100644 --- a/src/test/run-pass/builtin-superkinds-capabilities.rs +++ b/src/test/run-pass/builtin-superkinds-capabilities.rs @@ -18,7 +18,7 @@ trait Foo : Send { } impl Foo for T { } -fn foo(val: T, chan: Sender) { +fn foo(val: T, chan: Sender) { chan.send(val).unwrap(); } diff --git a/src/test/run-pass/builtin-superkinds-self-type.rs b/src/test/run-pass/builtin-superkinds-self-type.rs index 1b3070ba3b0..1d05a7baa53 100644 --- a/src/test/run-pass/builtin-superkinds-self-type.rs +++ b/src/test/run-pass/builtin-superkinds-self-type.rs @@ -13,13 +13,13 @@ use std::sync::mpsc::{Sender, channel}; -trait Foo : Send + Sized { +trait Foo : Send + Sized + 'static { fn foo(self, tx: Sender) { tx.send(self).unwrap(); } } -impl Foo for T { } +impl Foo for T { } pub fn main() { let (tx, rx) = channel(); diff --git a/src/test/run-pass/issue-18188.rs b/src/test/run-pass/issue-18188.rs index 7a5a86822af..a4b09eb08e0 100644 --- a/src/test/run-pass/issue-18188.rs +++ b/src/test/run-pass/issue-18188.rs @@ -14,12 +14,12 @@ use std::thunk::Thunk; pub trait Promisable: Send + Sync {} impl Promisable for T {} -pub fn propagate(action: F) -> Thunk, Result> +pub fn propagate<'a, T, E, F, G>(action: F) -> Thunk<'a,Result, Result> where - T: Promisable + Clone, - E: Promisable + Clone, - F: FnOnce(&T) -> Result + Send, - G: FnOnce(Result) -> Result { + T: Promisable + Clone + 'a, + E: Promisable + Clone + 'a, + F: FnOnce(&T) -> Result + Send + 'a, + G: FnOnce(Result) -> Result + 'a { Thunk::with_arg(move |result: Result| { match result { Ok(ref t) => action(t), diff --git a/src/test/run-pass/issue-21058.rs b/src/test/run-pass/issue-21058.rs index 044d43a57fa..3cdd57aed5a 100644 --- a/src/test/run-pass/issue-21058.rs +++ b/src/test/run-pass/issue-21058.rs @@ -14,7 +14,7 @@ struct DST { a: u32, b: str } fn main() { // get_tydesc should support unsized types - assert!(unsafe {( + assert_eq!(unsafe {( // Slice (*std::intrinsics::get_tydesc::<[u8]>()).name, // str @@ -25,5 +25,5 @@ fn main() { (*std::intrinsics::get_tydesc::()).name, // DST (*std::intrinsics::get_tydesc::()).name - )} == ("[u8]", "str", "core::marker::Copy + 'static", "NT", "DST")); + )}, ("[u8]", "str", "core::marker::Copy", "NT", "DST")); } diff --git a/src/test/run-pass/issue-2190-1.rs b/src/test/run-pass/issue-2190-1.rs index 810bf385d7e..3025741694f 100644 --- a/src/test/run-pass/issue-2190-1.rs +++ b/src/test/run-pass/issue-2190-1.rs @@ -13,11 +13,11 @@ use std::thunk::Thunk; static generations: uint = 1024+256+128+49; -fn spawn(f: Thunk) { +fn spawn(f: Thunk<'static>) { Builder::new().stack_size(32 * 1024).spawn(move|| f.invoke(())); } -fn child_no(x: uint) -> Thunk { +fn child_no(x: uint) -> Thunk<'static> { Thunk::new(move|| { if x < generations { spawn(child_no(x+1)); diff --git a/src/test/run-pass/send-type-inference.rs b/src/test/run-pass/send-type-inference.rs index ae992a0a358..60093803f0b 100644 --- a/src/test/run-pass/send-type-inference.rs +++ b/src/test/run-pass/send-type-inference.rs @@ -16,7 +16,7 @@ struct Command { val: V } -fn cache_server(mut tx: Sender>>) { +fn cache_server(mut tx: Sender>>) { let (tx1, _rx) = channel(); tx.send(tx1); } -- cgit 1.4.1-3-g733a5 From 6ac3799b75780f8c18bc38331403e1e517b89bab Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 15:24:34 -0800 Subject: Test fixes and rebase conflicts --- src/doc/trpl/concurrency.md | 62 ++++++++-------------- src/libcore/cmp.rs | 9 ++-- src/libgetopts/lib.rs | 1 + src/librustc_driver/lib.rs | 5 +- src/librustc_trans/back/write.rs | 2 +- src/librustdoc/lib.rs | 12 +++-- src/libstd/sys/windows/thread.rs | 3 +- src/libstd/thread.rs | 36 ++++++------- src/libterm/lib.rs | 1 + src/libtest/lib.rs | 4 +- src/test/compile-fail/issue-8460-const.rs | 40 +++++++------- src/test/compile-fail/lint-uppercase-variables.rs | 4 +- src/test/run-fail/panic-task-name-none.rs | 3 +- src/test/run-fail/panic-task-name-owned.rs | 8 +-- .../cleanup-rvalue-temp-during-incomplete-alloc.rs | 4 +- src/test/run-pass/issue-12684.rs | 4 +- src/test/run-pass/issue-16560.rs | 4 +- src/test/run-pass/issue-16671.rs | 4 +- src/test/run-pass/issue-4446.rs | 4 +- src/test/run-pass/issue-4448.rs | 4 +- src/test/run-pass/issue-8460.rs | 42 +++++++-------- src/test/run-pass/logging-only-prints-once.rs | 4 +- src/test/run-pass/no-landing-pads.rs | 4 +- src/test/run-pass/panic-in-dtor-drops-fields.rs | 4 +- src/test/run-pass/sendfn-spawn-with-fn-arg.rs | 4 +- src/test/run-pass/sepcomp-unwind.rs | 4 +- src/test/run-pass/slice-panic-1.rs | 4 +- src/test/run-pass/slice-panic-2.rs | 4 +- src/test/run-pass/spawn-types.rs | 4 +- src/test/run-pass/spawn.rs | 4 +- src/test/run-pass/spawn2.rs | 4 +- src/test/run-pass/task-stderr.rs | 5 +- src/test/run-pass/tempfile.rs | 16 +++--- src/test/run-pass/terminate-in-initializer.rs | 6 +-- 34 files changed, 155 insertions(+), 168 deletions(-) (limited to 'src/libstd') diff --git a/src/doc/trpl/concurrency.md b/src/doc/trpl/concurrency.md index 3c933c1c5af..9f8f76e1fea 100644 --- a/src/doc/trpl/concurrency.md +++ b/src/doc/trpl/concurrency.md @@ -57,13 +57,13 @@ place! ## Threads Rust's standard library provides a library for 'threads', which allow you to -run Rust code in parallel. Here's a basic example of using `Thread`: +run Rust code in parallel. Here's a basic example of using `std::thread`: ``` -use std::thread::Thread; +use std::thread; fn main() { - Thread::scoped(|| { + thread::scoped(|| { println!("Hello from a thread!"); }); } @@ -73,10 +73,10 @@ The `Thread::scoped()` method accepts a closure, which is executed in a new thread. It's called `scoped` because this thread returns a join guard: ``` -use std::thread::Thread; +use std::thread; fn main() { - let guard = Thread::scoped(|| { + let guard = thread::scoped(|| { println!("Hello from a thread!"); }); @@ -85,15 +85,15 @@ fn main() { ``` When `guard` goes out of scope, it will block execution until the thread is -finished. If we didn't want this behaviour, we could use `Thread::spawn()`: +finished. If we didn't want this behaviour, we could use `thread::spawn()`: ``` -use std::thread::Thread; +use std::thread; use std::old_io::timer; use std::time::Duration; fn main() { - Thread::spawn(|| { + thread::spawn(|| { println!("Hello from a thread!"); }); @@ -101,24 +101,6 @@ fn main() { } ``` -Or call `.detach()`: - -``` -use std::thread::Thread; -use std::old_io::timer; -use std::time::Duration; - -fn main() { - let guard = Thread::scoped(|| { - println!("Hello from a thread!"); - }); - - guard.detach(); - - timer::sleep(Duration::milliseconds(50)); -} -``` - We need to `sleep` here because when `main()` ends, it kills all of the running threads. @@ -164,7 +146,7 @@ As an example, here is a Rust program that would have a data race in many languages. It will not compile: ```ignore -use std::thread::Thread; +use std::thread; use std::old_io::timer; use std::time::Duration; @@ -172,7 +154,7 @@ fn main() { let mut data = vec![1u32, 2, 3]; for i in 0..2 { - Thread::spawn(move || { + thread::spawn(move || { data[i] += 1; }); } @@ -203,7 +185,7 @@ only one person at a time can mutate what's inside. For that, we can use the but for a different reason: ```ignore -use std::thread::Thread; +use std::thread; use std::old_io::timer; use std::time::Duration; use std::sync::Mutex; @@ -213,7 +195,7 @@ fn main() { for i in 0..2 { let data = data.lock().unwrap(); - Thread::spawn(move || { + thread::spawn(move || { data[i] += 1; }); } @@ -255,7 +237,7 @@ We can use `Arc` to fix this. Here's the working version: ``` use std::sync::{Arc, Mutex}; -use std::thread::Thread; +use std::thread; use std::old_io::timer; use std::time::Duration; @@ -264,7 +246,7 @@ fn main() { for i in 0us..2 { let data = data.clone(); - Thread::spawn(move || { + thread::spawn(move || { let mut data = data.lock().unwrap(); data[i] += 1; }); @@ -280,14 +262,14 @@ thread more closely: ``` # use std::sync::{Arc, Mutex}; -# use std::thread::Thread; +# use std::thread; # use std::old_io::timer; # use std::time::Duration; # fn main() { # let data = Arc::new(Mutex::new(vec![1u32, 2, 3])); # for i in 0us..2 { # let data = data.clone(); -Thread::spawn(move || { +thread::spawn(move || { let mut data = data.lock().unwrap(); data[i] += 1; }); @@ -315,7 +297,7 @@ than waiting for a specific time: ``` use std::sync::{Arc, Mutex}; -use std::thread::Thread; +use std::thread; use std::sync::mpsc; fn main() { @@ -326,7 +308,7 @@ fn main() { for _ in 0..10 { let (data, tx) = (data.clone(), tx.clone()); - Thread::spawn(move || { + thread::spawn(move || { let mut data = data.lock().unwrap(); *data += 1; @@ -348,7 +330,7 @@ is `Send` over the channel! ``` use std::sync::{Arc, Mutex}; -use std::thread::Thread; +use std::thread; use std::sync::mpsc; fn main() { @@ -357,7 +339,7 @@ fn main() { for _ in 0..10 { let tx = tx.clone(); - Thread::spawn(move || { + thread::spawn(move || { let answer = 42u32; tx.send(answer); @@ -378,9 +360,9 @@ A `panic!` will crash the currently executing thread. You can use Rust's threads as a simple isolation mechanism: ``` -use std::thread::Thread; +use std::thread; -let result = Thread::scoped(move || { +let result = thread::spawn(move || { panic!("oops!"); }).join(); diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 5bc634936cf..19ec245300d 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -87,8 +87,8 @@ pub trait PartialEq { /// - symmetric: `a == b` implies `b == a`; and /// - transitive: `a == b` and `b == c` implies `a == c`. /// -/// This property cannot be checked by the compiler, and therefore `Eq` implies `PartialEq`, and -/// has no extra methods. +/// This property cannot be checked by the compiler, and therefore `Eq` implies +/// `PartialEq`, and has no extra methods. #[stable(feature = "rust1", since = "1.0.0")] pub trait Eq: PartialEq { // FIXME #13101: this method is used solely by #[deriving] to @@ -100,6 +100,7 @@ pub trait Eq: PartialEq { // This should never be implemented by hand. #[doc(hidden)] #[inline(always)] + #[stable(feature = "rust1", since = "1.0.0")] fn assert_receiver_is_total_eq(&self) {} } @@ -408,7 +409,7 @@ pub fn max(v1: T, v2: T) -> T { /// ``` /// use std::cmp; /// -/// let result = cmp::partial_min(std::f64::NAN, &1.0); +/// let result = cmp::partial_min(std::f64::NAN, 1.0); /// assert_eq!(result, None); /// ``` #[inline] @@ -439,7 +440,7 @@ pub fn partial_min(v1: T, v2: T) -> Option { /// ``` /// use std::cmp; /// -/// let result = cmp::partial_max(std::f64::NAN, &1.0); +/// let result = cmp::partial_max(std::f64::NAN, 1.0); /// assert_eq!(result, None); /// ``` #[inline] diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index ca184fb8736..c743119f409 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -92,6 +92,7 @@ #![feature(collections)] #![feature(int_uint)] #![feature(staged_api)] +#![feature(str_words)] #![cfg_attr(test, feature(rustc_private))] #[cfg(test)] #[macro_use] extern crate log; diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 19a290282d6..234809e5284 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -37,7 +37,6 @@ #![feature(rustc_private)] #![feature(unsafe_destructor)] #![feature(staged_api)] -#![feature(std_misc)] #![feature(unicode)] extern crate arena; @@ -73,7 +72,7 @@ use rustc::metadata; use rustc::util::common::time; use std::cmp::Ordering::Equal; -use std::old_io; +use std::old_io::{self, stdio}; use std::iter::repeat; use std::env; use std::sync::mpsc::channel; @@ -780,7 +779,7 @@ pub fn monitor(f: F) { cfg = cfg.stack_size(STACK_SIZE); } - match cfg.scoped(move || { std::old_io::stdio::set_stderr(box w); f() }).join() { + match cfg.spawn(move || { stdio::set_stderr(box w); f() }).unwrap().join() { Ok(()) => { /* fallthrough */ } Err(value) => { // Thread panicked without emitting a fatal diagnostic diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 68f413eff85..9934d9993d6 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -939,7 +939,7 @@ fn run_work_multithreaded(sess: &Session, } tx.take().unwrap().send(()).unwrap(); - }); + }).unwrap(); } let mut panicked = false; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e2799eec90a..bab734db126 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -34,6 +34,7 @@ #![feature(std_misc)] #![feature(test)] #![feature(unicode)] +#![feature(str_words)] extern crate arena; extern crate getopts; @@ -55,6 +56,7 @@ use std::env; use std::old_io::File; use std::old_io; use std::rc::Rc; +use std::sync::mpsc::channel; use externalfiles::ExternalHtml; use serialize::Decodable; use serialize::json::{self, Json}; @@ -125,8 +127,8 @@ pub fn main() { let res = std::thread::Builder::new().stack_size(STACK_SIZE).scoped(move || { let s = env::args().collect::>(); main_args(&s) - }).join(); - env::set_exit_status(res.ok().unwrap() as i32); + }).unwrap().join(); + env::set_exit_status(res as i32); } pub fn opts() -> Vec { @@ -365,12 +367,14 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche let cr = Path::new(cratefile); info!("starting to run rustc"); - let (mut krate, analysis) = std::thread::spawn(move || { + let (tx, rx) = channel(); + std::thread::spawn(move || { use rustc::session::config::Input; let cr = cr; - core::run_core(paths, cfgs, externs, Input::File(cr), triple) + tx.send(core::run_core(paths, cfgs, externs, Input::File(cr), triple)).unwrap(); }).join().map_err(|_| "rustc failed").unwrap(); + let (mut krate, analysis) = rx.recv().unwrap(); info!("finished with rustc"); let mut analysis = Some(analysis); ANALYSISKEY.with(|s| { diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index d7f86e1842e..f3a27877e5c 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use boxed::Box; +use prelude::v1::*; + use cmp; use io; use mem; diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index d0fde8344b2..a8355c34000 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -147,21 +147,16 @@ #![stable(feature = "rust1", since = "1.0.0")] +use prelude::v1::*; + use any::Any; -use boxed::Box; use cell::UnsafeCell; -use clone::Clone; use fmt; use io; -use marker::{Send, Sync}; -use ops::{Drop, FnOnce}; -use option::Option::{self, Some, None}; -use result::Result::{Err, Ok}; -use sync::{Mutex, Condvar, Arc}; -use str::Str; -use string::String; +use marker; +use old_io::stdio; use rt::{self, unwind}; -use old_io::{Writer, stdio}; +use sync::{Mutex, Condvar, Arc}; use thunk::Thunk; use time::Duration; @@ -264,7 +259,9 @@ impl Builder { pub fn scoped<'a, T, F>(self, f: F) -> io::Result> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { - self.spawn_inner(Thunk::new(f)).map(JoinGuard) + self.spawn_inner(Thunk::new(f)).map(|inner| { + JoinGuard { inner: inner, _marker: marker::PhantomData } + }) } fn spawn_inner(self, f: Thunk<(), T>) -> io::Result> { @@ -643,7 +640,10 @@ impl Drop for JoinHandle { /// permission. #[must_use] #[stable(feature = "rust1", since = "1.0.0")] -pub struct JoinGuard<'a, T: 'a>(JoinInner); +pub struct JoinGuard<'a, T: 'a> { + inner: JoinInner, + _marker: marker::PhantomData<&'a T>, +} #[stable(feature = "rust1", since = "1.0.0")] unsafe impl<'a, T: Send + 'a> Sync for JoinGuard<'a, T> {} @@ -652,7 +652,7 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> { /// Extract a handle to the thread this guard will join on. #[stable(feature = "rust1", since = "1.0.0")] pub fn thread(&self) -> &Thread { - &self.0.thread + &self.inner.thread } /// Wait for the associated thread to finish, returning the result of the thread's @@ -663,7 +663,7 @@ impl<'a, T: Send + 'a> JoinGuard<'a, T> { /// Panics on the child thread are propagated by panicking the parent. #[stable(feature = "rust1", since = "1.0.0")] pub fn join(mut self) -> T { - match self.0.join() { + match self.inner.join() { Ok(res) => res, Err(_) => panic!("child thread {:?} panicked", self.thread()), } @@ -676,8 +676,8 @@ impl JoinGuard<'static, T> { #[deprecated(since = "1.0.0", reason = "use spawn instead")] #[unstable(feature = "std_misc")] pub fn detach(mut self) { - unsafe { imp::detach(self.0.native) }; - self.0.joined = true; // avoid joining in the destructor + unsafe { imp::detach(self.inner.native) }; + self.inner.joined = true; // avoid joining in the destructor } } @@ -685,8 +685,8 @@ impl JoinGuard<'static, T> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> { fn drop(&mut self) { - if !self.0.joined { - unsafe { imp::join(self.0.native) }; + if !self.inner.joined { + unsafe { imp::join(self.inner.native) }; } } } diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 6cd96769ed2..304f370a199 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -59,6 +59,7 @@ #![feature(rustc_private)] #![feature(staged_api)] #![feature(unicode)] +#![feature(std_misc)] #![feature(env)] #![cfg_attr(windows, feature(libc))] diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 32ba410224e..62bf95d3b7b 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -75,7 +75,7 @@ use std::iter::repeat; use std::num::{Float, Int}; use std::env; use std::sync::mpsc::{channel, Sender}; -use std::thread::{self, Thread}; +use std::thread; use std::thunk::{Thunk, Invoke}; use std::time::Duration; @@ -895,7 +895,7 @@ pub fn run_test(opts: &TestOpts, cfg = cfg.stderr(box stderr as Box); } - let result_guard = cfg.scoped(move || { testfn.invoke(()) }); + let result_guard = cfg.spawn(move || { testfn.invoke(()) }).unwrap(); let stdout = reader.read_to_end().unwrap().into_iter().collect(); let test_result = calc_result(&desc, result_guard.join()); monitor_ch.send((desc.clone(), test_result, stdout)).unwrap(); diff --git a/src/test/compile-fail/issue-8460-const.rs b/src/test/compile-fail/issue-8460-const.rs index 4e44b4dcdce..b6d371e4b11 100644 --- a/src/test/compile-fail/issue-8460-const.rs +++ b/src/test/compile-fail/issue-8460-const.rs @@ -12,44 +12,44 @@ use std::{int, i8, i16, i32, i64}; use std::thread; fn main() { - assert!(thread::spawn(move|| int::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| { int::MIN / -1; }).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(thread::spawn(move|| i8::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| { i8::MIN / -1; }).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(thread::spawn(move|| i16::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| { i16::MIN / -1; }).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(thread::spawn(move|| i32::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| { i32::MIN / -1; }).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(thread::spawn(move|| i64::MIN / -1).join().is_err()); + assert!(thread::spawn(move|| { i64::MIN / -1; }).join().is_err()); //~^ ERROR attempted to divide with overflow in a constant expression - assert!(thread::spawn(move|| 1is / 0).join().is_err()); + assert!(thread::spawn(move|| { 1is / 0; }).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(thread::spawn(move|| 1i8 / 0).join().is_err()); + assert!(thread::spawn(move|| { 1i8 / 0; }).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(thread::spawn(move|| 1i16 / 0).join().is_err()); + assert!(thread::spawn(move|| { 1i16 / 0; }).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(thread::spawn(move|| 1i32 / 0).join().is_err()); + assert!(thread::spawn(move|| { 1i32 / 0; }).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(thread::spawn(move|| 1i64 / 0).join().is_err()); + assert!(thread::spawn(move|| { 1i64 / 0; }).join().is_err()); //~^ ERROR attempted to divide by zero in a constant expression - assert!(thread::spawn(move|| int::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| { int::MIN % -1; }).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(thread::spawn(move|| i8::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| { i8::MIN % -1; }).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(thread::spawn(move|| i16::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| { i16::MIN % -1; }).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(thread::spawn(move|| i32::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| { i32::MIN % -1; }).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(thread::spawn(move|| i64::MIN % -1).join().is_err()); + assert!(thread::spawn(move|| { i64::MIN % -1; }).join().is_err()); //~^ ERROR attempted remainder with overflow in a constant expression - assert!(thread::spawn(move|| 1is % 0).join().is_err()); + assert!(thread::spawn(move|| { 1is % 0; }).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(thread::spawn(move|| 1i8 % 0).join().is_err()); + assert!(thread::spawn(move|| { 1i8 % 0; }).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(thread::spawn(move|| 1i16 % 0).join().is_err()); + assert!(thread::spawn(move|| { 1i16 % 0; }).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(thread::spawn(move|| 1i32 % 0).join().is_err()); + assert!(thread::spawn(move|| { 1i32 % 0; }).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression - assert!(thread::spawn(move|| 1i64 % 0).join().is_err()); + assert!(thread::spawn(move|| { 1i64 % 0; }).join().is_err()); //~^ ERROR attempted remainder with a divisor of zero in a constant expression } diff --git a/src/test/compile-fail/lint-uppercase-variables.rs b/src/test/compile-fail/lint-uppercase-variables.rs index b68d9dc4645..a4f46cbd187 100644 --- a/src/test/compile-fail/lint-uppercase-variables.rs +++ b/src/test/compile-fail/lint-uppercase-variables.rs @@ -13,9 +13,6 @@ #![allow(dead_code)] #![deny(non_snake_case)] -use std::old_io::File; -use std::old_io::IoError; - mod foo { pub enum Foo { Foo } } @@ -36,6 +33,7 @@ fn main() { Foo => {} //~^ ERROR variable `Foo` should have a snake case name such as `foo` //~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo` +//~^^^ WARN unused variable: `Foo` } test(1); diff --git a/src/test/run-fail/panic-task-name-none.rs b/src/test/run-fail/panic-task-name-none.rs index 40a881852f5..3a5ac5a1009 100644 --- a/src/test/run-fail/panic-task-name-none.rs +++ b/src/test/run-fail/panic-task-name-none.rs @@ -13,9 +13,8 @@ use std::thread; fn main() { - let r: Result = thread::spawn(move|| { + let r: Result<(),_> = thread::spawn(move|| { panic!("test"); - 1 }).join(); assert!(r.is_ok()); } diff --git a/src/test/run-fail/panic-task-name-owned.rs b/src/test/run-fail/panic-task-name-owned.rs index d48d282c9eb..8cab9e05f96 100644 --- a/src/test/run-fail/panic-task-name-owned.rs +++ b/src/test/run-fail/panic-task-name-owned.rs @@ -13,9 +13,9 @@ use std::thread::Builder; fn main() { - let r: Result = Builder::new().name("owned name".to_string()).scoped(move|| { + let r: () = Builder::new().name("owned name".to_string()).scoped(move|| { panic!("test"); - 1 - }).join(); - assert!(r.is_ok()); + () + }).unwrap().join(); + panic!(); } diff --git a/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs b/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs index edb3d72483b..96ae7e3d336 100644 --- a/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs +++ b/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs @@ -27,7 +27,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; enum Conzabble { Bickwick(Foo) @@ -48,5 +48,5 @@ pub fn fails() { } pub fn main() { - Thread::scoped(fails).join(); + thread::spawn(fails).join(); } diff --git a/src/test/run-pass/issue-12684.rs b/src/test/run-pass/issue-12684.rs index 38731b8c8da..e66b5d21e17 100644 --- a/src/test/run-pass/issue-12684.rs +++ b/src/test/run-pass/issue-12684.rs @@ -9,10 +9,10 @@ // except according to those terms. use std::time::Duration; -use std::thread::Thread; +use std::thread; fn main() { - Thread::scoped(move|| customtask()).join().ok().unwrap(); + thread::spawn(move|| customtask()).join().ok().unwrap(); } fn customtask() { diff --git a/src/test/run-pass/issue-16560.rs b/src/test/run-pass/issue-16560.rs index ca40b2fe4c7..9448e605937 100644 --- a/src/test/run-pass/issue-16560.rs +++ b/src/test/run-pass/issue-16560.rs @@ -10,7 +10,7 @@ #![feature(unboxed_closures)] -use std::thread::Thread; +use std::thread; use std::mem; fn main() { @@ -20,7 +20,7 @@ fn main() { // Check that both closures are capturing by value assert_eq!(1, mem::size_of_val(&closure)); - Thread::scoped(move|| { + thread::spawn(move|| { let ok = closure; }).join().ok().unwrap(); } diff --git a/src/test/run-pass/issue-16671.rs b/src/test/run-pass/issue-16671.rs index 124b0205fae..0e42f2593f2 100644 --- a/src/test/run-pass/issue-16671.rs +++ b/src/test/run-pass/issue-16671.rs @@ -18,11 +18,11 @@ // A var moved into a proc, that has a mutable loan path should // not trigger a misleading unused_mut warning. -use std::thread::Thread; +use std::thread; pub fn main() { let mut stdin = std::old_io::stdin(); - Thread::spawn(move|| { + thread::spawn(move|| { let _ = stdin.read_to_end(); }); } diff --git a/src/test/run-pass/issue-4446.rs b/src/test/run-pass/issue-4446.rs index ec4cd02e9fd..b40a726a2c3 100644 --- a/src/test/run-pass/issue-4446.rs +++ b/src/test/run-pass/issue-4446.rs @@ -10,14 +10,14 @@ use std::old_io::println; use std::sync::mpsc::channel; -use std::thread::Thread; +use std::thread; pub fn main() { let (tx, rx) = channel(); tx.send("hello, world").unwrap(); - Thread::scoped(move|| { + thread::spawn(move|| { println(rx.recv().unwrap()); }).join().ok().unwrap(); } diff --git a/src/test/run-pass/issue-4448.rs b/src/test/run-pass/issue-4448.rs index a19bfca721a..ef30f9182ba 100644 --- a/src/test/run-pass/issue-4448.rs +++ b/src/test/run-pass/issue-4448.rs @@ -9,12 +9,12 @@ // except according to those terms. use std::sync::mpsc::channel; -use std::thread::Thread; +use std::thread; pub fn main() { let (tx, rx) = channel::<&'static str>(); - let t = Thread::scoped(move|| { + let t = thread::spawn(move|| { assert_eq!(rx.recv().unwrap(), "hello, world"); }); diff --git a/src/test/run-pass/issue-8460.rs b/src/test/run-pass/issue-8460.rs index 4b9ed44c7cd..72a1ec436f3 100644 --- a/src/test/run-pass/issue-8460.rs +++ b/src/test/run-pass/issue-8460.rs @@ -9,31 +9,31 @@ // except according to those terms. use std::num::Int; -use std::thread::Thread; +use std::thread; // Avoid using constants, which would trigger compile-time errors. fn min_val() -> T { Int::min_value() } fn zero() -> T { Int::zero() } fn main() { - assert!(Thread::scoped(move|| min_val::() / -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() / -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() / -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() / -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() / -1).join().is_err()); - assert!(Thread::scoped(move|| 1is / zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i8 / zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i16 / zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i32 / zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i64 / zero()).join().is_err()); - assert!(Thread::scoped(move|| min_val::() % -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() % -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() % -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() % -1).join().is_err()); - assert!(Thread::scoped(move|| min_val::() % -1).join().is_err()); - assert!(Thread::scoped(move|| 1is % zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i8 % zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i16 % zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i32 % zero()).join().is_err()); - assert!(Thread::scoped(move|| 1i64 % zero()).join().is_err()); + assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); + assert!(thread::spawn(move|| { 1is / zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i8 / zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i16 / zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i32 / zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i64 / zero(); }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); + assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); + assert!(thread::spawn(move|| { 1is % zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i8 % zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i16 % zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i32 % zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i64 % zero(); }).join().is_err()); } diff --git a/src/test/run-pass/logging-only-prints-once.rs b/src/test/run-pass/logging-only-prints-once.rs index 644efe20ded..b03c4b5ff47 100644 --- a/src/test/run-pass/logging-only-prints-once.rs +++ b/src/test/run-pass/logging-only-prints-once.rs @@ -13,7 +13,7 @@ use std::cell::Cell; use std::fmt; -use std::thread::Thread; +use std::thread; struct Foo(Cell); @@ -27,7 +27,7 @@ impl fmt::Debug for Foo { } pub fn main() { - Thread::scoped(move|| { + thread::spawn(move|| { let mut f = Foo(Cell::new(0)); println!("{:?}", f); let Foo(ref mut f) = f; diff --git a/src/test/run-pass/no-landing-pads.rs b/src/test/run-pass/no-landing-pads.rs index c90c6ce87f0..5ce32e4fe2c 100644 --- a/src/test/run-pass/no-landing-pads.rs +++ b/src/test/run-pass/no-landing-pads.rs @@ -10,7 +10,7 @@ // compile-flags: -Z no-landing-pads -use std::thread::Thread; +use std::thread; static mut HIT: bool = false; @@ -23,7 +23,7 @@ impl Drop for A { } fn main() { - Thread::scoped(move|| -> () { + thread::spawn(move|| -> () { let _a = A; panic!(); }).join().err().unwrap(); diff --git a/src/test/run-pass/panic-in-dtor-drops-fields.rs b/src/test/run-pass/panic-in-dtor-drops-fields.rs index 3cc01b967ce..6da15b97aca 100644 --- a/src/test/run-pass/panic-in-dtor-drops-fields.rs +++ b/src/test/run-pass/panic-in-dtor-drops-fields.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; static mut dropped: bool = false; @@ -33,7 +33,7 @@ impl Drop for B { } pub fn main() { - let ret = Thread::scoped(move|| { + let ret = thread::spawn(move|| { let _a = A { b: B { foo: 3 } }; }).join(); assert!(ret.is_err()); diff --git a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs index 6c9707103b9..523b7528103 100644 --- a/src/test/run-pass/sendfn-spawn-with-fn-arg.rs +++ b/src/test/run-pass/sendfn-spawn-with-fn-arg.rs @@ -11,7 +11,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; pub fn main() { test05(); } @@ -25,7 +25,7 @@ fn test05() { println!("{}", *three + n); // will copy x into the closure assert_eq!(*three, 3); }; - Thread::scoped(move|| { + thread::spawn(move|| { test05_start(fn_to_send); }).join().ok().unwrap(); } diff --git a/src/test/run-pass/sepcomp-unwind.rs b/src/test/run-pass/sepcomp-unwind.rs index f68dea04a08..21c5a6fc83a 100644 --- a/src/test/run-pass/sepcomp-unwind.rs +++ b/src/test/run-pass/sepcomp-unwind.rs @@ -19,7 +19,7 @@ // In any case, this test should let us know if enabling parallel codegen ever // breaks unwinding. -use std::thread::Thread; +use std::thread; fn pad() -> uint { 0 } @@ -36,5 +36,5 @@ mod b { } fn main() { - Thread::scoped(move|| { ::b::g() }).join().err().unwrap(); + thread::spawn(move|| { ::b::g() }).join().err().unwrap(); } diff --git a/src/test/run-pass/slice-panic-1.rs b/src/test/run-pass/slice-panic-1.rs index b2e3d83ca9b..639ffd56002 100644 --- a/src/test/run-pass/slice-panic-1.rs +++ b/src/test/run-pass/slice-panic-1.rs @@ -10,7 +10,7 @@ // Test that if a slicing expr[..] fails, the correct cleanups happen. -use std::thread::Thread; +use std::thread; struct Foo; @@ -26,6 +26,6 @@ fn foo() { } fn main() { - let _ = Thread::scoped(move|| foo()).join(); + let _ = thread::spawn(move|| foo()).join(); unsafe { assert!(DTOR_COUNT == 2); } } diff --git a/src/test/run-pass/slice-panic-2.rs b/src/test/run-pass/slice-panic-2.rs index dea45e63ab0..4a2038175d2 100644 --- a/src/test/run-pass/slice-panic-2.rs +++ b/src/test/run-pass/slice-panic-2.rs @@ -10,7 +10,7 @@ // Test that if a slicing expr[..] fails, the correct cleanups happen. -use std::thread::Thread; +use std::thread; struct Foo; @@ -30,6 +30,6 @@ fn foo() { } fn main() { - let _ = Thread::scoped(move|| foo()).join(); + let _ = thread::spawn(move|| foo()).join(); unsafe { assert!(DTOR_COUNT == 2); } } diff --git a/src/test/run-pass/spawn-types.rs b/src/test/run-pass/spawn-types.rs index eaad2abe8f7..bf2f03b3e6d 100644 --- a/src/test/run-pass/spawn-types.rs +++ b/src/test/run-pass/spawn-types.rs @@ -14,7 +14,7 @@ Arnold. */ -use std::thread::Thread; +use std::thread; use std::sync::mpsc::{channel, Sender}; type ctx = Sender; @@ -25,6 +25,6 @@ fn iotask(_tx: &ctx, ip: String) { pub fn main() { let (tx, _rx) = channel::(); - let t = Thread::scoped(move|| iotask(&tx, "localhost".to_string()) ); + let t = thread::spawn(move|| iotask(&tx, "localhost".to_string()) ); t.join().ok().unwrap(); } diff --git a/src/test/run-pass/spawn.rs b/src/test/run-pass/spawn.rs index 8f937afa6b9..90b47f4986b 100644 --- a/src/test/run-pass/spawn.rs +++ b/src/test/run-pass/spawn.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { - Thread::scoped(move|| child(10)).join().ok().unwrap(); + thread::spawn(move|| child(10)).join().ok().unwrap(); } fn child(i: int) { println!("{}", i); assert!((i == 10)); } diff --git a/src/test/run-pass/spawn2.rs b/src/test/run-pass/spawn2.rs index 75104a4ddef..91edb5fd9c1 100644 --- a/src/test/run-pass/spawn2.rs +++ b/src/test/run-pass/spawn2.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::thread::Thread; +use std::thread; pub fn main() { - let t = Thread::scoped(move|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); + let t = thread::spawn(move|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); t.join().ok().unwrap(); } diff --git a/src/test/run-pass/task-stderr.rs b/src/test/run-pass/task-stderr.rs index 5994b24dfdc..1c263b19dd1 100644 --- a/src/test/run-pass/task-stderr.rs +++ b/src/test/run-pass/task-stderr.rs @@ -20,9 +20,10 @@ fn main() { let mut reader = ChanReader::new(rx); let stderr = ChanWriter::new(tx); - let res = thread::Builder::new().stderr(box stderr as Box).scoped(move|| -> () { + let res = thread::Builder::new().stderr(box stderr as Box) + .spawn(move|| -> () { panic!("Hello, world!") - }).join(); + }).unwrap().join(); assert!(res.is_err()); let output = reader.read_to_string().unwrap(); diff --git a/src/test/run-pass/tempfile.rs b/src/test/run-pass/tempfile.rs index 4df1ff14810..053df3a57f3 100644 --- a/src/test/run-pass/tempfile.rs +++ b/src/test/run-pass/tempfile.rs @@ -23,7 +23,7 @@ use std::old_io::{fs, TempDir}; use std::old_io; use std::os; use std::sync::mpsc::channel; -use std::thread::Thread; +use std::thread; fn test_tempdir() { let path = { @@ -42,7 +42,7 @@ fn test_rm_tempdir() { tx.send(tmp.path().clone()).unwrap(); panic!("panic to unwind past `tmp`"); }; - let _ = Thread::scoped(f).join(); + thread::spawn(f).join(); let path = rx.recv().unwrap(); assert!(!path.exists()); @@ -52,7 +52,7 @@ fn test_rm_tempdir() { let _tmp = tmp; panic!("panic to unwind past `tmp`"); }; - let _ = Thread::scoped(f).join(); + thread::spawn(f).join(); assert!(!path.exists()); let path; @@ -61,7 +61,7 @@ fn test_rm_tempdir() { TempDir::new("test_rm_tempdir").unwrap() }; // FIXME(#16640) `: TempDir` annotation shouldn't be necessary - let tmp: TempDir = Thread::scoped(f).join().ok().expect("test_rm_tmdir"); + let tmp: TempDir = thread::scoped(f).join(); path = tmp.path().clone(); assert!(path.exists()); } @@ -85,7 +85,7 @@ fn test_rm_tempdir_close() { tmp.close(); panic!("panic when unwinding past `tmp`"); }; - let _ = Thread::scoped(f).join(); + thread::spawn(f).join(); let path = rx.recv().unwrap(); assert!(!path.exists()); @@ -96,7 +96,7 @@ fn test_rm_tempdir_close() { tmp.close(); panic!("panic when unwinding past `tmp`"); }; - let _ = Thread::scoped(f).join(); + thread::spawn(f).join(); assert!(!path.exists()); let path; @@ -105,7 +105,7 @@ fn test_rm_tempdir_close() { TempDir::new("test_rm_tempdir").unwrap() }; // FIXME(#16640) `: TempDir` annotation shouldn't be necessary - let tmp: TempDir = Thread::scoped(f).join().ok().expect("test_rm_tmdir"); + let tmp: TempDir = thread::scoped(f).join(); path = tmp.path().clone(); assert!(path.exists()); tmp.close(); @@ -179,7 +179,7 @@ pub fn test_rmdir_recursive_ok() { } pub fn dont_double_panic() { - let r: Result<(), _> = Thread::scoped(move|| { + let r: Result<(), _> = thread::spawn(move|| { let tmpdir = TempDir::new("test").unwrap(); // Remove the temporary directory so that TempDir sees // an error on drop diff --git a/src/test/run-pass/terminate-in-initializer.rs b/src/test/run-pass/terminate-in-initializer.rs index 185edb02cca..bef9efa9eb6 100644 --- a/src/test/run-pass/terminate-in-initializer.rs +++ b/src/test/run-pass/terminate-in-initializer.rs @@ -12,7 +12,7 @@ // Issue #787 // Don't try to clean up uninitialized locals -use std::thread::Thread; +use std::thread; fn test_break() { loop { let _x: Box = break; } } @@ -22,13 +22,13 @@ fn test_ret() { let _x: Box = return; } fn test_panic() { fn f() { let _x: Box = panic!(); } - Thread::scoped(move|| f() ).join().err().unwrap(); + thread::spawn(move|| f() ).join().err().unwrap(); } fn test_panic_indirect() { fn f() -> ! { panic!(); } fn g() { let _x: Box = f(); } - Thread::scoped(move|| g() ).join().err().unwrap(); + thread::spawn(move|| g() ).join().err().unwrap(); } pub fn main() { -- cgit 1.4.1-3-g733a5 From 665ea963d3c29ef7670662707f2f2307f000efa3 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 19:00:20 -0800 Subject: Test fixes and rebase conflicts --- src/doc/trpl/traits.md | 2 +- src/libcollections/ring_buf.rs | 13 ++++++----- src/librustc_driver/lib.rs | 2 +- src/libstd/old_io/comm_adapters.rs | 5 +---- src/libstd/old_path/posix.rs | 2 +- src/libstd/old_path/windows.rs | 2 +- src/libstd/sync/rwlock.rs | 12 +++++------ src/libstd/thread.rs | 25 +++++++++++----------- src/libstd/thread_local/scoped.rs | 12 +++++------ src/test/bench/shootout-binarytrees.rs | 6 +++--- src/test/bench/shootout-fannkuch-redux.rs | 4 ++-- src/test/bench/shootout-k-nucleotide.rs | 8 +++---- src/test/bench/shootout-mandelbrot.rs | 8 +++---- .../send-is-not-static-ensures-scoping.rs | 7 +++--- src/test/pretty/attr-fn-inner.rs | 2 ++ src/test/run-make/static-unwinding/lib.rs | 2 +- src/test/run-make/static-unwinding/main.rs | 7 +++--- src/test/run-pass/drop-trait-enum.rs | 10 +++++---- 18 files changed, 65 insertions(+), 64 deletions(-) (limited to 'src/libstd') diff --git a/src/doc/trpl/traits.md b/src/doc/trpl/traits.md index 52ec012320a..abd9af1af33 100644 --- a/src/doc/trpl/traits.md +++ b/src/doc/trpl/traits.md @@ -343,7 +343,7 @@ trait ConvertTo { } impl ConvertTo for i32 { - fn convert(&self) -> i64 { *self as i32 } + fn convert(&self) -> i64 { *self as i64 } } // can be called with T == i32 diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index 5c3bd25438e..93218aed366 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! RingBuf is a double-ended queue, which is implemented with the help of a growing circular buffer. +//! RingBuf is a double-ended queue, which is implemented with the help of a +//! growing circular buffer. //! -//! This queue has `O(1)` amortized inserts and removals from both ends of the container. It also -//! has `O(1)` indexing like a vector. The contained elements are not required to be copyable, and -//! the queue will be sendable if the contained type is sendable. +//! This queue has `O(1)` amortized inserts and removals from both ends of the +//! container. It also has `O(1)` indexing like a vector. The contained elements +//! are not required to be copyable, and the queue will be sendable if the +//! contained type is sendable. #![stable(feature = "rust1", since = "1.0.0")] @@ -115,7 +117,8 @@ impl RingBuf { #[inline] fn is_full(&self) -> bool { self.cap - self.len() == 1 } - /// Returns the index in the underlying buffer for a given logical element index. + /// Returns the index in the underlying buffer for a given logical element + /// index. #[inline] fn wrap_index(&self, idx: usize) -> usize { wrap_index(idx, self.cap) } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 234809e5284..ac91a0098ea 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -764,7 +764,7 @@ fn parse_crate_attrs(sess: &Session, input: &Input) -> /// /// The diagnostic emitter yielded to the procedure should be used for reporting /// errors of the compiler. -pub fn monitor(f: F) { +pub fn monitor(f: F) { static STACK_SIZE: uint = 8 * 1024 * 1024; // 8MB let (tx, rx) = channel(); diff --git a/src/libstd/old_io/comm_adapters.rs b/src/libstd/old_io/comm_adapters.rs index a75686369ad..207d3d39167 100644 --- a/src/libstd/old_io/comm_adapters.rs +++ b/src/libstd/old_io/comm_adapters.rs @@ -234,10 +234,7 @@ mod test { writer.write_be_u32(42).unwrap(); let wanted = vec![0u8, 0u8, 0u8, 42u8]; - let got = match thread::spawn(move|| { rx.recv().unwrap() }).join() { - Ok(got) => got, - Err(_) => panic!(), - }; + let got = thread::scoped(move|| { rx.recv().unwrap() }).join(); assert_eq!(wanted, got); match writer.write_u8(1) { diff --git a/src/libstd/old_path/posix.rs b/src/libstd/old_path/posix.rs index 9bbce1934b0..440d17cfd50 100644 --- a/src/libstd/old_path/posix.rs +++ b/src/libstd/old_path/posix.rs @@ -520,7 +520,7 @@ mod tests { fn test_null_byte() { use thread; let result = thread::spawn(move|| { - Path::new(b"foo/bar\0") + Path::new(b"foo/bar\0"); }).join(); assert!(result.is_err()); diff --git a/src/libstd/old_path/windows.rs b/src/libstd/old_path/windows.rs index 8362e9a9530..07c5e10992b 100644 --- a/src/libstd/old_path/windows.rs +++ b/src/libstd/old_path/windows.rs @@ -1307,7 +1307,7 @@ mod tests { fn test_null_byte() { use thread; let result = thread::spawn(move|| { - Path::new(b"foo/bar\0") + Path::new(b"foo/bar\0"); }).join(); assert!(result.is_err()); diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 402542b8bdc..b8d157d341e 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -425,8 +425,8 @@ mod tests { #[test] fn frob() { static R: StaticRwLock = RW_LOCK_INIT; - static N: uint = 10; - static M: uint = 1000; + static N: usize = 10; + static M: usize = 1000; let (tx, rx) = channel::<()>(); for _ in 0..N { @@ -452,7 +452,7 @@ mod tests { fn test_rw_arc_poison_wr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move|| { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -464,7 +464,7 @@ mod tests { let arc = Arc::new(RwLock::new(1)); assert!(!arc.is_poisoned()); let arc2 = arc.clone(); - let _: Result = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move|| { let _lock = arc2.write().unwrap(); panic!(); }).join(); @@ -476,7 +476,7 @@ mod tests { fn test_rw_arc_no_poison_rr() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move|| { let _lock = arc2.read().unwrap(); panic!(); }).join(); @@ -487,7 +487,7 @@ mod tests { fn test_rw_arc_no_poison_rw() { let arc = Arc::new(RwLock::new(1)); let arc2 = arc.clone(); - let _: Result = thread::spawn(move|| { + let _: Result<(), _> = thread::spawn(move|| { let _lock = arc2.read().unwrap(); panic!() }).join(); diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index ea25ddc0fca..3137d779c40 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -260,7 +260,7 @@ impl Builder { T: Send + 'a, F: FnOnce() -> T, F: Send + 'a { self.spawn_inner(Thunk::new(f)).map(|inner| { - JoinGuard { inner: inner, _marker: marker::PhantomData } + JoinGuard { inner: inner, _marker: marker::CovariantType } }) } @@ -642,7 +642,7 @@ impl Drop for JoinHandle { #[stable(feature = "rust1", since = "1.0.0")] pub struct JoinGuard<'a, T: 'a> { inner: JoinInner, - _marker: marker::PhantomData<&'a T>, + _marker: marker::CovariantType<&'a T>, } #[stable(feature = "rust1", since = "1.0.0")] @@ -686,7 +686,9 @@ impl JoinGuard<'static, T> { impl<'a, T: Send + 'a> Drop for JoinGuard<'a, T> { fn drop(&mut self) { if !self.inner.joined { - unsafe { imp::join(self.inner.native) }; + if self.inner.join().is_err() { + panic!("child thread {:?} panicked", self.thread()); + } } } } @@ -700,7 +702,8 @@ mod test { use boxed::BoxAny; use result; use std::old_io::{ChanReader, ChanWriter}; - use super::{self, Thread, Builder}; + use super::{Thread, Builder}; + use thread; use thunk::Thunk; use time::Duration; @@ -718,7 +721,7 @@ mod test { fn test_named_thread() { Builder::new().name("ada lovelace".to_string()).scoped(move|| { assert!(thread::current().name().unwrap() == "ada lovelace".to_string()); - }).join().ok().unwrap(); + }).unwrap().join(); } #[test] @@ -732,12 +735,9 @@ mod test { #[test] fn test_join_success() { - match thread::spawn(move|| -> String { + assert!(thread::scoped(move|| -> String { "Success!".to_string() - }).join().as_ref().map(|s| &**s) { - result::Result::Ok("Success!") => (), - _ => panic!() - } + }).join() == "Success!"); } #[test] @@ -928,10 +928,9 @@ mod test { let mut reader = ChanReader::new(rx); let stdout = ChanWriter::new(tx); - let r = Builder::new().stdout(box stdout as Box).scoped(move|| { + Builder::new().stdout(box stdout as Box).scoped(move|| { print!("Hello, world!"); - }).join(); - assert!(r.is_ok()); + }).unwrap().join(); let output = reader.read_to_string().unwrap(); assert_eq!(output, "Hello, world!".to_string()); diff --git a/src/libstd/thread_local/scoped.rs b/src/libstd/thread_local/scoped.rs index e4633ea0f76..01220e7bc1f 100644 --- a/src/libstd/thread_local/scoped.rs +++ b/src/libstd/thread_local/scoped.rs @@ -84,7 +84,7 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")), thread_local)] - static $name: ::std::thread_local::spawn::Key<$t> = + static $name: ::std::thread_local::scoped::Key<$t> = __scoped_thread_local_inner!($t); ); (pub static $name:ident: $t:ty) => ( @@ -94,11 +94,11 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")), thread_local)] - pub static $name: ::std::thread_local::spawn::Key<$t> = + pub static $name: ::std::thread_local::scoped::Key<$t> = __scoped_thread_local_inner!($t); ); ($t:ty) => ({ - use std::thread_local::spawn::Key as __Key; + use std::thread_local::scoped::Key as __Key; #[cfg(not(any(windows, target_os = "android", @@ -106,7 +106,7 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64")))] const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::spawn::__impl::KeyInner { + inner: ::std::thread_local::scoped::__impl::KeyInner { inner: ::std::cell::UnsafeCell { value: 0 as *mut _ }, } }; @@ -117,8 +117,8 @@ macro_rules! __scoped_thread_local_inner { target_os = "openbsd", target_arch = "aarch64"))] const _INIT: __Key<$t> = __Key { - inner: ::std::thread_local::spawn::__impl::KeyInner { - inner: ::std::thread_local::spawn::__impl::OS_INIT, + inner: ::std::thread_local::scoped::__impl::KeyInner { + inner: ::std::thread_local::scoped::__impl::OS_INIT, marker: ::std::marker::InvariantType, } }; diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index dc0a2a6459f..1e23da3020f 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -41,7 +41,7 @@ extern crate arena; use std::iter::range_step; -use std::thread::{Thread, JoinGuard}; +use std::thread; use arena::TypedArena; struct Tree<'a> { @@ -110,11 +110,11 @@ fn main() { let messages = range_step(min_depth, max_depth + 1, 2).map(|depth| { use std::num::Int; let iterations = 2.pow((max_depth - depth + min_depth) as usize); - thread::spawn(move || inner(depth, iterations)) + thread::scoped(move || inner(depth, iterations)) }).collect::>(); for message in messages { - println!("{}", message.join().ok().unwrap()); + println!("{}", message.join()); } println!("long lived tree of depth {}\t check: {}", diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 8b840b16352..f7de935d08f 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -164,7 +164,7 @@ fn fannkuch(n: i32) -> (i32, i32) { for (_, j) in (0..N).zip(iter::count(0, k)) { let max = cmp::min(j+k, perm.max()); - futures.push(thread::spawn(move|| { + futures.push(thread::scoped(move|| { work(perm, j as uint, max as uint) })) } @@ -172,7 +172,7 @@ fn fannkuch(n: i32) -> (i32, i32) { let mut checksum = 0; let mut maxflips = 0; for fut in futures { - let (cs, mf) = fut.join().ok().unwrap(); + let (cs, mf) = fut.join(); checksum += cs; maxflips = cmp::max(maxflips, mf); } diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index e6beb952603..b5c460737b8 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -303,17 +303,17 @@ fn main() { let nb_freqs: Vec<_> = (1u..3).map(|i| { let input = input.clone(); - (i, thread::spawn(move|| generate_frequencies(&input, i))) + (i, thread::scoped(move|| generate_frequencies(&input, i))) }).collect(); let occ_freqs: Vec<_> = OCCURRENCES.iter().map(|&occ| { let input = input.clone(); - thread::spawn(move|| generate_frequencies(&input, occ.len())) + thread::scoped(move|| generate_frequencies(&input, occ.len())) }).collect(); for (i, freq) in nb_freqs { - print_frequencies(&freq.join().ok().unwrap(), i); + print_frequencies(&freq.join(), i); } for (&occ, freq) in OCCURRENCES.iter().zip(occ_freqs.into_iter()) { - print_occurrences(&mut freq.join().ok().unwrap(), occ); + print_occurrences(&mut freq.join(), occ); } } diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 8ab3b14a1f5..bddf6153228 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -81,7 +81,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let mut precalc_i = Vec::with_capacity(h); let precalc_futures = (0..WORKERS).map(|i| { - thread::spawn(move|| { + thread::scoped(move|| { let mut rs = Vec::with_capacity(w / WORKERS); let mut is = Vec::with_capacity(w / WORKERS); @@ -107,7 +107,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { }).collect::>(); for res in precalc_futures { - let (rs, is) = res.join().ok().unwrap(); + let (rs, is) = res.join(); precalc_r.extend(rs.into_iter()); precalc_i.extend(is.into_iter()); } @@ -122,7 +122,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { let vec_init_r = arc_init_r.clone(); let vec_init_i = arc_init_i.clone(); - thread::spawn(move|| { + thread::scoped(move|| { let mut res: Vec = Vec::with_capacity((chunk_size * w) / 8); let init_r_slice = vec_init_r; @@ -143,7 +143,7 @@ fn mandelbrot(w: usize, mut out: W) -> old_io::IoResult<()> { try!(writeln!(&mut out as &mut Writer, "P4\n{} {}", w, h)); for res in data { - try!(out.write(&res.join().ok().unwrap())); + try!(out.write(&res.join())); } out.flush() } diff --git a/src/test/compile-fail/send-is-not-static-ensures-scoping.rs b/src/test/compile-fail/send-is-not-static-ensures-scoping.rs index 0b74892d66c..abbcd7e4590 100755 --- a/src/test/compile-fail/send-is-not-static-ensures-scoping.rs +++ b/src/test/compile-fail/send-is-not-static-ensures-scoping.rs @@ -8,18 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(core, std_misc)] -use std::thread::Thread; +use std::thread; fn main() { let bad = { let x = 1; let y = &x; - Thread::scoped(|| { //~ ERROR cannot infer an appropriate lifetime + thread::scoped(|| { //~ ERROR cannot infer an appropriate lifetime let _z = y; }) }; - bad.join().ok().unwrap(); + bad.join(); } diff --git a/src/test/pretty/attr-fn-inner.rs b/src/test/pretty/attr-fn-inner.rs index 65dcf900567..79964d2a7ba 100644 --- a/src/test/pretty/attr-fn-inner.rs +++ b/src/test/pretty/attr-fn-inner.rs @@ -13,6 +13,8 @@ // preserved, and that the first outer item parsed in main is not // accidentally carried over to each inner function +#![feature(custom_attribute)] + fn main() { #![inner_attr] #[outer_attr] diff --git a/src/test/run-make/static-unwinding/lib.rs b/src/test/run-make/static-unwinding/lib.rs index c3fa1a68e16..12c72d54c09 100644 --- a/src/test/run-make/static-unwinding/lib.rs +++ b/src/test/run-make/static-unwinding/lib.rs @@ -10,7 +10,7 @@ #![crate_type = "rlib"] -pub static mut statik: int = 0; +pub static mut statik: isize = 0; struct A; impl Drop for A { diff --git a/src/test/run-make/static-unwinding/main.rs b/src/test/run-make/static-unwinding/main.rs index 6d10a247143..d325f54d365 100644 --- a/src/test/run-make/static-unwinding/main.rs +++ b/src/test/run-make/static-unwinding/main.rs @@ -10,9 +10,9 @@ extern crate lib; -use std::thread::Thread; +use std::thread; -static mut statik: int = 0; +static mut statik: isize = 0; struct A; impl Drop for A { @@ -22,10 +22,9 @@ impl Drop for A { } fn main() { - Thread::scoped(move|| { + thread::spawn(move|| { let _a = A; lib::callback(|| panic!()); - 1 }).join().err().unwrap(); unsafe { diff --git a/src/test/run-pass/drop-trait-enum.rs b/src/test/run-pass/drop-trait-enum.rs index 2474bb8a4f3..d52c645730f 100644 --- a/src/test/run-pass/drop-trait-enum.rs +++ b/src/test/run-pass/drop-trait-enum.rs @@ -11,7 +11,7 @@ #![allow(unknown_features)] #![feature(box_syntax)] -use std::thread::Thread; +use std::thread; use std::sync::mpsc::{channel, Sender}; #[derive(PartialEq, Debug)] @@ -69,15 +69,16 @@ pub fn main() { assert_eq!(receiver.recv().ok(), None); let (sender, receiver) = channel(); - let _t = Thread::scoped(move|| { + let t = thread::spawn(move|| { let v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } }; }); assert_eq!(receiver.recv().unwrap(), Message::Dropped); assert_eq!(receiver.recv().ok(), None); + drop(t.join()); let (sender, receiver) = channel(); - let _t = { - Thread::scoped(move|| { + let t = { + thread::spawn(move|| { let mut v = Foo::NestedVariant(box 42u, SendOnDrop { sender: sender.clone() }, sender.clone()); @@ -93,4 +94,5 @@ pub fn main() { assert_eq!(receiver.recv().unwrap(), Message::DestructorRan); assert_eq!(receiver.recv().unwrap(), Message::Dropped); assert_eq!(receiver.recv().ok(), None); + drop(t.join()); } -- cgit 1.4.1-3-g733a5 From 47f91a9484eceef10536d4caac6ef578cd254567 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Feb 2015 19:49:22 -0800 Subject: Register new snapshots --- src/liballoc/lib.rs | 8 ----- src/liballoc/rc.rs | 8 ++--- src/libcollections/binary_heap.rs | 22 -------------- src/libcollections/bit.rs | 22 -------------- src/libcollections/btree/map.rs | 33 -------------------- src/libcollections/btree/set.rs | 22 -------------- src/libcollections/dlist.rs | 33 -------------------- src/libcollections/enum_set.rs | 11 ------- src/libcollections/lib.rs | 9 ------ src/libcollections/ring_buf.rs | 33 -------------------- src/libcollections/vec.rs | 33 -------------------- src/libcollections/vec_map.rs | 33 -------------------- src/libcore/array.rs | 22 -------------- src/libcore/cell.rs | 3 +- src/libcore/iter.rs | 23 -------------- src/libcore/lib.rs | 21 ++++--------- src/libcore/marker.rs | 4 +-- src/libcore/slice.rs | 22 -------------- src/liblibc/lib.rs | 7 ----- src/librand/lib.rs | 11 ------- src/librustc/middle/subst.rs | 22 -------------- src/librustc/middle/ty.rs | 36 ---------------------- src/libstd/collections/hash/map.rs | 45 ---------------------------- src/libstd/collections/hash/set.rs | 30 ------------------- src/libstd/lib.rs | 10 ------- src/libstd/macros.rs | 17 ----------- src/libstd/thunk.rs | 2 +- src/libunicode/lib.rs | 13 -------- src/snapshots.txt | 9 ++++++ src/test/run-pass/foreign-call-no-runtime.rs | 8 ++--- 30 files changed, 25 insertions(+), 547 deletions(-) (limited to 'src/libstd') diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 87106041c69..b3c2638f3ae 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -126,11 +126,3 @@ pub fn oom() -> ! { // optimize it out). #[doc(hidden)] pub fn fixme_14344_be_sure_to_link_to_collections() {} - -// NOTE: remove after next snapshot -#[cfg(all(stage0, not(test)))] -#[doc(hidden)] -mod std { - pub use core::fmt; - pub use core::option; -} diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index fb73521af56..f361c36ec8f 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -776,9 +776,7 @@ impl RcBoxPtr for Rc { // the contract anyway. // This allows the null check to be elided in the destructor if we // manipulated the reference count in the same function. - if cfg!(not(stage0)) { // NOTE remove cfg after next snapshot - assume(!self._ptr.is_null()); - } + assume(!self._ptr.is_null()); &(**self._ptr) } } @@ -792,9 +790,7 @@ impl RcBoxPtr for Weak { // the contract anyway. // This allows the null check to be elided in the destructor if we // manipulated the reference count in the same function. - if cfg!(not(stage0)) { // NOTE remove cfg after next snapshot - assume(!self._ptr.is_null()); - } + assume(!self._ptr.is_null()); &(**self._ptr) } } diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs index 2a701e67c53..6196d94b5a6 100644 --- a/src/libcollections/binary_heap.rs +++ b/src/libcollections/binary_heap.rs @@ -655,17 +655,6 @@ impl FromIterator for BinaryHeap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for BinaryHeap { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for BinaryHeap { type Item = T; @@ -676,17 +665,6 @@ impl IntoIterator for BinaryHeap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a BinaryHeap where T: Ord { type Item = &'a T; diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index df1a3416602..0b762788b20 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -1070,17 +1070,6 @@ impl<'a> RandomAccessIterator for Iter<'a> { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a> IntoIterator for &'a Bitv { - type IntoIter = Iter<'a>; - - fn into_iter(self) -> Iter<'a> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a> IntoIterator for &'a Bitv { type Item = bool; @@ -1895,17 +1884,6 @@ impl<'a> Iterator for SymmetricDifference<'a> { #[inline] fn size_hint(&self) -> (usize, Option) { self.0.size_hint() } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a> IntoIterator for &'a BitvSet { - type IntoIter = SetIter<'a>; - - fn into_iter(self) -> SetIter<'a> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a> IntoIterator for &'a BitvSet { type Item = usize; diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index a0c1c2d1854..747211e9238 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -462,17 +462,6 @@ impl BTreeMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for BTreeMap { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for BTreeMap { type Item = (K, V); @@ -483,17 +472,6 @@ impl IntoIterator for BTreeMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, K, V> IntoIterator for &'a BTreeMap { - type IntoIter = Iter<'a, K, V>; - - fn into_iter(self) -> Iter<'a, K, V> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> IntoIterator for &'a BTreeMap { type Item = (&'a K, &'a V); @@ -504,17 +482,6 @@ impl<'a, K, V> IntoIterator for &'a BTreeMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, K, V> IntoIterator for &'a mut BTreeMap { - type IntoIter = IterMut<'a, K, V>; - - fn into_iter(mut self) -> IterMut<'a, K, V> { - self.iter_mut() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V> IntoIterator for &'a mut BTreeMap { type Item = (&'a K, &'a mut V); diff --git a/src/libcollections/btree/set.rs b/src/libcollections/btree/set.rs index 8ac1b97de25..7ef887b70cc 100644 --- a/src/libcollections/btree/set.rs +++ b/src/libcollections/btree/set.rs @@ -480,17 +480,6 @@ impl FromIterator for BTreeSet { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for BTreeSet { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for BTreeSet { type Item = T; @@ -501,17 +490,6 @@ impl IntoIterator for BTreeSet { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a BTreeSet { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a BTreeSet { type Item = &'a T; diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index c2ffccc88a2..eb1bf93c0aa 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -837,17 +837,6 @@ impl FromIterator for DList { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for DList { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for DList { type Item = T; @@ -858,17 +847,6 @@ impl IntoIterator for DList { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a DList { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a DList { type Item = &'a T; @@ -879,17 +857,6 @@ impl<'a, T> IntoIterator for &'a DList { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a mut DList { - type IntoIter = IterMut<'a, T>; - - fn into_iter(mut self) -> IterMut<'a, T> { - self.iter_mut() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a, T> IntoIterator for &'a mut DList { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; diff --git a/src/libcollections/enum_set.rs b/src/libcollections/enum_set.rs index ec30933bd2e..d5403ca5d9b 100644 --- a/src/libcollections/enum_set.rs +++ b/src/libcollections/enum_set.rs @@ -257,17 +257,6 @@ impl FromIterator for EnumSet { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { - type IntoIter = Iter; - - fn into_iter(self) -> Iter { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, E> IntoIterator for &'a EnumSet where E: CLike { type Item = E; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 8325e7247d5..cacbf3bce80 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -111,15 +111,6 @@ pub fn fixme_14344_be_sure_to_link_to_collections() {} #[cfg(not(test))] mod std { - // NOTE: remove after next snapshot - #[cfg(stage0)] pub use core::clone; // derive(Clone) - #[cfg(stage0)] pub use core::cmp; // derive(Eq, Ord, etc.) - #[cfg(stage0)] pub use core::marker; // derive(Copy) - #[cfg(stage0)] pub use core::hash; // derive(Hash) - #[cfg(stage0)] pub use core::iter; - #[cfg(stage0)] pub use core::fmt; // necessary for panic!() - #[cfg(stage0)] pub use core::option; // necessary for panic!() - pub use core::ops; // RangeFull } diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index 93218aed366..6dcdb21f800 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1704,17 +1704,6 @@ impl FromIterator for RingBuf { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for RingBuf { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for RingBuf { type Item = T; @@ -1725,17 +1714,6 @@ impl IntoIterator for RingBuf { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a RingBuf { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a RingBuf { type Item = &'a T; @@ -1746,17 +1724,6 @@ impl<'a, T> IntoIterator for &'a RingBuf { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a mut RingBuf { - type IntoIter = IterMut<'a, T>; - - fn into_iter(mut self) -> IterMut<'a, T> { - self.iter_mut() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut RingBuf { type Item = &'a mut T; diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 245711f6705..bde733644b5 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1447,17 +1447,6 @@ impl FromIterator for Vec { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for Vec { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for Vec { type Item = T; @@ -1468,17 +1457,6 @@ impl IntoIterator for Vec { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a Vec { - type IntoIter = slice::Iter<'a, T>; - - fn into_iter(self) -> slice::Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a Vec { type Item = &'a T; @@ -1489,17 +1467,6 @@ impl<'a, T> IntoIterator for &'a Vec { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a mut Vec { - type IntoIter = slice::IterMut<'a, T>; - - fn into_iter(mut self) -> slice::IterMut<'a, T> { - self.iter_mut() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut Vec { type Item = &'a mut T; diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 7a2194f8110..82ccfd0614f 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -668,17 +668,6 @@ impl FromIterator<(usize, V)> for VecMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for VecMap { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for VecMap { type Item = (usize, T); @@ -689,17 +678,6 @@ impl IntoIterator for VecMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a VecMap { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a VecMap { type Item = (usize, &'a T); @@ -710,17 +688,6 @@ impl<'a, T> IntoIterator for &'a VecMap { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a mut VecMap { - type IntoIter = IterMut<'a, T>; - - fn into_iter(mut self) -> IterMut<'a, T> { - self.iter_mut() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut VecMap { type Item = (usize, &'a mut T); diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 886893e647e..838ca4e478b 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -48,17 +48,6 @@ macro_rules! array_impls { } } - // NOTE(stage0): remove impl after a snapshot - #[cfg(stage0)] - impl<'a, T> IntoIterator for &'a [T; $N] { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } - } - - #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a [T; $N] { type Item = &'a T; @@ -69,17 +58,6 @@ macro_rules! array_impls { } } - // NOTE(stage0): remove impl after a snapshot - #[cfg(stage0)] - impl<'a, T> IntoIterator for &'a mut [T; $N] { - type IntoIter = IterMut<'a, T>; - - fn into_iter(self) -> IterMut<'a, T> { - self.iter_mut() - } - } - - #[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut [T; $N] { type Item = &'a mut T; diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index c13e8e78210..eb138e6142b 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -649,8 +649,7 @@ impl<'b, T> DerefMut for RefMut<'b, T> { /// /// **NOTE:** `UnsafeCell`'s fields are public to allow static initializers. It is not /// recommended to access its fields directly, `get` should be used instead. -#[cfg_attr(stage0, lang="unsafe")] // NOTE: remove after next snapshot -#[cfg_attr(not(stage0), lang="unsafe_cell")] +#[lang="unsafe_cell"] #[stable(feature = "rust1", since = "1.0.0")] pub struct UnsafeCell { /// Wrapped value diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 2960c310386..fffba1561a3 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -118,18 +118,6 @@ pub trait FromIterator { fn from_iter>(iterator: T) -> Self; } -// NOTE(stage0): remove trait after a snapshot -#[cfg(stage0)] -/// Conversion into an `Iterator` -pub trait IntoIterator { - type IntoIter: Iterator; - - /// Consumes `Self` and returns an iterator over it - #[stable(feature = "rust1", since = "1.0.0")] - fn into_iter(self) -> Self::IntoIter; -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot /// Conversion into an `Iterator` #[stable(feature = "rust1", since = "1.0.0")] pub trait IntoIterator { @@ -144,17 +132,6 @@ pub trait IntoIterator { fn into_iter(self) -> Self::IntoIter; } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for I where I: Iterator { - type IntoIter = I; - - fn into_iter(self) -> I { - self - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for I { type Item = I::Item; diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index f1808bc1fb5..f0c60ffe4bf 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -154,25 +154,16 @@ mod array; mod core { pub use panicking; pub use fmt; - #[cfg(not(stage0))] pub use clone; - #[cfg(not(stage0))] pub use cmp; - #[cfg(not(stage0))] pub use hash; - #[cfg(not(stage0))] pub use marker; - #[cfg(not(stage0))] pub use option; - #[cfg(not(stage0))] pub use iter; + pub use clone; + pub use cmp; + pub use hash; + pub use marker; + pub use option; + pub use iter; } #[doc(hidden)] mod std { - // NOTE: remove after next snapshot - #[cfg(stage0)] pub use clone; - #[cfg(stage0)] pub use cmp; - #[cfg(stage0)] pub use hash; - #[cfg(stage0)] pub use marker; - #[cfg(stage0)] pub use option; - #[cfg(stage0)] pub use fmt; - #[cfg(stage0)] pub use iter; - // range syntax pub use ops; } diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 7e8472b91dc..56e1c5dedc1 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -32,7 +32,7 @@ use clone::Clone; reason = "will be overhauled with new lifetime rules; see RFC 458")] #[lang="send"] #[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"] -#[cfg(stage0)] // SNAP ac134f7 remove after stage0 +#[cfg(stage0)] pub unsafe trait Send: 'static { // empty. } @@ -435,7 +435,7 @@ pub struct NoCopy; #[derive(Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Managed; -#[cfg(not(stage0))] // SNAP ac134f7 remove this attribute after the next snapshot +#[cfg(not(stage0))] mod impls { use super::{Send, Sync, Sized}; diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index ded76f51b07..bbfe7e58ef4 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -626,17 +626,6 @@ impl<'a, T> Default for &'a [T] { // Iterators // -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a [T] { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a [T] { type Item = &'a T; @@ -647,17 +636,6 @@ impl<'a, T> IntoIterator for &'a [T] { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T> IntoIterator for &'a mut [T] { - type IntoIter = IterMut<'a, T>; - - fn into_iter(self) -> IterMut<'a, T> { - self.iter_mut() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> IntoIterator for &'a mut [T] { type Item = &'a mut T; diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 4535e0b1691..d9f420bdd33 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -5733,10 +5733,3 @@ pub mod funcs { pub fn issue_14344_workaround() {} // FIXME #14344 force linkage to happen correctly #[test] fn work_on_windows() { } // FIXME #10872 needed for a happy windows - -// NOTE: remove after next snapshot -#[doc(hidden)] -#[cfg(all(stage0, not(test)))] -mod std { - pub use core::marker; -} diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 4113718cfd1..915c70bbf8c 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -497,17 +497,6 @@ pub struct Open01(pub F); /// ``` pub struct Closed01(pub F); -// NOTE: remove after next snapshot -#[cfg(all(stage0, not(test)))] -mod std { - pub use core::{option, fmt}; // panic!() - pub use core::clone; // derive Clone - pub use core::marker; - // for-loops - pub use core::iter; - pub use core::ops; // slicing syntax -} - #[cfg(test)] mod test { use std::rand; diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index e27e7a80246..9bf35bd4284 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -530,17 +530,6 @@ impl<'a,T> Iterator for EnumeratedItems<'a,T> { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for VecPerParamSpace { - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_vec().into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl IntoIterator for VecPerParamSpace { type Item = T; type IntoIter = IntoIter; @@ -550,17 +539,6 @@ impl IntoIterator for VecPerParamSpace { } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a,T> IntoIterator for &'a VecPerParamSpace { - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.as_slice().into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot impl<'a,T> IntoIterator for &'a VecPerParamSpace { type Item = &'a T; type IntoIter = Iter<'a, T>; diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 107715a8261..8618bde95fe 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -73,8 +73,6 @@ use std::cell::{Cell, RefCell}; use std::cmp; use std::fmt; use std::hash::{Hash, Writer, SipHasher, Hasher}; -#[cfg(stage0)] -use std::marker; use std::mem; use std::ops; use std::rc::Rc; @@ -944,26 +942,6 @@ pub struct TyS<'tcx> { // the maximal depth of any bound regions appearing in this type. region_depth: u32, - - // force the lifetime to be invariant to work-around - // region-inference issues with a covariant lifetime. - #[cfg(stage0)] - marker: ShowInvariantLifetime<'tcx>, -} - -#[cfg(stage0)] -struct ShowInvariantLifetime<'a>(marker::InvariantLifetime<'a>); -#[cfg(stage0)] -impl<'a> ShowInvariantLifetime<'a> { - fn new() -> ShowInvariantLifetime<'a> { - ShowInvariantLifetime(marker::InvariantLifetime) - } -} -#[cfg(stage0)] -impl<'a> fmt::Debug for ShowInvariantLifetime<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "InvariantLifetime") - } } impl fmt::Debug for TypeFlags { @@ -972,14 +950,6 @@ impl fmt::Debug for TypeFlags { } } -#[cfg(stage0)] -impl<'tcx> PartialEq for TyS<'tcx> { - fn eq<'a,'b>(&'a self, other: &'b TyS<'tcx>) -> bool { - let other: &'a TyS<'tcx> = unsafe { mem::transmute(other) }; - (self as *const _) == (other as *const _) - } -} -#[cfg(not(stage0))] impl<'tcx> PartialEq for TyS<'tcx> { fn eq(&self, other: &TyS<'tcx>) -> bool { // (self as *const _) == (other as *const _) @@ -2562,12 +2532,6 @@ fn intern_ty<'tcx>(type_arena: &'tcx TypedArena>, let flags = FlagComputation::for_sty(&st); let ty = match () { - #[cfg(stage0)] - () => type_arena.alloc(TyS { sty: st, - flags: flags.flags, - region_depth: flags.depth, - marker: ShowInvariantLifetime::new(), }), - #[cfg(not(stage0))] () => type_arena.alloc(TyS { sty: st, flags: flags.flags, region_depth: flags.depth, }), diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index e11bcec150c..1b9f8b99017 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1372,21 +1372,6 @@ enum VacantEntryState { NoElem(EmptyBucket), } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, K, V, S, H> IntoIterator for &'a HashMap - where K: Eq + Hash, - S: HashState, - H: hash::Hasher -{ - type IntoIter = Iter<'a, K, V>; - - fn into_iter(self) -> Iter<'a, K, V> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V, S, H> IntoIterator for &'a HashMap where K: Eq + Hash, @@ -1401,21 +1386,6 @@ impl<'a, K, V, S, H> IntoIterator for &'a HashMap } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap - where K: Eq + Hash, - S: HashState, - H: hash::Hasher -{ - type IntoIter = IterMut<'a, K, V>; - - fn into_iter(mut self) -> IterMut<'a, K, V> { - self.iter_mut() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap where K: Eq + Hash, @@ -1430,21 +1400,6 @@ impl<'a, K, V, S, H> IntoIterator for &'a mut HashMap } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for HashMap - where K: Eq + Hash, - S: HashState, - H: hash::Hasher -{ - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for HashMap where K: Eq + Hash, diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index fb01dc89e68..5fbbcb3b347 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -835,21 +835,6 @@ pub struct Union<'a, T: 'a, S: 'a> { iter: Chain, Difference<'a, T, S>> } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl<'a, T, S, H> IntoIterator for &'a HashSet - where T: Eq + Hash, - S: HashState, - H: hash::Hasher -{ - type IntoIter = Iter<'a, T>; - - fn into_iter(self) -> Iter<'a, T> { - self.iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, S, H> IntoIterator for &'a HashSet where T: Eq + Hash, @@ -864,21 +849,6 @@ impl<'a, T, S, H> IntoIterator for &'a HashSet } } -// NOTE(stage0): remove impl after a snapshot -#[cfg(stage0)] -impl IntoIterator for HashSet - where T: Eq + Hash, - S: HashState, - H: hash::Hasher -{ - type IntoIter = IntoIter; - - fn into_iter(self) -> IntoIter { - self.into_iter() - } -} - -#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for HashSet where T: Eq + Hash, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 139693ccdbc..7c9a8a7b4b5 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -292,13 +292,6 @@ mod tuple; // can be resolved within libstd. #[doc(hidden)] mod std { - // NOTE: remove after next snapshot - // mods used for deriving - #[cfg(stage0)] pub use clone; - #[cfg(stage0)] pub use cmp; - #[cfg(stage0)] pub use hash; - #[cfg(stage0)] pub use default; - pub use sync; // used for select!() pub use error; // used for try!() pub use fmt; // used for any formatting strings @@ -319,7 +312,4 @@ mod std { pub use slice; pub use boxed; // used for vec![] - // for-loops - // NOTE: remove after next snapshot - #[cfg(stage0)] pub use iter; } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 1b9b13d4bd4..00bb7f86b17 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -60,23 +60,6 @@ macro_rules! panic { }); } -/// Use the syntax described in `std::fmt` to create a value of type `String`. -/// See `std::fmt` for more information. -/// -/// # Example -/// -/// ``` -/// format!("test"); -/// format!("hello {}", "world!"); -/// format!("x = {}, y = {y}", 10, y = 30); -/// ``` -#[cfg(stage0)] // NOTE: remove after snapshot -#[macro_export] -#[stable(feature = "rust1", since = "1.0.0")] -macro_rules! format { - ($($arg:tt)*) => ($crate::fmt::format(format_args!($($arg)*))) -} - /// Equivalent to the `println!` macro except that a newline is not printed at /// the end of the message. #[macro_export] diff --git a/src/libstd/thunk.rs b/src/libstd/thunk.rs index 1412dbd70b9..fe39954f0d4 100644 --- a/src/libstd/thunk.rs +++ b/src/libstd/thunk.rs @@ -17,7 +17,7 @@ use core::marker::Send; use core::ops::FnOnce; pub struct Thunk<'a, A=(),R=()> { - #[cfg(stage0)] // // SNAP ac134f7 remove after stage0 + #[cfg(stage0)] invoke: Box+Send>, #[cfg(not(stage0))] invoke: Box+Send + 'a>, diff --git a/src/libunicode/lib.rs b/src/libunicode/lib.rs index 89b310d4949..791886be1ce 100644 --- a/src/libunicode/lib.rs +++ b/src/libunicode/lib.rs @@ -77,16 +77,3 @@ pub mod str { pub use u_str::{utf8_char_width, is_utf16, Utf16Items, Utf16Item}; pub use u_str::{utf16_items, Utf16Encoder}; } - -// NOTE: remove after next snapshot -// this lets us use #[derive(..)] -#[cfg(stage0)] -mod std { - pub use core::clone; - pub use core::cmp; - pub use core::fmt; - pub use core::marker; - // for-loops - pub use core::iter; - pub use core::option; -} diff --git a/src/snapshots.txt b/src/snapshots.txt index 56948ea1219..4759c44259d 100644 --- a/src/snapshots.txt +++ b/src/snapshots.txt @@ -1,3 +1,12 @@ +S 2015-02-17 f1bb6c2 + freebsd-x86_64 59f3a2c6350c170804fb65838e1b504eeab89105 + linux-i386 191ed5ec4f17e32d36abeade55a1c6085e51245c + linux-x86_64 acec86045632f4f3f085c072ba696f889906dffe + macos-i386 9d9e622584bfa318f32bcb5b9ce6a365febff595 + macos-x86_64 e96c1e9860b186507cc75c186d1b96d44df12292 + winnt-i386 3f43e0e71311636f9143ad6f2ee7a514e9fa3f8e + winnt-x86_64 26ef3d9098ea346e5ff8945d5b224bb10c24341d + S 2015-02-04 ac134f7 freebsd-x86_64 483e37a02a7ebc12a872e3146145e342ba4a5c04 linux-i386 8af64e5df839cc945399484380a8b2ebe05a6751 diff --git a/src/test/run-pass/foreign-call-no-runtime.rs b/src/test/run-pass/foreign-call-no-runtime.rs index f99d3eb1c7d..3f226a1985e 100644 --- a/src/test/run-pass/foreign-call-no-runtime.rs +++ b/src/test/run-pass/foreign-call-no-runtime.rs @@ -11,7 +11,7 @@ extern crate libc; use std::mem; -use std::thread::Thread; +use std::thread; #[link(name = "rust_test_helpers")] extern { @@ -21,9 +21,9 @@ extern { pub fn main() { unsafe { - Thread::scoped(move|| { - let i = &100; - rust_dbg_call(callback, mem::transmute(i)); + thread::spawn(move|| { + let i = 100; + rust_dbg_call(callback, mem::transmute(&i)); }).join(); } } -- cgit 1.4.1-3-g733a5