diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2017-07-05 08:42:13 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2017-07-05 08:42:13 -0700 |
| commit | fd95db25b367d5d61ee9bc86b928c529747b3622 (patch) | |
| tree | f93755558c3f91addb568e1f5aa4f2a4799589f5 /src/libstd | |
| parent | d316874c87e25669895c306658e15aa3746d66ab (diff) | |
| parent | 692b5722363be2de18a27b46db59950124a5101d (diff) | |
| download | rust-fd95db25b367d5d61ee9bc86b928c529747b3622.tar.gz rust-fd95db25b367d5d61ee9bc86b928c529747b3622.zip | |
Merge remote-tracking branch 'origin/master' into proc_macro_api
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/env.rs | 82 | ||||
| -rw-r--r-- | src/libstd/f32.rs | 48 | ||||
| -rw-r--r-- | src/libstd/f64.rs | 39 | ||||
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 8 | ||||
| -rw-r--r-- | src/libstd/ffi/os_str.rs | 14 | ||||
| -rw-r--r-- | src/libstd/fs.rs | 39 | ||||
| -rw-r--r-- | src/libstd/io/mod.rs | 20 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 10 | ||||
| -rw-r--r-- | src/libstd/panicking.rs | 84 | ||||
| -rw-r--r-- | src/libstd/path.rs | 21 | ||||
| -rw-r--r-- | src/libstd/process.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/redox/fast_thread_local.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/redox/fs.rs | 19 | ||||
| -rw-r--r-- | src/libstd/sys/redox/net/tcp.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/redox/pipe.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/redox/syscall/flag.rs | 2 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 10 |
18 files changed, 201 insertions, 212 deletions
diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 1dfae0ce83f..f81adad3ebe 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -949,63 +949,9 @@ mod arch { mod tests { use super::*; - use iter::repeat; - use rand::{self, Rng}; - use ffi::{OsString, OsStr}; + use ffi::OsStr; use path::{Path, PathBuf}; - fn make_rand_name() -> OsString { - let mut rng = rand::thread_rng(); - let n = format!("TEST{}", rng.gen_ascii_chars().take(10) - .collect::<String>()); - let n = OsString::from(n); - assert!(var_os(&n).is_none()); - n - } - - fn eq(a: Option<OsString>, b: Option<&str>) { - assert_eq!(a.as_ref().map(|s| &**s), b.map(OsStr::new).map(|s| &*s)); - } - - #[test] - fn test_set_var() { - let n = make_rand_name(); - set_var(&n, "VALUE"); - eq(var_os(&n), Some("VALUE")); - } - - #[test] - fn test_remove_var() { - let n = make_rand_name(); - set_var(&n, "VALUE"); - remove_var(&n); - eq(var_os(&n), None); - } - - #[test] - fn test_set_var_overwrite() { - let n = make_rand_name(); - set_var(&n, "1"); - set_var(&n, "2"); - eq(var_os(&n), Some("2")); - set_var(&n, ""); - eq(var_os(&n), Some("")); - } - - #[test] - #[cfg_attr(target_os = "emscripten", ignore)] - fn test_var_big() { - let mut s = "".to_string(); - let mut i = 0; - while i < 100 { - s.push_str("aaaaaaaaaa"); - i += 1; - } - let n = make_rand_name(); - set_var(&n, &s); - eq(var_os(&n), Some(&s)); - } - #[test] #[cfg_attr(target_os = "emscripten", ignore)] fn test_self_exe_path() { @@ -1018,32 +964,6 @@ mod tests { } #[test] - #[cfg_attr(target_os = "emscripten", ignore)] - fn test_env_set_get_huge() { - let n = make_rand_name(); - let s = repeat("x").take(10000).collect::<String>(); - set_var(&n, &s); - eq(var_os(&n), Some(&s)); - remove_var(&n); - eq(var_os(&n), None); - } - - #[test] - fn test_env_set_var() { - let n = make_rand_name(); - - let mut e = vars_os(); - set_var(&n, "VALUE"); - assert!(!e.any(|(k, v)| { - &*k == &*n && &*v == "VALUE" - })); - - assert!(vars_os().any(|(k, v)| { - &*k == &*n && &*v == "VALUE" - })); - } - - #[test] fn test() { assert!((!Path::new("test-path").is_absolute())); diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 6134b0b882c..a6eb17c8fa4 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -363,39 +363,29 @@ impl f32 { #[inline] pub fn signum(self) -> f32 { num::Float::signum(self) } - /// Returns `true` if `self`'s sign bit is positive, including - /// `+0.0` and `INFINITY`. + /// Returns `true` if and only if `self` has a positive sign, including `+0.0`, `NaN`s with + /// positive sign bit and positive infinity. /// /// ``` - /// use std::f32; - /// - /// let nan = f32::NAN; /// let f = 7.0_f32; /// let g = -7.0_f32; /// /// assert!(f.is_sign_positive()); /// assert!(!g.is_sign_positive()); - /// // Requires both tests to determine if is `NaN` - /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_sign_positive(self) -> bool { num::Float::is_sign_positive(self) } - /// Returns `true` if `self`'s sign is negative, including `-0.0` - /// and `NEG_INFINITY`. + /// Returns `true` if and only if `self` has a negative sign, including `-0.0`, `NaN`s with + /// negative sign bit and negative infinity. /// /// ``` - /// use std::f32; - /// - /// let nan = f32::NAN; /// let f = 7.0f32; /// let g = -7.0f32; /// /// assert!(!f.is_sign_negative()); /// assert!(g.is_sign_negative()); - /// // Requires both tests to determine if is `NaN`. - /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -1141,13 +1131,16 @@ impl f32 { #[inline] pub fn from_bits(mut v: u32) -> Self { const EXP_MASK: u32 = 0x7F800000; - const QNAN_MASK: u32 = 0x00400000; const FRACT_MASK: u32 = 0x007FFFFF; if v & EXP_MASK == EXP_MASK && v & FRACT_MASK != 0 { - // If we have a NaN value, we - // convert signaling NaN values to quiet NaN - // by setting the the highest bit of the fraction - v |= QNAN_MASK; + // While IEEE 754-2008 specifies encodings for quiet NaNs + // and signaling ones, certain MIPS and PA-RISC + // CPUs treat signaling NaNs differently. + // Therefore to be safe, we pass a known quiet NaN + // if v is any kind of NaN. + // The check above only assumes IEEE 754-1985 to be + // valid. + v = unsafe { ::mem::transmute(NAN) }; } unsafe { ::mem::transmute(v) } } @@ -1184,7 +1177,7 @@ mod tests { assert!(!nan.is_infinite()); assert!(!nan.is_finite()); assert!(!nan.is_normal()); - assert!(!nan.is_sign_positive()); + assert!(nan.is_sign_positive()); assert!(!nan.is_sign_negative()); assert_eq!(Fp::Nan, nan.classify()); } @@ -1428,7 +1421,8 @@ mod tests { assert!(!(-1f32).is_sign_positive()); assert!(!NEG_INFINITY.is_sign_positive()); assert!(!(1f32/NEG_INFINITY).is_sign_positive()); - assert!(!NAN.is_sign_positive()); + assert!(NAN.is_sign_positive()); + assert!(!(-NAN).is_sign_positive()); } #[test] @@ -1441,6 +1435,7 @@ mod tests { assert!(NEG_INFINITY.is_sign_negative()); assert!((1f32/NEG_INFINITY).is_sign_negative()); assert!(!NAN.is_sign_negative()); + assert!((-NAN).is_sign_negative()); } #[test] @@ -1740,8 +1735,15 @@ mod tests { } #[test] fn test_snan_masking() { + // NOTE: this test assumes that our current platform + // implements IEEE 754-2008 that specifies the difference + // in encoding of quiet and signaling NaNs. + // If you are porting Rust to a platform that does not + // implement IEEE 754-2008 (but e.g. IEEE 754-1985, which + // only says that "Signaling NaNs shall be reserved operands" + // but doesn't specify the actual setup), feel free to + // cfg out this test. let snan: u32 = 0x7F801337; - const PAYLOAD_MASK: u32 = 0x003FFFFF; const QNAN_MASK: u32 = 0x00400000; let nan_masked_fl = f32::from_bits(snan); let nan_masked = nan_masked_fl.to_bits(); @@ -1750,7 +1752,5 @@ mod tests { // Ensure that we have a quiet NaN assert_ne!(nan_masked & QNAN_MASK, 0); assert!(nan_masked_fl.is_nan()); - // Ensure the payload wasn't touched during conversion - assert_eq!(nan_masked & PAYLOAD_MASK, snan & PAYLOAD_MASK); } } diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index e8d25cfbf94..4d8d8b4ebe6 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -301,21 +301,15 @@ impl f64 { #[inline] pub fn signum(self) -> f64 { num::Float::signum(self) } - /// Returns `true` if `self`'s sign bit is positive, including - /// `+0.0` and `INFINITY`. + /// Returns `true` if and only if `self` has a positive sign, including `+0.0`, `NaN`s with + /// positive sign bit and positive infinity. /// /// ``` - /// use std::f64; - /// - /// let nan: f64 = f64::NAN; - /// /// let f = 7.0_f64; /// let g = -7.0_f64; /// /// assert!(f.is_sign_positive()); /// assert!(!g.is_sign_positive()); - /// // Requires both tests to determine if is `NaN` - /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -326,21 +320,15 @@ impl f64 { #[inline] pub fn is_positive(self) -> bool { num::Float::is_sign_positive(self) } - /// Returns `true` if `self`'s sign is negative, including `-0.0` - /// and `NEG_INFINITY`. + /// Returns `true` if and only if `self` has a negative sign, including `-0.0`, `NaN`s with + /// negative sign bit and negative infinity. /// /// ``` - /// use std::f64; - /// - /// let nan = f64::NAN; - /// /// let f = 7.0_f64; /// let g = -7.0_f64; /// /// assert!(!f.is_sign_negative()); /// assert!(g.is_sign_negative()); - /// // Requires both tests to determine if is `NaN`. - /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -1058,13 +1046,16 @@ impl f64 { #[inline] pub fn from_bits(mut v: u64) -> Self { const EXP_MASK: u64 = 0x7FF0000000000000; - const QNAN_MASK: u64 = 0x0001000000000000; const FRACT_MASK: u64 = 0x000FFFFFFFFFFFFF; if v & EXP_MASK == EXP_MASK && v & FRACT_MASK != 0 { - // If we have a NaN value, we - // convert signaling NaN values to quiet NaN - // by setting the the highest bit of the fraction - v |= QNAN_MASK; + // While IEEE 754-2008 specifies encodings for quiet NaNs + // and signaling ones, certain MIPS and PA-RISC + // CPUs treat signaling NaNs differently. + // Therefore to be safe, we pass a known quiet NaN + // if v is any kind of NaN. + // The check above only assumes IEEE 754-1985 to be + // valid. + v = unsafe { ::mem::transmute(NAN) }; } unsafe { ::mem::transmute(v) } } @@ -1101,7 +1092,7 @@ mod tests { assert!(!nan.is_infinite()); assert!(!nan.is_finite()); assert!(!nan.is_normal()); - assert!(!nan.is_sign_positive()); + assert!(nan.is_sign_positive()); assert!(!nan.is_sign_negative()); assert_eq!(Fp::Nan, nan.classify()); } @@ -1347,7 +1338,8 @@ mod tests { assert!(!(-1f64).is_sign_positive()); assert!(!NEG_INFINITY.is_sign_positive()); assert!(!(1f64/NEG_INFINITY).is_sign_positive()); - assert!(!NAN.is_sign_positive()); + assert!(NAN.is_sign_positive()); + assert!(!(-NAN).is_sign_positive()); } #[test] @@ -1360,6 +1352,7 @@ mod tests { assert!(NEG_INFINITY.is_sign_negative()); assert!((1f64/NEG_INFINITY).is_sign_negative()); assert!(!NAN.is_sign_negative()); + assert!((-NAN).is_sign_negative()); } #[test] diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 1a91417ca0e..5f0b11a616e 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -585,11 +585,11 @@ impl From<Box<CStr>> for CString { } } -#[stable(feature = "box_from_c_string", since = "1.18.0")] -impl Into<Box<CStr>> for CString { +#[stable(feature = "box_from_c_string", since = "1.20.0")] +impl From<CString> for Box<CStr> { #[inline] - fn into(self) -> Box<CStr> { - self.into_boxed_c_str() + fn from(s: CString) -> Box<CStr> { + s.into_boxed_c_str() } } diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index f54d79c201f..02a13ed7a5a 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -29,7 +29,7 @@ use sys_common::{AsInner, IntoInner, FromInner}; /// * On Windows, strings are often arbitrary sequences of non-zero 16-bit /// values, interpreted as UTF-16 when it is valid to do so. /// -/// * In Rust, strings are always valid UTF-8, but may contain zeros. +/// * In Rust, strings are always valid UTF-8, which may contain zeros. /// /// `OsString` and [`OsStr`] bridge this gap by simultaneously representing Rust /// and platform-native string values, and in particular allowing a Rust string @@ -230,8 +230,6 @@ impl OsString { /// # Examples /// /// ``` - /// #![feature(osstring_shrink_to_fit)] - /// /// use std::ffi::OsString; /// /// let mut s = OsString::from("foo"); @@ -242,7 +240,7 @@ impl OsString { /// s.shrink_to_fit(); /// assert_eq!(3, s.capacity()); /// ``` - #[unstable(feature = "osstring_shrink_to_fit", issue = "40421")] + #[stable(feature = "osstring_shrink_to_fit", since = "1.19.0")] pub fn shrink_to_fit(&mut self) { self.inner.shrink_to_fit() } @@ -542,10 +540,10 @@ impl From<Box<OsStr>> for OsString { } } -#[stable(feature = "box_from_os_string", since = "1.18.0")] -impl Into<Box<OsStr>> for OsString { - fn into(self) -> Box<OsStr> { - self.into_boxed_os_str() +#[stable(feature = "box_from_os_string", since = "1.20.0")] +impl From<OsString> for Box<OsStr> { + fn from(s: OsString) -> Box<OsStr> { + s.into_boxed_os_str() } } diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 5b8c0c33990..88994b284c9 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -653,15 +653,29 @@ impl OpenOptions { /// # Errors /// /// This function will return an error under a number of different - /// circumstances, to include but not limited to: - /// - /// * Opening a file that does not exist without setting `create` or - /// `create_new`. - /// * Attempting to open a file with access that the user lacks - /// permissions for - /// * Filesystem-level errors (full disk, etc) - /// * Invalid combinations of open options (truncate without write access, - /// no access mode set, etc) + /// circumstances. Some of these error conditions are listed here, together + /// with their [`ErrorKind`]. The mapping to [`ErrorKind`]s is not part of + /// the compatiblity contract of the function, especially the `Other` kind + /// might change to more specific kinds in the future. + /// + /// * [`NotFound`]: The specified file does not exist and neither `create` + /// or `create_new` is set. + /// * [`NotFound`]: One of the directory components of the file path does + /// not exist. + /// * [`PermissionDenied`]: The user lacks permission to get the specified + /// access rights for the file. + /// * [`PermissionDenied`]: The user lacks permission to open one of the + /// directory components of the specified path. + /// * [`AlreadyExists`]: `create_new` was specified and the file already + /// exists. + /// * [`InvalidInput`]: Invalid combinations of open options (truncate + /// without write access, no access mode set, etc.). + /// * [`Other`]: One of the directory components of the specified file path + /// was not, in fact, a directory. + /// * [`Other`]: Filesystem-level errors: full disk, write permission + /// requested on a read-only file system, exceeded disk quota, too many + /// open files, too long filename, too many symbolic links in the + /// specified path (Unix-like systems only), etc. /// /// # Examples /// @@ -670,6 +684,13 @@ impl OpenOptions { /// /// let file = OpenOptions::new().open("foo.txt"); /// ``` + /// + /// [`ErrorKind`]: ../io/enum.ErrorKind.html + /// [`AlreadyExists`]: ../io/enum.ErrorKind.html#variant.AlreadyExists + /// [`InvalidInput`]: ../io/enum.ErrorKind.html#variant.InvalidInput + /// [`NotFound`]: ../io/enum.ErrorKind.html#variant.NotFound + /// [`Other`]: ../io/enum.ErrorKind.html#variant.Other + /// [`PermissionDenied`]: ../io/enum.ErrorKind.html#variant.PermissionDenied #[stable(feature = "rust1", since = "1.0.0")] pub fn open<P: AsRef<Path>>(&self, path: P) -> io::Result<File> { self._open(path.as_ref()) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 680a5f32ae2..71c76008244 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1589,8 +1589,6 @@ impl<T, U> Chain<T, U> { /// # Examples /// /// ``` - /// #![feature(more_io_inner_methods)] - /// /// # use std::io; /// use std::io::prelude::*; /// use std::fs::File; @@ -1604,7 +1602,7 @@ impl<T, U> Chain<T, U> { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="41519")] + #[stable(feature = "more_io_inner_methods", since = "1.20.0")] pub fn into_inner(self) -> (T, U) { (self.first, self.second) } @@ -1614,8 +1612,6 @@ impl<T, U> Chain<T, U> { /// # Examples /// /// ``` - /// #![feature(more_io_inner_methods)] - /// /// # use std::io; /// use std::io::prelude::*; /// use std::fs::File; @@ -1629,7 +1625,7 @@ impl<T, U> Chain<T, U> { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="41519")] + #[stable(feature = "more_io_inner_methods", since = "1.20.0")] pub fn get_ref(&self) -> (&T, &U) { (&self.first, &self.second) } @@ -1643,8 +1639,6 @@ impl<T, U> Chain<T, U> { /// # Examples /// /// ``` - /// #![feature(more_io_inner_methods)] - /// /// # use std::io; /// use std::io::prelude::*; /// use std::fs::File; @@ -1658,7 +1652,7 @@ impl<T, U> Chain<T, U> { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="41519")] + #[stable(feature = "more_io_inner_methods", since = "1.20.0")] pub fn get_mut(&mut self) -> (&mut T, &mut U) { (&mut self.first, &mut self.second) } @@ -1791,8 +1785,6 @@ impl<T> Take<T> { /// # Examples /// /// ``` - /// #![feature(more_io_inner_methods)] - /// /// use std::io; /// use std::io::prelude::*; /// use std::fs::File; @@ -1808,7 +1800,7 @@ impl<T> Take<T> { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="41519")] + #[stable(feature = "more_io_inner_methods", since = "1.20.0")] pub fn get_ref(&self) -> &T { &self.inner } @@ -1822,8 +1814,6 @@ impl<T> Take<T> { /// # Examples /// /// ``` - /// #![feature(more_io_inner_methods)] - /// /// use std::io; /// use std::io::prelude::*; /// use std::fs::File; @@ -1839,7 +1829,7 @@ impl<T> Take<T> { /// # Ok(()) /// # } /// ``` - #[unstable(feature = "more_io_inner_methods", issue="41519")] + #[stable(feature = "more_io_inner_methods", since = "1.20.0")] pub fn get_mut(&mut self) -> &mut T { &mut self.inner } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 9a4c5ec8f6b..6eb9faacf7f 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -41,10 +41,10 @@ macro_rules! panic { panic!("explicit panic") }); ($msg:expr) => ({ - $crate::rt::begin_panic($msg, { + $crate::rt::begin_panic_new($msg, { // static requires less code at runtime, more constant data - static _FILE_LINE: (&'static str, u32) = (file!(), line!()); - &_FILE_LINE + static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(), column!()); + &_FILE_LINE_COL }) }); ($fmt:expr, $($arg:tt)+) => ({ @@ -53,8 +53,8 @@ macro_rules! panic { // used inside a dead function. Just `#[allow(dead_code)]` is // insufficient, since the user may have // `#[forbid(dead_code)]` and which cannot be overridden. - static _FILE_LINE: (&'static str, u32) = (file!(), line!()); - &_FILE_LINE + static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(), column!()); + &_FILE_LINE_COL }) }); } diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 6f46a73698f..494376b831e 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -262,6 +262,7 @@ impl<'a> PanicInfo<'a> { pub struct Location<'a> { file: &'a str, line: u32, + col: u32, } impl<'a> Location<'a> { @@ -308,6 +309,29 @@ impl<'a> Location<'a> { pub fn line(&self) -> u32 { self.line } + + /// Returns the column from which the panic originated. + /// + /// # Examples + /// + /// ```should_panic + /// #![feature(panic_col)] + /// use std::panic; + /// + /// panic::set_hook(Box::new(|panic_info| { + /// if let Some(location) = panic_info.location() { + /// println!("panic occured at column {}", location.column()); + /// } else { + /// println!("panic occured but can't get location information..."); + /// } + /// })); + /// + /// panic!("Normal panic"); + /// ``` + #[unstable(feature = "panic_col", reason = "recently added", issue = "42939")] + pub fn column(&self) -> u32 { + self.col + } } fn default_hook(info: &PanicInfo) { @@ -329,6 +353,7 @@ fn default_hook(info: &PanicInfo) { let file = info.location.file; let line = info.location.line; + let col = info.location.col; let msg = match info.payload.downcast_ref::<&'static str>() { Some(s) => *s, @@ -342,8 +367,8 @@ fn default_hook(info: &PanicInfo) { let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>"); let write = |err: &mut ::io::Write| { - let _ = writeln!(err, "thread '{}' panicked at '{}', {}:{}", - name, msg, file, line); + let _ = writeln!(err, "thread '{}' panicked at '{}', {}:{}:{}", + name, msg, file, line, col); #[cfg(feature = "backtrace")] { @@ -467,8 +492,9 @@ pub fn panicking() -> bool { #[unwind] pub extern fn rust_begin_panic(msg: fmt::Arguments, file: &'static str, - line: u32) -> ! { - begin_panic_fmt(&msg, &(file, line)) + line: u32, + col: u32) -> ! { + begin_panic_fmt(&msg, &(file, line, col)) } /// The entry point for panicking with a formatted message. @@ -482,7 +508,7 @@ pub extern fn rust_begin_panic(msg: fmt::Arguments, issue = "0")] #[inline(never)] #[cold] pub fn begin_panic_fmt(msg: &fmt::Arguments, - file_line: &(&'static str, u32)) -> ! { + file_line_col: &(&'static str, u32, u32)) -> ! { use fmt::Write; // We do two allocations here, unfortunately. But (a) they're @@ -492,7 +518,39 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments, let mut s = String::new(); let _ = s.write_fmt(*msg); - begin_panic(s, file_line) + begin_panic_new(s, file_line_col) +} + +// FIXME: In PR #42938, we have added the column as info passed to the panic +// handling code. For this, we want to break the ABI of begin_panic. +// This is not possible to do directly, as the stage0 compiler is hardcoded +// to emit a call to begin_panic in src/libsyntax/ext/build.rs, only +// with the file and line number being passed, but not the colum number. +// By changing the compiler source, we can only affect behaviour of higher +// stages. We need to perform the switch over two stage0 replacements, using +// a temporary function begin_panic_new while performing the switch: +// 0. Right now, we tell stage1 onward to emit a call to begin_panic_new. +// 1. In the first SNAP, stage0 calls begin_panic_new with the new ABI, +// begin_panic stops being used. Now we can change begin_panic to +// the new ABI, and start emitting calls to begin_panic in higher +// stages again, this time with the new ABI. +// 2. After the second SNAP, stage0 calls begin_panic with the new ABI, +// and we can remove the temporary begin_panic_new function. + +/// This is the entry point of panicking for panic!() and assert!(). +#[unstable(feature = "libstd_sys_internals", + reason = "used by the panic! macro", + issue = "0")] +#[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible +pub fn begin_panic_new<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! { + // Note that this should be the only allocation performed in this code path. + // Currently this means that panic!() on OOM will invoke this code path, + // but then again we're not really ready for panic on OOM anyway. If + // we do start doing this, then we should propagate this allocation to + // be performed in the parent of this thread instead of the thread that's + // panicking. + + rust_panic_with_hook(Box::new(msg), file_line_col) } /// This is the entry point of panicking for panic!() and assert!(). @@ -508,7 +566,10 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line: &(&'static str, u32)) -> ! // be performed in the parent of this thread instead of the thread that's // panicking. - rust_panic_with_hook(Box::new(msg), file_line) + let (file, line) = *file_line; + let file_line_col = (file, line, 0); + + rust_panic_with_hook(Box::new(msg), &file_line_col) } /// Executes the primary logic for a panic, including checking for recursive @@ -520,8 +581,8 @@ pub fn begin_panic<M: Any + Send>(msg: M, file_line: &(&'static str, u32)) -> ! #[inline(never)] #[cold] fn rust_panic_with_hook(msg: Box<Any + Send>, - file_line: &(&'static str, u32)) -> ! { - let (file, line) = *file_line; + file_line_col: &(&'static str, u32, u32)) -> ! { + let (file, line, col) = *file_line_col; let panics = update_panic_count(1); @@ -540,8 +601,9 @@ fn rust_panic_with_hook(msg: Box<Any + Send>, let info = PanicInfo { payload: &*msg, location: Location { - file: file, - line: line, + file, + line, + col, }, }; HOOK_LOCK.read(); diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 42a54ed6d75..e7c7be981d2 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -276,7 +276,7 @@ impl<'a> Prefix<'a> { /// ``` /// use std::path; /// -/// assert!(path::is_separator('/')); +/// assert!(path::is_separator('/')); // '/' works for both Unix and Windows /// assert!(!path::is_separator('❤')); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -1348,10 +1348,10 @@ impl From<Box<Path>> for PathBuf { } } -#[stable(feature = "box_from_path_buf", since = "1.18.0")] -impl Into<Box<Path>> for PathBuf { - fn into(self) -> Box<Path> { - self.into_boxed_path() +#[stable(feature = "box_from_path_buf", since = "1.20.0")] +impl From<PathBuf> for Box<Path> { + fn from(p: PathBuf) -> Box<Path> { + p.into_boxed_path() } } @@ -1499,9 +1499,9 @@ impl AsRef<OsStr> for PathBuf { /// A slice of a path (akin to [`str`]). /// /// This type supports a number of operations for inspecting a path, including -/// breaking the path into its components (separated by `/` or `\`, depending on -/// the platform), extracting the file name, determining whether the path is -/// absolute, and so on. +/// breaking the path into its components (separated by `/` on Unix and by either +/// `/` or `\` on Windows), extracting the file name, determining whether the path +/// is absolute, and so on. /// /// This is an *unsized* type, meaning that it must always be used behind a /// pointer like `&` or [`Box`]. For an owned version of this type, @@ -1520,10 +1520,11 @@ impl AsRef<OsStr> for PathBuf { /// use std::path::Path; /// use std::ffi::OsStr; /// -/// let path = Path::new("/tmp/foo/bar.txt"); +/// // Note: this example does work on Windows +/// let path = Path::new("./foo/bar.txt"); /// /// let parent = path.parent(); -/// assert_eq!(parent, Some(Path::new("/tmp/foo"))); +/// assert_eq!(parent, Some(Path::new("./foo"))); /// /// let file_stem = path.file_stem(); /// assert_eq!(file_stem, Some(OsStr::new("bar"))); diff --git a/src/libstd/process.rs b/src/libstd/process.rs index df6a648b7b1..7adfcc44ad0 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -447,8 +447,6 @@ impl Command { /// Basic usage: /// /// ```no_run - /// #![feature(command_envs)] - /// /// use std::process::{Command, Stdio}; /// use std::env; /// use std::collections::HashMap; @@ -466,7 +464,7 @@ impl Command { /// .spawn() /// .expect("printenv failed to start"); /// ``` - #[unstable(feature = "command_envs", issue = "38526")] + #[stable(feature = "command_envs", since = "1.19.0")] pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command where I: IntoIterator<Item=(K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr> { diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 06fd838ea06..2ee63527c14 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -25,7 +25,7 @@ // Reexport some of our utilities which are expected by other crates. -pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; +pub use panicking::{begin_panic_new, begin_panic, begin_panic_fmt, update_panic_count}; #[cfg(not(test))] #[lang = "start"] diff --git a/src/libstd/sys/redox/fast_thread_local.rs b/src/libstd/sys/redox/fast_thread_local.rs index 7dc61ce6654..9f0eee024d5 100644 --- a/src/libstd/sys/redox/fast_thread_local.rs +++ b/src/libstd/sys/redox/fast_thread_local.rs @@ -57,7 +57,7 @@ impl<T> Key<T> { } } -unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { +pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { // The fallback implementation uses a vanilla OS-based TLS key to track // the list of destructors that need to be run for this thread. The key // then has its own destructor which runs all the other destructors. @@ -115,3 +115,7 @@ pub unsafe extern fn destroy_value<T>(ptr: *mut u8) { ptr::drop_in_place((*ptr).inner.get()); } } + +pub fn requires_move_before_drop() -> bool { + false +} diff --git a/src/libstd/sys/redox/fs.rs b/src/libstd/sys/redox/fs.rs index 48d9cdcb2c9..c5a19e8debe 100644 --- a/src/libstd/sys/redox/fs.rs +++ b/src/libstd/sys/redox/fs.rs @@ -420,12 +420,19 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { } pub fn readlink(p: &Path) -> io::Result<PathBuf> { - canonicalize(p) -} - -pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { - ::sys_common::util::dumb_print(format_args!("Symlink\n")); - unimplemented!(); + let fd = cvt(syscall::open(p.to_str().unwrap(), syscall::O_SYMLINK | syscall::O_RDONLY))?; + let mut buf: [u8; 4096] = [0; 4096]; + let count = cvt(syscall::read(fd, &mut buf))?; + cvt(syscall::close(fd))?; + Ok(PathBuf::from(unsafe { String::from_utf8_unchecked(Vec::from(&buf[..count])) })) +} + +pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { + let fd = cvt(syscall::open(dst.to_str().unwrap(), + syscall::O_SYMLINK | syscall::O_CREAT | syscall::O_WRONLY | 0o777))?; + cvt(syscall::write(fd, src.to_str().unwrap().as_bytes()))?; + cvt(syscall::close(fd))?; + Ok(()) } pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> { diff --git a/src/libstd/sys/redox/net/tcp.rs b/src/libstd/sys/redox/net/tcp.rs index ac3fd2ad6b9..17673f0bd60 100644 --- a/src/libstd/sys/redox/net/tcp.rs +++ b/src/libstd/sys/redox/net/tcp.rs @@ -17,7 +17,6 @@ use sys::fs::{File, OpenOptions}; use sys::syscall::TimeSpec; use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; -use vec::Vec; use super::{path_to_peer_addr, path_to_local_addr}; diff --git a/src/libstd/sys/redox/pipe.rs b/src/libstd/sys/redox/pipe.rs index 05863adf108..28645facd93 100644 --- a/src/libstd/sys/redox/pipe.rs +++ b/src/libstd/sys/redox/pipe.rs @@ -49,8 +49,8 @@ pub fn read2(p1: AnonPipe, //FIXME: Use event based I/O multiplexing //unimplemented!() - p1.read_to_end(v1)?; - p2.read_to_end(v2)?; + p1.0.read_to_end(v1)?; + p2.0.read_to_end(v2)?; Ok(()) diff --git a/src/libstd/sys/redox/syscall/flag.rs b/src/libstd/sys/redox/syscall/flag.rs index 9f0d3e6f779..bd603cfe6ef 100644 --- a/src/libstd/sys/redox/syscall/flag.rs +++ b/src/libstd/sys/redox/syscall/flag.rs @@ -33,6 +33,7 @@ pub const MAP_WRITE_COMBINE: usize = 2; pub const MODE_TYPE: u16 = 0xF000; pub const MODE_DIR: u16 = 0x4000; pub const MODE_FILE: u16 = 0x8000; +pub const MODE_SYMLINK: u16 = 0xA000; pub const MODE_PERM: u16 = 0x0FFF; pub const MODE_SETUID: u16 = 0o4000; @@ -53,6 +54,7 @@ pub const O_TRUNC: usize = 0x0400_0000; pub const O_EXCL: usize = 0x0800_0000; pub const O_DIRECTORY: usize = 0x1000_0000; pub const O_STAT: usize = 0x2000_0000; +pub const O_SYMLINK: usize = 0x4000_0000; pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR; pub const SEEK_SET: usize = 0; diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 743b7c3220a..f4fe52ca3b3 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -825,8 +825,6 @@ pub fn park_timeout(dur: Duration) { /// # Examples /// /// ``` -/// #![feature(thread_id)] -/// /// use std::thread; /// /// let other_thread = thread::spawn(|| { @@ -836,7 +834,7 @@ pub fn park_timeout(dur: Duration) { /// let other_thread_id = other_thread.join().unwrap(); /// assert!(thread::current().id() != other_thread_id); /// ``` -#[unstable(feature = "thread_id", issue = "21507")] +#[stable(feature = "thread_id", since = "1.19.0")] #[derive(Eq, PartialEq, Clone, Copy, Hash, Debug)] pub struct ThreadId(u64); @@ -966,8 +964,6 @@ impl Thread { /// # Examples /// /// ``` - /// #![feature(thread_id)] - /// /// use std::thread; /// /// let other_thread = thread::spawn(|| { @@ -977,7 +973,7 @@ impl Thread { /// let other_thread_id = other_thread.join().unwrap(); /// assert!(thread::current().id() != other_thread_id); /// ``` - #[unstable(feature = "thread_id", issue = "21507")] + #[stable(feature = "thread_id", since = "1.19.0")] pub fn id(&self) -> ThreadId { self.inner.id } @@ -1168,8 +1164,6 @@ impl<T> JoinHandle<T> { /// # Examples /// /// ``` - /// #![feature(thread_id)] - /// /// use std::thread; /// /// let builder = thread::Builder::new(); |
