From 7eb9a091f3ab8e77978ad5c8369f2fb4bedc2610 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Wed, 28 Mar 2018 18:54:34 +0100 Subject: [PATCH 01/23] std: Child::kill() returns error if process has already exited This patch makes it clear in std::process::Child::kill()'s API documentation that an error is returned if the child process has already cleanly exited. This is implied by the example, but not called out explicitly. --- src/libstd/process.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 92e9f48f7ebe..b3cb8d745b46 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1121,8 +1121,9 @@ impl ExitCode { } impl Child { - /// Forces the child to exit. This is equivalent to sending a - /// SIGKILL on unix platforms. + /// Forces the child process to exit. If the child has already exited, an error is returned. + /// + /// This is equivalent to sending a SIGKILL on Unix platforms. /// /// # Examples /// From d541282d6c578fcb09000bd4747dd7f08ccd3805 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Wed, 28 Mar 2018 23:05:51 +0100 Subject: [PATCH 02/23] fixup! std: Child::kill() returns error if process has already exited --- src/libstd/process.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index b3cb8d745b46..4d4a48bd2da8 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1121,7 +1121,8 @@ impl ExitCode { } impl Child { - /// Forces the child process to exit. If the child has already exited, an error is returned. + /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] + /// error might be returned. /// /// This is equivalent to sending a SIGKILL on Unix platforms. /// @@ -1139,6 +1140,8 @@ impl Child { /// println!("yes command didn't start"); /// } /// ``` + /// + /// [`InvalidInput`]: ../io/enum.ErrorKind.html#variant.InvalidInput #[stable(feature = "process", since = "1.0.0")] pub fn kill(&mut self) -> io::Result<()> { self.handle.kill() From 51dc6304e71b95ad26f697db56c0bc2e6df5dd47 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Thu, 29 Mar 2018 18:10:40 +0100 Subject: [PATCH 03/23] fixup! std: Child::kill() returns error if process has already exited --- src/libstd/process.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 4d4a48bd2da8..c3d681a89626 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1122,7 +1122,10 @@ impl ExitCode { impl Child { /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] - /// error might be returned. + /// error is returned. + /// + /// The mapping to [`ErrorKind`]s is not part of the compatibility contract of the function, + /// especially the [`Other`] kind might change to more specific kinds in the future. /// /// This is equivalent to sending a SIGKILL on Unix platforms. /// @@ -1141,7 +1144,9 @@ impl Child { /// } /// ``` /// + /// [`ErrorKind`]: ../io/enum.ErrorKind.html /// [`InvalidInput`]: ../io/enum.ErrorKind.html#variant.InvalidInput + /// [`Other]: ../io/enum.ErrorKind.html#variant.Other #[stable(feature = "process", since = "1.0.0")] pub fn kill(&mut self) -> io::Result<()> { self.handle.kill() From f86deef5b6059b9a0a76d9f0dafb95ced85f7449 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 6 Apr 2018 15:02:21 +0200 Subject: [PATCH 04/23] Add Cell::update --- src/libcore/cell.rs | 24 ++++++++++++++++++++++++ src/libcore/tests/cell.rs | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index c8ee166fee3e..2ea1b84d0340 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -256,6 +256,30 @@ impl Cell { pub fn get(&self) -> T { unsafe{ *self.value.get() } } + + /// Applies a function to the contained value. + /// + /// # Examples + /// + /// ``` + /// use std::cell::Cell; + /// + /// let c = Cell::new(5); + /// c.update(|x| x + 1); + /// + /// assert_eq!(c.get(), 6); + /// ``` + #[inline] + #[unstable(feature = "cell_update", issue = "0")] // TODO: issue + pub fn update(&self, f: F) -> T + where + F: FnOnce(T) -> T, + { + let old = self.get(); + let new = f(old); + self.set(new); + new + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/tests/cell.rs b/src/libcore/tests/cell.rs index cc0ef6a6f17e..962fb2f0e027 100644 --- a/src/libcore/tests/cell.rs +++ b/src/libcore/tests/cell.rs @@ -26,6 +26,17 @@ fn smoketest_cell() { assert!(y.get() == (30, 40)); } +#[test] +fn cell_update() { + let x = Cell::new(10); + + assert_eq!(x.update(|x| x + 5), 15); + assert_eq!(x.get(), 15); + + assert_eq!(x.update(|x| x / 3), 5); + assert_eq!(x.get(), 5); +} + #[test] fn cell_has_sensible_show() { let x = Cell::new("foo bar"); From 9377340ee3f638fcb011afd5a818d6e6b66c2d27 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 6 Apr 2018 15:29:10 +0200 Subject: [PATCH 05/23] Change TODO to FIXME --- src/libcore/cell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 2ea1b84d0340..c0f7183b06c7 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -270,7 +270,7 @@ pub fn get(&self) -> T { /// assert_eq!(c.get(), 6); /// ``` #[inline] - #[unstable(feature = "cell_update", issue = "0")] // TODO: issue + #[unstable(feature = "cell_update", issue = "0")] // FIXME: issue pub fn update(&self, f: F) -> T where F: FnOnce(T) -> T, From 5dcce519469690d09704b82d53417b67915adb94 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 6 Apr 2018 22:45:31 +0200 Subject: [PATCH 06/23] Fix the failing tests --- src/libcore/cell.rs | 2 ++ src/libcore/tests/lib.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index c0f7183b06c7..e4a52d9c4a40 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -262,6 +262,8 @@ pub fn get(&self) -> T { /// # Examples /// /// ``` + /// #![feature(cell_update)] + /// /// use std::cell::Cell; /// /// let c = Cell::new(5); diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index de7211e718c9..13c53f47b696 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -12,6 +12,7 @@ #![feature(ascii_ctype)] #![feature(box_syntax)] +#![feature(cell_update)] #![feature(core_float)] #![feature(core_private_bignum)] #![feature(core_private_diy_float)] From fd2afa01aa614114811ff68ed31c146f7aab1d28 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Sun, 8 Apr 2018 16:20:15 +0100 Subject: [PATCH 07/23] fixup! std: Child::kill() returns error if process has already exited --- src/libstd/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index c3d681a89626..60759de8afc3 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1146,7 +1146,7 @@ impl Child { /// /// [`ErrorKind`]: ../io/enum.ErrorKind.html /// [`InvalidInput`]: ../io/enum.ErrorKind.html#variant.InvalidInput - /// [`Other]: ../io/enum.ErrorKind.html#variant.Other + /// [`Other`]: ../io/enum.ErrorKind.html#variant.Other #[stable(feature = "process", since = "1.0.0")] pub fn kill(&mut self) -> io::Result<()> { self.handle.kill() From 182d99cfd1a551b9daa3d7f6896775278fb2962e Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 9 Apr 2018 17:44:28 -0700 Subject: [PATCH 08/23] Add doc links to `std::os` extension traits Add documentation links to the original type for various OS-specific extension traits and normalize the language for introducing such traits. Also, remove some outdated comments around the extension trait definitions. --- src/libstd/os/android/fs.rs | 4 ++- src/libstd/os/bitrig/fs.rs | 4 ++- src/libstd/os/dragonfly/fs.rs | 4 ++- src/libstd/os/emscripten/fs.rs | 4 ++- src/libstd/os/freebsd/fs.rs | 4 ++- src/libstd/os/fuchsia/fs.rs | 4 ++- src/libstd/os/haiku/fs.rs | 4 ++- src/libstd/os/ios/fs.rs | 4 ++- src/libstd/os/linux/fs.rs | 4 ++- src/libstd/os/macos/fs.rs | 4 ++- src/libstd/os/netbsd/fs.rs | 4 ++- src/libstd/os/openbsd/fs.rs | 4 ++- src/libstd/os/solaris/fs.rs | 4 ++- src/libstd/sys/redox/ext/ffi.rs | 10 +++++--- src/libstd/sys/redox/ext/fs.rs | 36 +++++++++++++++++++-------- src/libstd/sys/redox/ext/process.rs | 10 +++++--- src/libstd/sys/redox/ext/thread.rs | 6 +++-- src/libstd/sys/unix/ext/ffi.rs | 8 ++++-- src/libstd/sys/unix/ext/fs.rs | 33 +++++++++++++----------- src/libstd/sys/unix/ext/process.rs | 8 ++++-- src/libstd/sys/unix/ext/thread.rs | 4 ++- src/libstd/sys/windows/ext/ffi.rs | 8 ++++-- src/libstd/sys/windows/ext/fs.rs | 20 ++++++++------- src/libstd/sys/windows/ext/process.rs | 8 ++++-- 24 files changed, 139 insertions(+), 64 deletions(-) diff --git a/src/libstd/os/android/fs.rs b/src/libstd/os/android/fs.rs index a51b46559859..5899dc688e22 100644 --- a/src/libstd/os/android/fs.rs +++ b/src/libstd/os/android/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::android::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/bitrig/fs.rs b/src/libstd/os/bitrig/fs.rs index e4f1c9432f3f..24caf326ab0f 100644 --- a/src/libstd/os/bitrig/fs.rs +++ b/src/libstd/os/bitrig/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::bitrig::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/dragonfly/fs.rs b/src/libstd/os/dragonfly/fs.rs index db672e564353..6aea450774ff 100644 --- a/src/libstd/os/dragonfly/fs.rs +++ b/src/libstd/os/dragonfly/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::dragonfly::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/emscripten/fs.rs b/src/libstd/os/emscripten/fs.rs index 8056ce4fdc4e..e0e197dc122a 100644 --- a/src/libstd/os/emscripten/fs.rs +++ b/src/libstd/os/emscripten/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::emscripten::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/freebsd/fs.rs b/src/libstd/os/freebsd/fs.rs index 2f17d2f74094..5f24cd636d54 100644 --- a/src/libstd/os/freebsd/fs.rs +++ b/src/libstd/os/freebsd/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::freebsd::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/fuchsia/fs.rs b/src/libstd/os/fuchsia/fs.rs index d22f9a628bd1..16802576356d 100644 --- a/src/libstd/os/fuchsia/fs.rs +++ b/src/libstd/os/fuchsia/fs.rs @@ -13,7 +13,9 @@ use fs::Metadata; use sys_common::AsInner; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { #[stable(feature = "metadata_ext2", since = "1.8.0")] diff --git a/src/libstd/os/haiku/fs.rs b/src/libstd/os/haiku/fs.rs index 54f8ea1b71b3..453136e0ac86 100644 --- a/src/libstd/os/haiku/fs.rs +++ b/src/libstd/os/haiku/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::haiku::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/ios/fs.rs b/src/libstd/os/ios/fs.rs index 275daf3d3a0a..296ce69ff436 100644 --- a/src/libstd/os/ios/fs.rs +++ b/src/libstd/os/ios/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::ios::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/linux/fs.rs b/src/libstd/os/linux/fs.rs index 2be2fbcb2dbf..76fb10da850b 100644 --- a/src/libstd/os/linux/fs.rs +++ b/src/libstd/os/linux/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::linux::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/macos/fs.rs b/src/libstd/os/macos/fs.rs index 12b44901d03d..0b14c05cb551 100644 --- a/src/libstd/os/macos/fs.rs +++ b/src/libstd/os/macos/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::macos::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/netbsd/fs.rs b/src/libstd/os/netbsd/fs.rs index cd7d5fafd1c8..e9cad33fee61 100644 --- a/src/libstd/os/netbsd/fs.rs +++ b/src/libstd/os/netbsd/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::netbsd::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/openbsd/fs.rs b/src/libstd/os/openbsd/fs.rs index cc812fcf12cf..0f6b83b6e324 100644 --- a/src/libstd/os/openbsd/fs.rs +++ b/src/libstd/os/openbsd/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::openbsd::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/os/solaris/fs.rs b/src/libstd/os/solaris/fs.rs index 5dc43d03a866..19dce1ba34c7 100644 --- a/src/libstd/os/solaris/fs.rs +++ b/src/libstd/os/solaris/fs.rs @@ -18,7 +18,9 @@ #[allow(deprecated)] use os::solaris::raw; -/// OS-specific extension methods for `fs::Metadata` +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Gain a reference to the underlying `stat` structure which contains diff --git a/src/libstd/sys/redox/ext/ffi.rs b/src/libstd/sys/redox/ext/ffi.rs index d59b4fc0b70b..060edbd22e48 100644 --- a/src/libstd/sys/redox/ext/ffi.rs +++ b/src/libstd/sys/redox/ext/ffi.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Unix-specific extension to the primitives in the `std::ffi` module +//! Redox-specific extension to the primitives in the `std::ffi` module. #![stable(feature = "rust1", since = "1.0.0")] @@ -17,7 +17,9 @@ use sys::os_str::Buf; use sys_common::{FromInner, IntoInner, AsInner}; -/// Unix-specific extensions to `OsString`. +/// Redox-specific extensions to [`ffi::OsString`]. +/// +/// [`ffi::OsString`]: ../../../../std/ffi/struct.OsString.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { /// Creates an `OsString` from a byte vector. @@ -39,7 +41,9 @@ fn into_vec(self) -> Vec { } } -/// Unix-specific extensions to `OsStr`. +/// Redox-specific extensions to [`ffi::OsStr`]. +/// +/// [`ffi::OsStr`]: ../../../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/redox/ext/fs.rs b/src/libstd/sys/redox/ext/fs.rs index 0f4762aa8810..b39c6f5d0225 100644 --- a/src/libstd/sys/redox/ext/fs.rs +++ b/src/libstd/sys/redox/ext/fs.rs @@ -18,7 +18,9 @@ use sys; use sys_common::{FromInner, AsInner, AsInnerMut}; -/// Redox-specific extensions to `Permissions` +/// Redox-specific extensions to [`fs::Permissions`]. +/// +/// [`fs::Permissions`]: ../../../../std/fs/struct.Permissions.html #[stable(feature = "fs_ext", since = "1.1.0")] pub trait PermissionsExt { /// Returns the underlying raw `mode_t` bits that are the standard Redox @@ -95,7 +97,9 @@ fn from_mode(mode: u32) -> Permissions { } } -/// Redox-specific extensions to `OpenOptions` +/// Redox-specific extensions to [`fs::OpenOptions`]. +/// +/// [`fs::OpenOptions`]: ../../../../std/fs/struct.OpenOptions.html #[stable(feature = "fs_ext", since = "1.1.0")] pub trait OpenOptionsExt { /// Sets the mode bits that a new file will be created with. @@ -163,13 +167,9 @@ fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions { } } -// Hm, why are there casts here to the returned type, shouldn't the types always -// be the same? Right you are! Turns out, however, on android at least the types -// in the raw `stat` structure are not the same as the types being returned. Who -// knew! -// -// As a result to make sure this compiles for all platforms we do the manual -// casts and rely on manual lowering to `stat` if the raw type is desired. +/// Redox-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { #[stable(feature = "metadata_ext", since = "1.1.0")] @@ -204,6 +204,13 @@ pub trait MetadataExt { fn blocks(&self) -> u64; } +// Hm, why are there casts here to the returned type, shouldn't the types always +// be the same? Right you are! Turns out, however, on android at least the types +// in the raw `stat` structure are not the same as the types being returned. Who +// knew! +// +// As a result to make sure this compiles for all platforms we do the manual +// casts and rely on manual lowering to `stat` if the raw type is desired. #[stable(feature = "metadata_ext", since = "1.1.0")] impl MetadataExt for fs::Metadata { fn dev(&self) -> u64 { @@ -253,7 +260,12 @@ fn blocks(&self) -> u64 { } } -/// Add special Redox types (block/char device, fifo and socket) +/// Redox-specific extensions for [`fs::FileType`]. +/// +/// Adds support for special Unix file types such as block/character devices, +/// pipes, and sockets. +/// +/// [`fs::FileType`]: ../../../../std/fs/struct.FileType.html #[stable(feature = "file_type_ext", since = "1.5.0")] pub trait FileTypeExt { /// Returns whether this file type is a block device. @@ -307,8 +319,10 @@ pub fn symlink, Q: AsRef>(src: P, dst: Q) -> io::Result<()> sys::fs::symlink(src.as_ref(), dst.as_ref()) } +/// Redox-specific extensions to [`fs::DirBuilder`]. +/// +/// [`fs::DirBuilder`]: ../../../../std/fs/struct.DirBuilder.html #[stable(feature = "dir_builder", since = "1.6.0")] -/// An extension trait for `fs::DirBuilder` for Redox-specific options. pub trait DirBuilderExt { /// Sets the mode to create new directories with. This option defaults to /// 0o777. diff --git a/src/libstd/sys/redox/ext/process.rs b/src/libstd/sys/redox/ext/process.rs index e68e180acf1c..608740a5cf70 100644 --- a/src/libstd/sys/redox/ext/process.rs +++ b/src/libstd/sys/redox/ext/process.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Unix-specific extensions to primitives in the `std::process` module. +//! Redox-specific extensions to primitives in the `std::process` module. #![stable(feature = "rust1", since = "1.0.0")] @@ -18,7 +18,9 @@ use sys; use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner}; -/// Unix-specific extensions to the `std::process::Command` builder +/// Redox-specific extensions to the [`process::Command`] builder. +/// +/// [`process::Command`]: ../../../../std/process/struct.Command.html #[stable(feature = "rust1", since = "1.0.0")] pub trait CommandExt { /// Sets the child process's user id. This translates to a @@ -107,7 +109,9 @@ fn exec(&mut self) -> io::Error { } } -/// Unix-specific extensions to `std::process::ExitStatus` +/// Redox-specific extensions to [`process::ExitStatus`]. +/// +/// [`process::ExitStatus`]: ../../../../std/process/struct.ExitStatus.html #[stable(feature = "rust1", since = "1.0.0")] pub trait ExitStatusExt { /// Creates a new `ExitStatus` from the raw underlying `i32` return value of diff --git a/src/libstd/sys/redox/ext/thread.rs b/src/libstd/sys/redox/ext/thread.rs index 52be2ccd9f96..71ff0d46b91e 100644 --- a/src/libstd/sys/redox/ext/thread.rs +++ b/src/libstd/sys/redox/ext/thread.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Unix-specific extensions to primitives in the `std::thread` module. +//! Redox-specific extensions to primitives in the `std::thread` module. #![stable(feature = "thread_extensions", since = "1.9.0")] @@ -19,7 +19,9 @@ #[allow(deprecated)] pub type RawPthread = usize; -/// Unix-specific extensions to `std::thread::JoinHandle` +/// Redox-specific extensions to [`thread::JoinHandle`]. +/// +/// [`thread::JoinHandle`]: ../../../../std/thread/struct.JoinHandle.html #[stable(feature = "thread_extensions", since = "1.9.0")] pub trait JoinHandleExt { /// Extracts the raw pthread_t without taking ownership diff --git a/src/libstd/sys/unix/ext/ffi.rs b/src/libstd/sys/unix/ext/ffi.rs index fb9984ccbdda..3103ad0416ec 100644 --- a/src/libstd/sys/unix/ext/ffi.rs +++ b/src/libstd/sys/unix/ext/ffi.rs @@ -17,7 +17,9 @@ use sys::os_str::Buf; use sys_common::{FromInner, IntoInner, AsInner}; -/// Unix-specific extensions to `OsString`. +/// Unix-specific extensions to [`ffi::OsString`]. +/// +/// [`ffi::OsString`]: ../../../../std/ffi/struct.OsString.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { /// Creates an [`OsString`] from a byte vector. @@ -66,7 +68,9 @@ fn into_vec(self) -> Vec { } } -/// Unix-specific extensions to `OsStr`. +/// Unix-specific extensions to [`ffi::OsStr`]. +/// +/// [`ffi::OsStr`]: ../../../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 3c5b9424fb06..844e0106df0f 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -20,9 +20,9 @@ use sys_common::{FromInner, AsInner, AsInnerMut}; use sys::platform::fs::MetadataExt as UnixMetadataExt; -/// Unix-specific extensions to [`File`]. +/// Unix-specific extensions to [`fs::File`]. /// -/// [`File`]: ../../../../std/fs/struct.File.html +/// [`fs::File`]: ../../../../std/fs/struct.File.html #[stable(feature = "file_offset", since = "1.15.0")] pub trait FileExt { /// Reads a number of bytes starting from a given offset. @@ -105,7 +105,9 @@ fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { } } -/// Unix-specific extensions to `Permissions` +/// Unix-specific extensions to [`fs::Permissions`]. +/// +/// [`fs::Permissions`]: ../../../../std/fs/struct.Permissions.html #[stable(feature = "fs_ext", since = "1.1.0")] pub trait PermissionsExt { /// Returns the underlying raw `st_mode` bits that contain the standard @@ -180,7 +182,9 @@ fn from_mode(mode: u32) -> Permissions { } } -/// Unix-specific extensions to `OpenOptions` +/// Unix-specific extensions to [`fs::OpenOptions`]. +/// +/// [`fs::OpenOptions`]: ../../../../std/fs/struct.OpenOptions.html #[stable(feature = "fs_ext", since = "1.1.0")] pub trait OpenOptionsExt { /// Sets the mode bits that a new file will be created with. @@ -246,13 +250,9 @@ fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions { } } -// Hm, why are there casts here to the returned type, shouldn't the types always -// be the same? Right you are! Turns out, however, on android at least the types -// in the raw `stat` structure are not the same as the types being returned. Who -// knew! -// -// As a result to make sure this compiles for all platforms we do the manual -// casts and rely on manual lowering to `stat` if the raw type is desired. +/// Unix-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Returns the ID of the device containing the file. @@ -555,7 +555,12 @@ fn blksize(&self) -> u64 { self.st_blksize() } fn blocks(&self) -> u64 { self.st_blocks() } } -/// Add support for special unix types (block/char device, fifo and socket). +/// Unix-specific extensions for [`fs::FileType`]. +/// +/// Adds support for special Unix file types such as block/character devices, +/// pipes, and sockets. +/// +/// [`fs::FileType`]: ../../../../std/fs/struct.FileType.html #[stable(feature = "file_type_ext", since = "1.5.0")] pub trait FileTypeExt { /// Returns whether this file type is a block device. @@ -701,10 +706,10 @@ pub fn symlink, Q: AsRef>(src: P, dst: Q) -> io::Result<()> sys::fs::symlink(src.as_ref(), dst.as_ref()) } -#[stable(feature = "dir_builder", since = "1.6.0")] -/// An extension trait for [`fs::DirBuilder`] for unix-specific options. +/// Unix-specific extensions to [`fs::DirBuilder`]. /// /// [`fs::DirBuilder`]: ../../../../std/fs/struct.DirBuilder.html +#[stable(feature = "dir_builder", since = "1.6.0")] pub trait DirBuilderExt { /// Sets the mode to create new directories with. This option defaults to /// 0o777. diff --git a/src/libstd/sys/unix/ext/process.rs b/src/libstd/sys/unix/ext/process.rs index 7b4ec20d91fb..21630ae9746f 100644 --- a/src/libstd/sys/unix/ext/process.rs +++ b/src/libstd/sys/unix/ext/process.rs @@ -18,7 +18,9 @@ use sys; use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner}; -/// Unix-specific extensions to the `std::process::Command` builder +/// Unix-specific extensions to the [`process::Command`] builder. +/// +/// [`process::Command`]: ../../../../std/process/struct.Command.html #[stable(feature = "rust1", since = "1.0.0")] pub trait CommandExt { /// Sets the child process's user id. This translates to a @@ -117,7 +119,9 @@ fn exec(&mut self) -> io::Error { } } -/// Unix-specific extensions to `std::process::ExitStatus` +/// Unix-specific extensions to [`process::ExitStatus`]. +/// +/// [`process::ExitStatus`]: ../../../../std/process/struct.ExitStatus.html #[stable(feature = "rust1", since = "1.0.0")] pub trait ExitStatusExt { /// Creates a new `ExitStatus` from the raw underlying `i32` return value of diff --git a/src/libstd/sys/unix/ext/thread.rs b/src/libstd/sys/unix/ext/thread.rs index fe2a48764dc3..8dadf29945c1 100644 --- a/src/libstd/sys/unix/ext/thread.rs +++ b/src/libstd/sys/unix/ext/thread.rs @@ -21,7 +21,9 @@ #[allow(deprecated)] pub type RawPthread = pthread_t; -/// Unix-specific extensions to `std::thread::JoinHandle` +/// Unix-specific extensions to [`thread::JoinHandle`]. +/// +/// [`thread::JoinHandle`]: ../../../../std/thread/struct.JoinHandle.html #[stable(feature = "thread_extensions", since = "1.9.0")] pub trait JoinHandleExt { /// Extracts the raw pthread_t without taking ownership diff --git a/src/libstd/sys/windows/ext/ffi.rs b/src/libstd/sys/windows/ext/ffi.rs index d6b8896ac096..b3f7635efd33 100644 --- a/src/libstd/sys/windows/ext/ffi.rs +++ b/src/libstd/sys/windows/ext/ffi.rs @@ -76,7 +76,9 @@ #[stable(feature = "rust1", since = "1.0.0")] pub use sys_common::wtf8::EncodeWide; -/// Windows-specific extensions to `OsString`. +/// Windows-specific extensions to [`ffi::OsString`]. +/// +/// [`ffi::OsString`]: ../../../../std/ffi/struct.OsString.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { /// Creates an `OsString` from a potentially ill-formed UTF-16 slice of @@ -109,7 +111,9 @@ fn from_wide(wide: &[u16]) -> OsString { } } -/// Windows-specific extensions to `OsStr`. +/// Windows-specific extensions to [`ffi::OsStr`]. +/// +/// [`ffi::OsStr`]: ../../../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { /// Re-encodes an `OsStr` as a wide character sequence, i.e. potentially diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index e5cd51b6550b..5daeb5282cd1 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -18,9 +18,9 @@ use sys; use sys_common::{AsInnerMut, AsInner}; -/// Windows-specific extensions to [`File`]. +/// Windows-specific extensions to [`fs::File`]. /// -/// [`File`]: ../../../fs/struct.File.html +/// [`fs::File`]: ../../../fs/struct.File.html #[stable(feature = "file_offset", since = "1.15.0")] pub trait FileExt { /// Seeks to a given position and reads a number of bytes. @@ -103,9 +103,9 @@ fn seek_write(&self, buf: &[u8], offset: u64) -> io::Result { } } -/// Windows-specific extensions to [`OpenOptions`]. +/// Windows-specific extensions to [`fs::OpenOptions`]. /// -/// [`OpenOptions`]: ../../../fs/struct.OpenOptions.html +/// [`fs::OpenOptions`]: ../../../../std/fs/struct.OpenOptions.html #[stable(feature = "open_options_ext", since = "1.10.0")] pub trait OpenOptionsExt { /// Overrides the `dwDesiredAccess` argument to the call to [`CreateFile`] @@ -281,13 +281,12 @@ fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions { } } -/// Extension methods for [`fs::Metadata`] to access the raw fields contained -/// within. +/// Windows-specific extensions to [`fs::Metadata`]. /// /// The data members that this trait exposes correspond to the members /// of the [`BY_HANDLE_FILE_INFORMATION`] structure. /// -/// [`fs::Metadata`]: ../../../fs/struct.Metadata.html +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html /// [`BY_HANDLE_FILE_INFORMATION`]: /// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx #[stable(feature = "metadata_ext", since = "1.1.0")] @@ -445,8 +444,11 @@ fn last_write_time(&self) -> u64 { self.as_inner().modified_u64() } fn file_size(&self) -> u64 { self.as_inner().size() } } -/// Add support for the Windows specific fact that a symbolic link knows whether it is a file -/// or directory. +/// Windows-specific extensions to [`fs::FileType`]. +/// +/// On Windows, a symbolic link knows whether it is a file or directory. +/// +/// [`fs::FileType`]: ../../../../std/fs/struct.FileType.html #[unstable(feature = "windows_file_type_ext", issue = "0")] pub trait FileTypeExt { /// Returns whether this file type is a symbolic link that is also a directory. diff --git a/src/libstd/sys/windows/ext/process.rs b/src/libstd/sys/windows/ext/process.rs index 759f055c4b12..a02bcbe0c87c 100644 --- a/src/libstd/sys/windows/ext/process.rs +++ b/src/libstd/sys/windows/ext/process.rs @@ -82,7 +82,9 @@ fn into_raw_handle(self) -> RawHandle { } } -/// Windows-specific extensions to `std::process::ExitStatus` +/// Windows-specific extensions to [`process::ExitStatus`]. +/// +/// [`process::ExitStatus`]: ../../../../std/process/struct.ExitStatus.html #[stable(feature = "exit_status_from", since = "1.12.0")] pub trait ExitStatusExt { /// Creates a new `ExitStatus` from the raw underlying `u32` return value of @@ -98,7 +100,9 @@ fn from_raw(raw: u32) -> Self { } } -/// Windows-specific extensions to the `std::process::Command` builder +/// Windows-specific extensions to the [`process::Command`] builder. +/// +/// [`process::Command`]: ../../../../std/process/struct.Command.html #[stable(feature = "windows_process_extensions", since = "1.16.0")] pub trait CommandExt { /// Sets the [process creation flags][1] to be passed to `CreateProcess`. From d5bee64df400126279e71562352936d5e4d14433 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 10 Apr 2018 17:03:07 -0700 Subject: [PATCH 09/23] Prefer unprefixed paths for well known structs --- src/libstd/sys/redox/ext/ffi.rs | 8 ++++---- src/libstd/sys/redox/ext/fs.rs | 4 ++-- src/libstd/sys/redox/ext/process.rs | 2 +- src/libstd/sys/unix/ext/ffi.rs | 8 ++++---- src/libstd/sys/unix/ext/fs.rs | 8 ++++---- src/libstd/sys/windows/ext/ffi.rs | 8 ++++---- src/libstd/sys/windows/ext/fs.rs | 8 ++++---- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/libstd/sys/redox/ext/ffi.rs b/src/libstd/sys/redox/ext/ffi.rs index 060edbd22e48..cd88c8f46b3c 100644 --- a/src/libstd/sys/redox/ext/ffi.rs +++ b/src/libstd/sys/redox/ext/ffi.rs @@ -17,9 +17,9 @@ use sys::os_str::Buf; use sys_common::{FromInner, IntoInner, AsInner}; -/// Redox-specific extensions to [`ffi::OsString`]. +/// Redox-specific extensions to [`OsString`]. /// -/// [`ffi::OsString`]: ../../../../std/ffi/struct.OsString.html +/// [`OsString`]: ../../../../std/ffi/struct.OsString.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { /// Creates an `OsString` from a byte vector. @@ -41,9 +41,9 @@ fn into_vec(self) -> Vec { } } -/// Redox-specific extensions to [`ffi::OsStr`]. +/// Redox-specific extensions to [`OsStr`]. /// -/// [`ffi::OsStr`]: ../../../../std/ffi/struct.OsStr.html +/// [`OsStr`]: ../../../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/redox/ext/fs.rs b/src/libstd/sys/redox/ext/fs.rs index b39c6f5d0225..c1dba6edda48 100644 --- a/src/libstd/sys/redox/ext/fs.rs +++ b/src/libstd/sys/redox/ext/fs.rs @@ -260,12 +260,12 @@ fn blocks(&self) -> u64 { } } -/// Redox-specific extensions for [`fs::FileType`]. +/// Redox-specific extensions for [`FileType`]. /// /// Adds support for special Unix file types such as block/character devices, /// pipes, and sockets. /// -/// [`fs::FileType`]: ../../../../std/fs/struct.FileType.html +/// [`FileType`]: ../../../../std/fs/struct.FileType.html #[stable(feature = "file_type_ext", since = "1.5.0")] pub trait FileTypeExt { /// Returns whether this file type is a block device. diff --git a/src/libstd/sys/redox/ext/process.rs b/src/libstd/sys/redox/ext/process.rs index 608740a5cf70..cfb6d5fc703a 100644 --- a/src/libstd/sys/redox/ext/process.rs +++ b/src/libstd/sys/redox/ext/process.rs @@ -18,7 +18,7 @@ use sys; use sys_common::{AsInnerMut, AsInner, FromInner, IntoInner}; -/// Redox-specific extensions to the [`process::Command`] builder. +/// Redox-specific extensions to the [`process::Command`] builder, /// /// [`process::Command`]: ../../../../std/process/struct.Command.html #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/unix/ext/ffi.rs b/src/libstd/sys/unix/ext/ffi.rs index 3103ad0416ec..8347145db5aa 100644 --- a/src/libstd/sys/unix/ext/ffi.rs +++ b/src/libstd/sys/unix/ext/ffi.rs @@ -17,9 +17,9 @@ use sys::os_str::Buf; use sys_common::{FromInner, IntoInner, AsInner}; -/// Unix-specific extensions to [`ffi::OsString`]. +/// Unix-specific extensions to [`OsString`]. /// -/// [`ffi::OsString`]: ../../../../std/ffi/struct.OsString.html +/// [`OsString`]: ../../../../std/ffi/struct.OsString.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { /// Creates an [`OsString`] from a byte vector. @@ -68,9 +68,9 @@ fn into_vec(self) -> Vec { } } -/// Unix-specific extensions to [`ffi::OsStr`]. +/// Unix-specific extensions to [`OsStr`]. /// -/// [`ffi::OsStr`]: ../../../../std/ffi/struct.OsStr.html +/// [`OsStr`]: ../../../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 844e0106df0f..4e9810126690 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -20,9 +20,9 @@ use sys_common::{FromInner, AsInner, AsInnerMut}; use sys::platform::fs::MetadataExt as UnixMetadataExt; -/// Unix-specific extensions to [`fs::File`]. +/// Unix-specific extensions to [`File`]. /// -/// [`fs::File`]: ../../../../std/fs/struct.File.html +/// [`File`]: ../../../../std/fs/struct.File.html #[stable(feature = "file_offset", since = "1.15.0")] pub trait FileExt { /// Reads a number of bytes starting from a given offset. @@ -555,12 +555,12 @@ fn blksize(&self) -> u64 { self.st_blksize() } fn blocks(&self) -> u64 { self.st_blocks() } } -/// Unix-specific extensions for [`fs::FileType`]. +/// Unix-specific extensions for [`FileType`]. /// /// Adds support for special Unix file types such as block/character devices, /// pipes, and sockets. /// -/// [`fs::FileType`]: ../../../../std/fs/struct.FileType.html +/// [`FileType`]: ../../../../std/fs/struct.FileType.html #[stable(feature = "file_type_ext", since = "1.5.0")] pub trait FileTypeExt { /// Returns whether this file type is a block device. diff --git a/src/libstd/sys/windows/ext/ffi.rs b/src/libstd/sys/windows/ext/ffi.rs index b3f7635efd33..98d435524899 100644 --- a/src/libstd/sys/windows/ext/ffi.rs +++ b/src/libstd/sys/windows/ext/ffi.rs @@ -76,9 +76,9 @@ #[stable(feature = "rust1", since = "1.0.0")] pub use sys_common::wtf8::EncodeWide; -/// Windows-specific extensions to [`ffi::OsString`]. +/// Windows-specific extensions to [`OsString`]. /// -/// [`ffi::OsString`]: ../../../../std/ffi/struct.OsString.html +/// [`OsString`]: ../../../../std/ffi/struct.OsString.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStringExt { /// Creates an `OsString` from a potentially ill-formed UTF-16 slice of @@ -111,9 +111,9 @@ fn from_wide(wide: &[u16]) -> OsString { } } -/// Windows-specific extensions to [`ffi::OsStr`]. +/// Windows-specific extensions to [`OsStr`]. /// -/// [`ffi::OsStr`]: ../../../../std/ffi/struct.OsStr.html +/// [`OsStr`]: ../../../../std/ffi/struct.OsStr.html #[stable(feature = "rust1", since = "1.0.0")] pub trait OsStrExt { /// Re-encodes an `OsStr` as a wide character sequence, i.e. potentially diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index 5daeb5282cd1..78c9e95a0550 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -18,9 +18,9 @@ use sys; use sys_common::{AsInnerMut, AsInner}; -/// Windows-specific extensions to [`fs::File`]. +/// Windows-specific extensions to [`File`]. /// -/// [`fs::File`]: ../../../fs/struct.File.html +/// [`File`]: ../../../fs/struct.File.html #[stable(feature = "file_offset", since = "1.15.0")] pub trait FileExt { /// Seeks to a given position and reads a number of bytes. @@ -444,11 +444,11 @@ fn last_write_time(&self) -> u64 { self.as_inner().modified_u64() } fn file_size(&self) -> u64 { self.as_inner().size() } } -/// Windows-specific extensions to [`fs::FileType`]. +/// Windows-specific extensions to [`FileType`]. /// /// On Windows, a symbolic link knows whether it is a file or directory. /// -/// [`fs::FileType`]: ../../../../std/fs/struct.FileType.html +/// [`FileType`]: ../../../../std/fs/struct.FileType.html #[unstable(feature = "windows_file_type_ext", issue = "0")] pub trait FileTypeExt { /// Returns whether this file type is a symbolic link that is also a directory. From 7cbeddb7b78cc54a52d63ed8556da7121d1d2e68 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 14 Apr 2018 23:49:37 +0200 Subject: [PATCH 10/23] Deprecate Read::chars and char::decode_utf8 Per FCP: * https://github.com/rust-lang/rust/issues/27802#issuecomment-377537778 * https://github.com/rust-lang/rust/issues/33906#issuecomment-377534308 --- src/libcore/char/decode.rs | 11 +++++++++++ src/libcore/char/mod.rs | 3 +++ src/libcore/tests/char.rs | 1 + src/libstd/io/buffered.rs | 2 ++ src/libstd/io/cursor.rs | 2 ++ src/libstd/io/mod.rs | 14 +++++++++++++- 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/libcore/char/decode.rs b/src/libcore/char/decode.rs index 48b531104f88..45a73191db2f 100644 --- a/src/libcore/char/decode.rs +++ b/src/libcore/char/decode.rs @@ -17,11 +17,17 @@ /// An iterator over an iterator of bytes of the characters the bytes represent /// as UTF-8 #[unstable(feature = "decode_utf8", issue = "33906")] +#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: + https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] #[derive(Clone, Debug)] +#[allow(deprecated)] pub struct DecodeUtf8>(::iter::Peekable); /// Decodes an `Iterator` of bytes as UTF-8. #[unstable(feature = "decode_utf8", issue = "33906")] +#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: + https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +#[allow(deprecated)] #[inline] pub fn decode_utf8>(i: I) -> DecodeUtf8 { DecodeUtf8(i.into_iter().peekable()) @@ -29,10 +35,14 @@ pub fn decode_utf8>(i: I) -> DecodeUtf8 /// `::next` returns this for an invalid input sequence. #[unstable(feature = "decode_utf8", issue = "33906")] +#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: + https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] #[derive(PartialEq, Eq, Debug)] +#[allow(deprecated)] pub struct InvalidSequence(()); #[unstable(feature = "decode_utf8", issue = "33906")] +#[allow(deprecated)] impl> Iterator for DecodeUtf8 { type Item = Result; #[inline] @@ -127,6 +137,7 @@ fn size_hint(&self) -> (usize, Option) { } #[unstable(feature = "decode_utf8", issue = "33906")] +#[allow(deprecated)] impl> FusedIterator for DecodeUtf8 {} /// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s. diff --git a/src/libcore/char/mod.rs b/src/libcore/char/mod.rs index 9edc0c88756b..bfe05af3c1c8 100644 --- a/src/libcore/char/mod.rs +++ b/src/libcore/char/mod.rs @@ -51,6 +51,9 @@ #[unstable(feature = "unicode_version", issue = "49726")] pub use unicode::version::UnicodeVersion; #[unstable(feature = "decode_utf8", issue = "33906")] +#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: + https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +#[allow(deprecated)] pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence}; use fmt::{self, Write}; diff --git a/src/libcore/tests/char.rs b/src/libcore/tests/char.rs index 4e10ceac878b..ab90763abf8d 100644 --- a/src/libcore/tests/char.rs +++ b/src/libcore/tests/char.rs @@ -364,6 +364,7 @@ fn check(c: char) { } #[test] +#[allow(deprecated)] fn test_decode_utf8() { macro_rules! assert_decode_utf8 { ($input_bytes: expr, $expected_str: expr) => { diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index d6eac7483348..ee297d3783e5 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -1251,6 +1251,7 @@ fn test_short_reads() { } #[test] + #[allow(deprecated)] fn read_char_buffered() { let buf = [195, 159]; let reader = BufReader::with_capacity(1, &buf[..]); @@ -1258,6 +1259,7 @@ fn read_char_buffered() { } #[test] + #[allow(deprecated)] fn test_chars() { let buf = [195, 159, b'a']; let reader = BufReader::with_capacity(1, &buf[..]); diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 2673f3ccfa3a..8ac52572810c 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -566,6 +566,7 @@ fn test_buf_reader() { } #[test] + #[allow(deprecated)] fn test_read_char() { let b = &b"Vi\xE1\xBB\x87t"[..]; let mut c = Cursor::new(b).chars(); @@ -577,6 +578,7 @@ fn test_read_char() { } #[test] + #[allow(deprecated)] fn test_read_bad_char() { let b = &b"\x80"[..]; let mut c = Cursor::new(b).chars(); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index b02e133ee4dd..eba4e9fe7036 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -840,6 +840,9 @@ fn bytes(self) -> Bytes where Self: Sized { of where errors happen is currently \ unclear and may change", issue = "27802")] + #[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: + https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] + #[allow(deprecated)] fn chars(self) -> Chars where Self: Sized { Chars { inner: self } } @@ -2010,16 +2013,22 @@ fn next(&mut self) -> Option> { /// [chars]: trait.Read.html#method.chars #[unstable(feature = "io", reason = "awaiting stability of Read::chars", issue = "27802")] +#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: + https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] #[derive(Debug)] +#[allow(deprecated)] pub struct Chars { inner: R, } /// An enumeration of possible errors that can be generated from the `Chars` /// adapter. -#[derive(Debug)] #[unstable(feature = "io", reason = "awaiting stability of Read::chars", issue = "27802")] +#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead: + https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")] +#[derive(Debug)] +#[allow(deprecated)] pub enum CharsError { /// Variant representing that the underlying stream was read successfully /// but it did not contain valid utf8 data. @@ -2031,6 +2040,7 @@ pub enum CharsError { #[unstable(feature = "io", reason = "awaiting stability of Read::chars", issue = "27802")] +#[allow(deprecated)] impl Iterator for Chars { type Item = result::Result; @@ -2063,6 +2073,7 @@ fn next(&mut self) -> Option> { #[unstable(feature = "io", reason = "awaiting stability of Read::chars", issue = "27802")] +#[allow(deprecated)] impl std_error::Error for CharsError { fn description(&self) -> &str { match *self { @@ -2080,6 +2091,7 @@ fn cause(&self) -> Option<&std_error::Error> { #[unstable(feature = "io", reason = "awaiting stability of Read::chars", issue = "27802")] +#[allow(deprecated)] impl fmt::Display for CharsError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { From e77110e1f61e42c0f0e9e3288edb0d663eb39bba Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 15 Apr 2018 11:12:33 -0700 Subject: [PATCH 11/23] don't see issue #0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The unstable-feature attribute requires an issue (neglecting it is E0547), which gets used in the error messages. Unfortunately, there are some cases where "0" is apparently used a placeholder where no issue exists, directing the user to see the (nonexistent) issue #0. (It would have been better to either let `issue` be optional—compare to how issue is an `Option` in the feature-gate declarations in libsyntax/feature-gate.rs—or actually require that an issue be created.) Rather than endeavoring to change how `#[unstable]` works at this time (given competing contributor and reviewer priorities), this simple patch proposes the less-ambitious solution of just not adding the "(see issue)" note when the number is zero. Resolves #49983. --- src/libsyntax/feature_gate.rs | 7 +++---- .../ui/feature-gate/issue-49983-see-issue-0.rs | 16 ++++++++++++++++ .../feature-gate/issue-49983-see-issue-0.stderr | 11 +++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/feature-gate/issue-49983-see-issue-0.rs create mode 100644 src/test/ui/feature-gate/issue-49983-see-issue-0.stderr diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 73ebfc20876d..5413a05a364b 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1228,10 +1228,9 @@ fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue GateIssue::Library(lib) => lib, }; - let explanation = if let Some(n) = issue { - format!("{} (see issue #{})", explain, n) - } else { - explain.to_owned() + let explanation = match issue { + None | Some(0) => explain.to_owned(), + Some(n) => format!("{} (see issue #{})", explain, n) }; let mut err = match level { diff --git a/src/test/ui/feature-gate/issue-49983-see-issue-0.rs b/src/test/ui/feature-gate/issue-49983-see-issue-0.rs new file mode 100644 index 000000000000..1e0039aba04b --- /dev/null +++ b/src/test/ui/feature-gate/issue-49983-see-issue-0.rs @@ -0,0 +1,16 @@ +// Copyright 2018 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. + +extern crate core; + +// error should not say "(see issue #0)" +#[allow(unused_imports)] use core::ptr::Unique; //~ ERROR use of unstable library feature + +fn main() {} diff --git a/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr b/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr new file mode 100644 index 000000000000..986a2d88e00a --- /dev/null +++ b/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr @@ -0,0 +1,11 @@ +error[E0658]: use of unstable library feature 'ptr_internals': use NonNull instead and consider PhantomData (if you also use #[may_dangle]), Send, and/or Sync + --> $DIR/issue-49983-see-issue-0.rs:14:30 + | +LL | #[allow(unused_imports)] use core::ptr::Unique; //~ ERROR use of unstable library feature + | ^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(ptr_internals)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. From 5fe8c59f1219705ea54f842f9868ad0017643a33 Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 12 Apr 2018 21:47:38 +0800 Subject: [PATCH 12/23] Stabilize core::hint::unreachable_unchecked. Closes #43751. --- src/libcore/hint.rs | 61 +++++++++++++++++++++++++++++++++++++++ src/libcore/intrinsics.rs | 3 ++ src/libcore/lib.rs | 1 + src/libcore/macros.rs | 8 ++--- src/libcore/mem.rs | 12 -------- src/libstd/lib.rs | 2 ++ 6 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 src/libcore/hint.rs diff --git a/src/libcore/hint.rs b/src/libcore/hint.rs new file mode 100644 index 000000000000..f4e96e67b2c6 --- /dev/null +++ b/src/libcore/hint.rs @@ -0,0 +1,61 @@ +// Copyright 2018 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. + +#![stable(feature = "core_hint", since = "1.27.0")] + +//! Hints to compiler that affects how code should be emitted or optimized. + +use intrinsics; + +/// Informs the compiler that this point in the code is not reachable, enabling +/// further optimizations. +/// +/// # Safety +/// +/// Reaching this function is completely *undefined behavior* (UB). In +/// particular, the compiler assumes that all UB must never happen, and +/// therefore will eliminate all branches that reach to a call to +/// `unreachable_unchecked()`. +/// +/// Like all instances of UB, if this assumption turns out to be wrong, i.e. the +/// `unreachable_unchecked()` call is actually reachable among all possible +/// control flow, the compiler will apply the wrong optimization strategy, and +/// may sometimes even corrupt seemingly unrelated code, causing +/// difficult-to-debug problems. +/// +/// Use this function only when you can prove that the code will never call it. +/// +/// The [`unreachable!()`] macro is the safe counterpart of this function, which +/// will panic instead when executed. +/// +/// [`unreachable!()`]: ../macro.unreachable.html +/// +/// # Example +/// +/// ``` +/// fn div_1(a: u32, b: u32) -> u32 { +/// use std::hint::unreachable_unchecked; +/// +/// // `b.saturating_add(1)` is always positive (not zero), +/// // hence `checked_div` will never return None. +/// // Therefore, the else branch is unreachable. +/// a.checked_div(b.saturating_add(1)) +/// .unwrap_or_else(|| unsafe { unreachable_unchecked() }) +/// } +/// +/// assert_eq!(div_1(7, 0), 7); +/// assert_eq!(div_1(9, 1), 4); +/// assert_eq!(div_1(11, std::u32::MAX), 0); +/// ``` +#[inline] +#[stable(feature = "unreachable", since = "1.27.0")] +pub unsafe fn unreachable_unchecked() -> ! { + intrinsics::unreachable() +} diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 83274682250b..fb0d2d9c8821 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -638,6 +638,9 @@ /// NB: This is very different from the `unreachable!()` macro: Unlike the /// macro, which panics when it is executed, it is *undefined behavior* to /// reach code marked with this function. + /// + /// The stabilized version of this intrinsic is + /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html). pub fn unreachable() -> !; /// Informs the optimizer that a condition is always true. diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 5ebd9e4334cd..1968c11d0622 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -149,6 +149,7 @@ pub mod mem; pub mod nonzero; pub mod ptr; +pub mod hint; /* Core language traits */ diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 90a9cb3379b8..1e2551e36f54 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -420,13 +420,13 @@ macro_rules! writeln { /// * Iterators that dynamically terminate. /// /// If the determination that the code is unreachable proves incorrect, the -/// program immediately terminates with a [`panic!`]. The function [`unreachable`], -/// which belongs to the [`std::intrinsics`] module, informs the compilier to +/// program immediately terminates with a [`panic!`]. The function [`unreachable_unchecked`], +/// which belongs to the [`std::hint`] module, informs the compilier to /// optimize the code out of the release version entirely. /// /// [`panic!`]: ../std/macro.panic.html -/// [`unreachable`]: ../std/intrinsics/fn.unreachable.html -/// [`std::intrinsics`]: ../std/intrinsics/index.html +/// [`unreachable_unchecked`]: ../std/hint/fn.unreachable_unchecked.html +/// [`std::hint`]: ../std/hint/index.html /// /// # Panics /// diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index e3f08926610f..10efab82ddff 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -1094,18 +1094,6 @@ fn hash(&self, state: &mut H) { } } -/// Tells LLVM that this point in the code is not reachable, enabling further -/// optimizations. -/// -/// NB: This is very different from the `unreachable!()` macro: Unlike the -/// macro, which panics when it is executed, it is *undefined behavior* to -/// reach code marked with this function. -#[inline] -#[unstable(feature = "unreachable", issue = "43751")] -pub unsafe fn unreachable() -> ! { - intrinsics::unreachable() -} - /// A pinned reference. /// /// A pinned reference is a lot like a mutable reference, except that it is not diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a34fcb5a7f98..d92a45265493 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -457,6 +457,8 @@ pub use core::char; #[stable(feature = "i128", since = "1.26.0")] pub use core::u128; +#[stable(feature = "core_hint", since = "1.27.0")] +pub use core::hint; pub mod f32; pub mod f64; From bc4bd5642ab7ccfdaf84c95c8b62f620acbca644 Mon Sep 17 00:00:00 2001 From: Andreas Tolfsen Date: Tue, 17 Apr 2018 08:00:48 +0100 Subject: [PATCH 13/23] fixup! std: Child::kill() returns error if process has already exited --- src/libstd/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 60759de8afc3..431226453ff2 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1121,7 +1121,7 @@ impl ExitCode { } impl Child { - /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] + /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`] /// error is returned. /// /// The mapping to [`ErrorKind`]s is not part of the compatibility contract of the function, From bf816a2fe08c6d40ea356306ef4c750d3667dc3d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 9 Apr 2018 11:46:54 -0700 Subject: [PATCH 14/23] Fix revision support for UI tests. Fixes #48878 --- src/test/ui/update-references.sh | 29 +++++------- src/tools/compiletest/src/runtest.rs | 68 +++++++++++++++++----------- src/tools/tidy/src/ui_tests.rs | 42 ++++++----------- 3 files changed, 68 insertions(+), 71 deletions(-) diff --git a/src/test/ui/update-references.sh b/src/test/ui/update-references.sh index cfe9a43707cf..4fc11daaa3af 100755 --- a/src/test/ui/update-references.sh +++ b/src/test/ui/update-references.sh @@ -31,24 +31,17 @@ MYDIR=$(dirname $0) BUILD_DIR="$1" shift +shopt -s nullglob + while [[ "$1" != "" ]]; do - STDERR_NAME="${1/%.rs/.stderr}" - STDERR_NLL_NAME="${1/%.rs/.nll.stderr}" - STDOUT_NAME="${1/%.rs/.stdout}" + for EXT in "stderr" "stdout"; do + for OUT_NAME in $BUILD_DIR/${1%.rs}.*$EXT; do + OUT_BASE=`basename "$OUT_NAME"` + if ! (diff $OUT_NAME $MYDIR/$OUT_BASE >& /dev/null); then + echo updating $MYDIR/$OUT_BASE + cp $OUT_NAME $MYDIR + fi + done + done shift - if [ -f $BUILD_DIR/$STDOUT_NAME ] && \ - ! (diff $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME >& /dev/null); then - echo updating $MYDIR/$STDOUT_NAME - cp $BUILD_DIR/$STDOUT_NAME $MYDIR/$STDOUT_NAME - fi - if [ -f $BUILD_DIR/$STDERR_NAME ] && \ - ! (diff $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME >& /dev/null); then - echo updating $MYDIR/$STDERR_NAME - cp $BUILD_DIR/$STDERR_NAME $MYDIR/$STDERR_NAME - fi - if [ -f $BUILD_DIR/$STDERR_NLL_NAME ] && \ - ! (diff $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME >& /dev/null); then - echo updating $MYDIR/$STDERR_NLL_NAME - cp $BUILD_DIR/$STDERR_NLL_NAME $MYDIR/$STDERR_NLL_NAME - fi done diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 0f4d247633a6..4d1fca8207b9 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -26,7 +26,7 @@ use std::collections::HashMap; use std::collections::HashSet; use std::env; -use std::ffi::OsString; +use std::ffi::{OsStr, OsString}; use std::fs::{self, create_dir_all, File}; use std::fmt; use std::io::prelude::*; @@ -72,6 +72,26 @@ fn new(line_number: u32) -> Mismatch { } } +trait PathBufExt { + /// Append an extension to the path, even if it already has one. + fn with_extra_extension>(&self, extension: S) -> PathBuf; +} + +impl PathBufExt for PathBuf { + fn with_extra_extension>(&self, extension: S) -> PathBuf { + if extension.as_ref().len() == 0 { + self.clone() + } else { + let mut fname = self.file_name().unwrap().to_os_string(); + if !extension.as_ref().to_str().unwrap().starts_with(".") { + fname.push("."); + } + fname.push(extension); + self.with_file_name(fname) + } + } +} + // Produces a diff between the expected output and actual output. pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec { let mut line_number = 1; @@ -1725,20 +1745,14 @@ fn make_lib_name(&self, auxfile: &Path) -> PathBuf { } fn make_exe_name(&self) -> PathBuf { - let mut f = self.output_base_name(); + let mut f = self.output_base_name_stage(); // FIXME: This is using the host architecture exe suffix, not target! if self.config.target.contains("emscripten") { - let mut fname = f.file_name().unwrap().to_os_string(); - fname.push(".js"); - f.set_file_name(&fname); + f = f.with_extra_extension("js"); } else if self.config.target.contains("wasm32") { - let mut fname = f.file_name().unwrap().to_os_string(); - fname.push(".wasm"); - f.set_file_name(&fname); + f = f.with_extra_extension("wasm"); } else if !env::consts::EXE_SUFFIX.is_empty() { - let mut fname = f.file_name().unwrap().to_os_string(); - fname.push(env::consts::EXE_SUFFIX); - f.set_file_name(&fname); + f = f.with_extra_extension(env::consts::EXE_SUFFIX); } f } @@ -1846,25 +1860,26 @@ fn make_out_name(&self, extension: &str) -> PathBuf { } fn aux_output_dir_name(&self) -> PathBuf { - let f = self.output_base_name(); - let mut fname = f.file_name().unwrap().to_os_string(); - fname.push(&format!("{}.aux", self.config.mode.disambiguator())); - f.with_file_name(&fname) + self.output_base_name_stage() + .with_extra_extension(self.config.mode.disambiguator()) + .with_extra_extension(".aux") } fn output_testname(&self, filepath: &Path) -> PathBuf { PathBuf::from(filepath.file_stem().unwrap()) } - /// Given a test path like `compile-fail/foo/bar.rs` Returns a name like - /// - /// /foo/bar-stage1 + /// Given a test path like `compile-fail/foo/bar.rs` returns a name like + /// `/path/to/build//test/compile-fail/foo/bar`. fn output_base_name(&self) -> PathBuf { let dir = self.config.build_base.join(&self.testpaths.relative_dir); // Note: The directory `dir` is created during `collect_tests_from_dir` dir.join(&self.output_testname(&self.testpaths.file)) - .with_extension(&self.config.stage_id) + } + + fn output_base_name_stage(&self) -> PathBuf { + self.output_base_name().with_extension(&self.config.stage_id) } fn maybe_dump_to_stdout(&self, out: &str, err: &str) { @@ -1989,7 +2004,7 @@ fn charset() -> &'static str { fn run_rustdoc_test(&self) { assert!(self.revision.is_none(), "revisions not relevant here"); - let out_dir = self.output_base_name(); + let out_dir = self.output_base_name_stage(); let _ = fs::remove_dir_all(&out_dir); create_dir_all(&out_dir).unwrap(); @@ -2391,7 +2406,7 @@ fn run_rmake_test(&self) { .unwrap(); let src_root = cwd.join(&src_root); - let tmpdir = cwd.join(self.output_base_name()); + let tmpdir = cwd.join(self.output_base_name_stage()); if tmpdir.exists() { self.aggressive_rm_rf(&tmpdir).unwrap(); } @@ -2816,7 +2831,6 @@ fn expected_output_path(&self, kind: &str) -> PathBuf { self.revision, &self.config.compare_mode, kind); - if !path.exists() && self.config.compare_mode.is_some() { // fallback! path = expected_output_path(&self.testpaths, self.revision, &None, kind); @@ -2880,10 +2894,12 @@ fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize { } } - let expected_output = self.expected_output_path(kind); - // #50113: output is abspath; only want filename component. - let expected_output = expected_output.file_name().expect("output path requires file name"); - let output_file = self.output_base_name().with_file_name(&expected_output); + let mode = self.config.compare_mode.as_ref().map_or("", |m| m.to_str()); + let output_file = self.output_base_name() + .with_extra_extension(self.revision.unwrap_or("")) + .with_extra_extension(mode) + .with_extra_extension(kind); + match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) { Ok(()) => {} Err(e) => self.fatal(&format!( diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index bda58bc09f77..351005ff4b81 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -12,38 +12,26 @@ use std::path::Path; -// See rust-lang/rust#48879: In addition to the mapping from `foo.rs` -// to `foo.stderr`/`foo.stdout`, we also can optionally have -// `foo.$mode.stderr`, where $mode is one of the strings on this list, -// as an alternative to use when running under that mode. -static COMPARE_MODE_NAMES: [&'static str; 1] = ["nll"]; - pub fn check(path: &Path, bad: &mut bool) { super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")], &mut |_| false, &mut |file_path| { if let Some(ext) = file_path.extension() { - if (ext == "stderr" || ext == "stdout") && !file_path.with_extension("rs").exists() { - - // rust-lang/rust#48879: this fn used to be beautful - // because Path API special-cases replacing - // extensions. That works great for ".stderr" but not - // so well for ".nll.stderr". To support the latter, - // we explicitly search backwards for mode's starting - // point and build corresponding source name. - let filename = file_path.file_name().expect("need filename") - .to_str().expect("need UTF-8 filename"); - let found_matching_prefix = COMPARE_MODE_NAMES.iter().any(|mode| { - if let Some(r_idx) = filename.rfind(&format!(".{}", mode)) { - let source_name = format!("{}.rs", &filename[0..r_idx]); - let source_path = file_path.with_file_name(source_name); - source_path.exists() - } else { - false - } - }); - - if !found_matching_prefix { + if ext == "stderr" || ext == "stdout" { + // Test output filenames have the format: + // $testname.stderr + // $testname.$mode.stderr + // $testname.$revision.stderr + // $testname.$revision.$mode.stderr + // + // For now, just make sure that there is a corresponding + // $testname.rs file. + let testname = file_path.file_name().unwrap() + .to_str().unwrap() + .splitn(2, '.').next().unwrap(); + if !file_path.with_file_name(testname) + .with_extension("rs") + .exists() { println!("Stray file with UI testing output: {:?}", file_path); *bad = true; } From c3af11808640c2a77a474bcd09b61e63d4553917 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 11 Apr 2018 17:17:14 -0700 Subject: [PATCH 15/23] Add doc for output_base_name_stage. --- src/tools/compiletest/src/runtest.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 4d1fca8207b9..aabf2e6f8f0e 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1878,6 +1878,8 @@ fn output_base_name(&self) -> PathBuf { dir.join(&self.output_testname(&self.testpaths.file)) } + /// Same as `output_base_name`, but includes the stage ID as an extension, + /// such as: `.../compile-fail/foo/bar.stage1-` fn output_base_name_stage(&self) -> PathBuf { self.output_base_name().with_extension(&self.config.stage_id) } From 79b11275965fe6dbd8d1ed52b44d7663ca4d2f95 Mon Sep 17 00:00:00 2001 From: Niv Kaminer Date: Sat, 21 Apr 2018 12:08:01 +0300 Subject: [PATCH 16/23] encourage descriptive issue titles --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c5dd3cd72054..a6c66cf5d7e9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,6 +47,12 @@ as it's possible that someone else has already reported your error. This doesn't always work, and sometimes it's hard to know what to search for, so consider this extra credit. We won't mind if you accidentally file a duplicate report. +Similarly, to help others who encountered the bug find your issue, +consider filing an issue with with a descriptive title, which contains imformation that might be unique to it. +This can be the language or compiler feature used, the conditions that trigger the bug, +or part of the error message if there is any. +An example could be: **"impossible case reached" on lifetime inference for impl Trait in return position**. + Opening an issue is as easy as following [this link](https://github.com/rust-lang/rust/issues/new) and filling out the fields. Here's a template that you can use to file a bug, though it's not necessary to From 6b6933cf3cccdcc8a6f8177f93c10ef737dabf70 Mon Sep 17 00:00:00 2001 From: Niv Kaminer Date: Sat, 21 Apr 2018 13:10:27 +0300 Subject: [PATCH 17/23] typofix --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a6c66cf5d7e9..e7041dcddc42 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,7 @@ always work, and sometimes it's hard to know what to search for, so consider thi extra credit. We won't mind if you accidentally file a duplicate report. Similarly, to help others who encountered the bug find your issue, -consider filing an issue with with a descriptive title, which contains imformation that might be unique to it. +consider filing an issue with with a descriptive title, which contains information that might be unique to it. This can be the language or compiler feature used, the conditions that trigger the bug, or part of the error message if there is any. An example could be: **"impossible case reached" on lifetime inference for impl Trait in return position**. From f7d4c976a2b83f3e7119bfc1377b422062187a00 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 23 Apr 2018 09:48:08 +1000 Subject: [PATCH 18/23] Use FxHashMap in syntax_pos::symbol::Interner::intern. Because it's faster than HashMap. This change reduces the time taken for a few of the rustc-perf benchmarks, mostly the small ones, by up to 5%. --- src/libsyntax_pos/symbol.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 50fac600a978..b449c5eea665 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -15,8 +15,8 @@ use hygiene::SyntaxContext; use {Span, DUMMY_SP, GLOBALS}; +use rustc_data_structures::fx::FxHashMap; use serialize::{Decodable, Decoder, Encodable, Encoder}; -use std::collections::HashMap; use std::fmt; use std::hash::{Hash, Hasher}; @@ -184,7 +184,7 @@ fn eq(&self, other: &T) -> bool { #[derive(Default)] pub struct Interner { - names: HashMap, Symbol>, + names: FxHashMap, Symbol>, strings: Vec>, gensyms: Vec, } From fbb1c280bf5f3d4fc68f323860ade8fa48d96979 Mon Sep 17 00:00:00 2001 From: Daiki Mizukami Date: Tue, 24 Apr 2018 01:45:44 +0900 Subject: [PATCH 19/23] core: Fix overflow in `int::mod_euc` when `self < 0 && rhs == MIN` --- src/libcore/num/mod.rs | 6 +++++- src/libcore/tests/lib.rs | 1 + src/libcore/tests/num/int_macros.rs | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index aa4d4bc638b1..4893e05badcb 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1765,7 +1765,11 @@ pub fn div_euc(self, rhs: Self) -> Self { pub fn mod_euc(self, rhs: Self) -> Self { let r = self % rhs; if r < 0 { - r + rhs.abs() + if rhs.is_negative() { + r - rhs + } else { + r + rhs + } } else { r } diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 7d3852d2f2a9..ccf647c358d6 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -15,6 +15,7 @@ #![feature(core_private_diy_float)] #![feature(dec2flt)] #![feature(decode_utf8)] +#![feature(euclidean_division)] #![feature(exact_size_is_empty)] #![feature(fixed_size_array)] #![feature(float_internals)] diff --git a/src/libcore/tests/num/int_macros.rs b/src/libcore/tests/num/int_macros.rs index 8d791283ab87..71d2e7945389 100644 --- a/src/libcore/tests/num/int_macros.rs +++ b/src/libcore/tests/num/int_macros.rs @@ -30,6 +30,11 @@ fn test_num() { num::test_num(10 as $T, 2 as $T); } + #[test] + fn test_mod_euc() { + assert!((-1 as $T).mod_euc(MIN) == MAX); + } + #[test] pub fn test_abs() { assert!((1 as $T).abs() == 1 as $T); From 1c0db245e0c87c2158f4a4456bf8e0a7aa14b677 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 23 Apr 2018 20:23:04 +0200 Subject: [PATCH 20/23] Clarify the docs for Cell::update --- src/libcore/cell.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index e4a52d9c4a40..64dbcbf7ae43 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -257,7 +257,7 @@ pub fn get(&self) -> T { unsafe{ *self.value.get() } } - /// Applies a function to the contained value. + /// Updates the contained value using a function and returns the new value. /// /// # Examples /// @@ -267,8 +267,9 @@ pub fn get(&self) -> T { /// use std::cell::Cell; /// /// let c = Cell::new(5); - /// c.update(|x| x + 1); + /// let new = c.update(|x| x + 1); /// + /// assert_eq!(new, 6); /// assert_eq!(c.get(), 6); /// ``` #[inline] From 104c64dc360f297fbdd4a467dac1c5006d76dece Mon Sep 17 00:00:00 2001 From: Daiki Mizukami Date: Tue, 24 Apr 2018 03:32:40 +0900 Subject: [PATCH 21/23] core: Minor cleanup --- src/libcore/num/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 4893e05badcb..a062fbda5bad 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1765,7 +1765,7 @@ pub fn div_euc(self, rhs: Self) -> Self { pub fn mod_euc(self, rhs: Self) -> Self { let r = self % rhs; if r < 0 { - if rhs.is_negative() { + if rhs < 0 { r - rhs } else { r + rhs From 29e9de85d6ae185d7d66c7ba0f2c418082d2df5f Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 23 Apr 2018 20:34:49 +0200 Subject: [PATCH 22/23] Assign the tracking issue --- src/libcore/cell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 64dbcbf7ae43..1ff187ed3f10 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -273,7 +273,7 @@ pub fn get(&self) -> T { /// assert_eq!(c.get(), 6); /// ``` #[inline] - #[unstable(feature = "cell_update", issue = "0")] // FIXME: issue + #[unstable(feature = "cell_update", issue = "50186")] pub fn update(&self, f: F) -> T where F: FnOnce(T) -> T, From f33af5c4dedb10bf4eaee0ce2e83c6f05d07692f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 20 Apr 2018 16:42:44 +0200 Subject: [PATCH 23/23] fix search bar bug --- src/librustdoc/html/static/main.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 2cae88855e3e..ef8bf2244d97 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1375,13 +1375,17 @@ function search(e) { var params = getQueryStringParams(); - var query = getQuery(document.getElementsByClassName('search-input')[0].value.trim()); + var search_input = document.getElementsByClassName('search-input')[0]; + var query = getQuery(search_input.value.trim()); if (e) { e.preventDefault(); } if (!query.query || query.id === currentResults) { + if (query.query.length > 0) { + putBackSearch(search_input); + } return; } @@ -2072,19 +2076,23 @@ }; }); + function putBackSearch(search_input) { + if (search_input.value !== "") { + addClass(document.getElementById("main"), "hidden"); + removeClass(document.getElementById("search"), "hidden"); + if (browserSupportsHistoryApi()) { + history.replaceState(search_input.value, + "", + "?search=" + encodeURIComponent(search_input.value)); + } + } + } + var search_input = document.getElementsByClassName("search-input")[0]; if (search_input) { search_input.onfocus = function() { - if (search_input.value !== "") { - addClass(document.getElementById("main"), "hidden"); - removeClass(document.getElementById("search"), "hidden"); - if (browserSupportsHistoryApi()) { - history.replaceState(search_input.value, - "", - "?search=" + encodeURIComponent(search_input.value)); - } - } + putBackSearch(this); }; }