From 1fb00335df72fc3a05cd13a2bd5013f362d21177 Mon Sep 17 00:00:00 2001 From: Sean Linsley Date: Mon, 16 Oct 2023 12:41:43 -0500 Subject: [PATCH 1/8] Improve rewind documentation --- library/std/src/io/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index c0a729481121a..b7b6a9a24c9b9 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -556,6 +556,10 @@ where /// therefore, using something that implements [`BufRead`], such as /// [`BufReader`], will be more efficient. /// +/// Repeated calls to the reader use the same cursor, so for example +/// calling `read_to_end` twice on a [`File`] will only return the file's +/// contents once. It's recommended to first call `rewind()` in that case. +/// /// # Examples /// /// [`File`]s implement `Read`: From a355df44320f516547cd1e715ff9ea694256c978 Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Thu, 16 Nov 2023 00:01:57 +0800 Subject: [PATCH 2/8] remove unnecessary drop --- library/core/src/cell.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 0978b3c92805e..f10a82c569496 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -409,8 +409,7 @@ impl Cell { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn set(&self, val: T) { - let old = self.replace(val); - drop(old); + self.replace(val); } /// Swaps the values of two `Cell`s. From df58704701569ec53de043eb5ebf34248f78c1ac Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Tue, 7 Nov 2023 05:42:46 +0000 Subject: [PATCH 3/8] Define `INVALID_HANDLE_VALUE` ourselves --- library/std/src/sys/windows/c.rs | 2 ++ library/std/src/sys/windows/c/windows_sys.lst | 2 +- library/std/src/sys/windows/c/windows_sys.rs | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index a349e24b03951..795e1c160415e 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -46,6 +46,8 @@ pub use FD_SET as fd_set; pub use LINGER as linger; pub use TIMEVAL as timeval; +pub const INVALID_HANDLE_VALUE: HANDLE = ::core::ptr::invalid_mut(-1i32 as _); + // https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure?view=msvc-170 pub const EXIT_SUCCESS: u32 = 0; pub const EXIT_FAILURE: u32 = 1; diff --git a/library/std/src/sys/windows/c/windows_sys.lst b/library/std/src/sys/windows/c/windows_sys.lst index 38bf15b7c7202..5cd738c2930ad 100644 --- a/library/std/src/sys/windows/c/windows_sys.lst +++ b/library/std/src/sys/windows/c/windows_sys.lst @@ -2,6 +2,7 @@ --config flatten std --filter // tidy-alphabetical-start +!Windows.Win32.Foundation.INVALID_HANDLE_VALUE Windows.Wdk.Storage.FileSystem.FILE_COMPLETE_IF_OPLOCKED Windows.Wdk.Storage.FileSystem.FILE_CONTAINS_EXTENDED_CREATE_INFORMATION Windows.Wdk.Storage.FileSystem.FILE_CREATE @@ -1923,7 +1924,6 @@ Windows.Win32.Foundation.HANDLE_FLAG_INHERIT Windows.Win32.Foundation.HANDLE_FLAG_PROTECT_FROM_CLOSE Windows.Win32.Foundation.HANDLE_FLAGS Windows.Win32.Foundation.HMODULE -Windows.Win32.Foundation.INVALID_HANDLE_VALUE Windows.Win32.Foundation.MAX_PATH Windows.Win32.Foundation.NO_ERROR Windows.Win32.Foundation.NTSTATUS diff --git a/library/std/src/sys/windows/c/windows_sys.rs b/library/std/src/sys/windows/c/windows_sys.rs index e0509e6a5dd79..221dc2346a802 100644 --- a/library/std/src/sys/windows/c/windows_sys.rs +++ b/library/std/src/sys/windows/c/windows_sys.rs @@ -3498,7 +3498,6 @@ impl ::core::clone::Clone for INIT_ONCE { } pub const INIT_ONCE_INIT_FAILED: u32 = 4u32; pub const INVALID_FILE_ATTRIBUTES: u32 = 4294967295u32; -pub const INVALID_HANDLE_VALUE: HANDLE = ::core::ptr::invalid_mut(-1i32 as _); pub const INVALID_SOCKET: SOCKET = -1i32 as _; #[repr(C)] pub struct IN_ADDR { From 00a12af3ca17746f3e4548d783b7107f42155101 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Fri, 17 Nov 2023 12:13:38 +0000 Subject: [PATCH 4/8] Update windows-bindgen --- Cargo.lock | 8 ++++---- library/std/src/sys/windows/c/windows_sys.lst | 2 +- library/std/src/sys/windows/c/windows_sys.rs | 8 ++++---- src/tools/generate-windows-sys/Cargo.toml | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92bac995bc615..52640036f9e0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6130,9 +6130,9 @@ dependencies = [ [[package]] name = "windows-bindgen" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc1f16b778125675feee0d15d6dd9f6af0e3ac52b3233d63a10aa39230c1cd75" +checksum = "970efb0b6849eb8a87a898f586af7cc167567b070014c7434514c0bde0ca341c" dependencies = [ "proc-macro2", "rayon", @@ -6142,9 +6142,9 @@ dependencies = [ [[package]] name = "windows-metadata" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "753135d996f9da437c0b31dbde3032489a61708361929bcc07d4fba0b161000e" +checksum = "218fd59201e26acdbb894fa2b302d1de84bf3eec7d0eb894ac8e9c5a854ee4ef" [[package]] name = "windows-sys" diff --git a/library/std/src/sys/windows/c/windows_sys.lst b/library/std/src/sys/windows/c/windows_sys.lst index 5cd738c2930ad..f91e1054a040b 100644 --- a/library/std/src/sys/windows/c/windows_sys.lst +++ b/library/std/src/sys/windows/c/windows_sys.lst @@ -2483,7 +2483,6 @@ Windows.Win32.System.SystemInformation.GetSystemTimeAsFileTime Windows.Win32.System.SystemInformation.GetWindowsDirectoryW Windows.Win32.System.SystemInformation.PROCESSOR_ARCHITECTURE Windows.Win32.System.SystemInformation.SYSTEM_INFO -Windows.Win32.System.SystemServices.ALL_PROCESSOR_GROUPS Windows.Win32.System.SystemServices.DLL_PROCESS_DETACH Windows.Win32.System.SystemServices.DLL_THREAD_DETACH Windows.Win32.System.SystemServices.EXCEPTION_MAXIMUM_PARAMETERS @@ -2492,6 +2491,7 @@ Windows.Win32.System.SystemServices.IO_REPARSE_TAG_SYMLINK Windows.Win32.System.Threading.ABOVE_NORMAL_PRIORITY_CLASS Windows.Win32.System.Threading.AcquireSRWLockExclusive Windows.Win32.System.Threading.AcquireSRWLockShared +Windows.Win32.System.Threading.ALL_PROCESSOR_GROUPS Windows.Win32.System.Threading.BELOW_NORMAL_PRIORITY_CLASS Windows.Win32.System.Threading.CREATE_BREAKAWAY_FROM_JOB Windows.Win32.System.Threading.CREATE_DEFAULT_ERROR_MODE diff --git a/library/std/src/sys/windows/c/windows_sys.rs b/library/std/src/sys/windows/c/windows_sys.rs index 221dc2346a802..b38b70c8983e6 100644 --- a/library/std/src/sys/windows/c/windows_sys.rs +++ b/library/std/src/sys/windows/c/windows_sys.rs @@ -4,7 +4,7 @@ // regenerate the bindings. // // ignore-tidy-filelength -// Bindings generated by `windows-bindgen` 0.51.1 +// Bindings generated by `windows-bindgen` 0.52.0 #![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, clippy::all)] #[link(name = "advapi32")] @@ -63,7 +63,7 @@ extern "system" { lpnewfilename: PCWSTR, lpprogressroutine: LPPROGRESS_ROUTINE, lpdata: *const ::core::ffi::c_void, - pbcancel: *mut i32, + pbcancel: *mut BOOL, dwcopyflags: u32, ) -> BOOL; } @@ -619,7 +619,7 @@ extern "system" { lpmultibytestr: PSTR, cbmultibyte: i32, lpdefaultchar: PCSTR, - lpuseddefaultchar: *mut i32, + lpuseddefaultchar: *mut BOOL, ) -> i32; } #[link(name = "kernel32")] @@ -869,7 +869,7 @@ pub const AF_INET: ADDRESS_FAMILY = 2u16; pub const AF_INET6: ADDRESS_FAMILY = 23u16; pub const AF_UNIX: u16 = 1u16; pub const AF_UNSPEC: ADDRESS_FAMILY = 0u16; -pub const ALL_PROCESSOR_GROUPS: u32 = 65535u32; +pub const ALL_PROCESSOR_GROUPS: u16 = 65535u16; #[repr(C)] pub union ARM64_NT_NEON128 { pub Anonymous: ARM64_NT_NEON128_0, diff --git a/src/tools/generate-windows-sys/Cargo.toml b/src/tools/generate-windows-sys/Cargo.toml index 9821677a1226e..d8a7a06efc6d4 100644 --- a/src/tools/generate-windows-sys/Cargo.toml +++ b/src/tools/generate-windows-sys/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies.windows-bindgen] -version = "0.51.1" +version = "0.52.0" From db629211591f7ac8ab6d502d8bee3fce8b528312 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Fri, 17 Nov 2023 19:54:37 -0500 Subject: [PATCH 5/8] Document behavior of `::type_id()` See also #57893 --- library/core/src/any.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/any.rs b/library/core/src/any.rs index 8f5404d9713dd..22777fb078a26 100644 --- a/library/core/src/any.rs +++ b/library/core/src/any.rs @@ -115,6 +115,11 @@ use crate::intrinsics; pub trait Any: 'static { /// Gets the `TypeId` of `self`. /// + /// If called on a `dyn Any` trait object + /// (or a trait object of a subtrait of `Any`), + /// this returns the `TypeId` of the underlying + /// concrete type, not that of `dyn Any` itself. + /// /// # Examples /// /// ``` From 3a486c1feb0a4846a3bcff0dda5182dc9c762ba2 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sun, 19 Nov 2023 16:24:39 +0000 Subject: [PATCH 6/8] Use an absolute path to the NUL device While a bare "NUL" *should* be redirected to the NUL device, especially in this simple case, let's be explicit that we aren't opening a file called "NUL" and instead open it directly. This will also set a good example for people copying std code. --- library/std/src/sys/windows/process.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/windows/process.rs b/library/std/src/sys/windows/process.rs index f4078d359448e..3b22f6d2e3158 100644 --- a/library/std/src/sys/windows/process.rs +++ b/library/std/src/sys/windows/process.rs @@ -597,7 +597,7 @@ impl Stdio { opts.read(stdio_id == c::STD_INPUT_HANDLE); opts.write(stdio_id != c::STD_INPUT_HANDLE); opts.security_attributes(&mut sa); - File::open(Path::new("NUL"), &opts).map(|file| file.into_inner()) + File::open(Path::new(r"\\.\NUL"), &opts).map(|file| file.into_inner()) } } } From a994f46421f5ac551905e336c1c1b78a8885f6a5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 23 Nov 2023 17:16:19 -0800 Subject: [PATCH 7/8] Add test of rustdoc sort order for stable vs unstable item --- tests/rustdoc/stability.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/rustdoc/stability.rs b/tests/rustdoc/stability.rs index 90be2050d926b..5d8286d8116f2 100644 --- a/tests/rustdoc/stability.rs +++ b/tests/rustdoc/stability.rs @@ -2,6 +2,14 @@ #![unstable(feature = "test", issue = "none")] +// @has stability/index.html +// @has - '//ul[@class="item-table"]/li[1]//a' Unstable +// @has - '//ul[@class="item-table"]/li[2]//a' AaStable +// @has - '//ul[@class="item-table"]/li[3]//a' ZzStable + +#[stable(feature = "rust2", since = "2.2.2")] +pub struct AaStable; + pub struct Unstable { // @has stability/struct.Unstable.html \ // '//span[@class="item-info"]//div[@class="stab unstable"]' \ @@ -10,3 +18,6 @@ pub struct Unstable { pub foo: u32, pub bar: u32, } + +#[stable(feature = "rust2", since = "2.2.2")] +pub struct ZzStable; From b77aa74a2d6b0b5cac167a942a7c53931dc715c9 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 23 Nov 2023 16:38:31 -0800 Subject: [PATCH 8/8] Sort unstable items last in rustdoc, instead of first --- src/librustdoc/html/render/print_item.rs | 4 ++-- tests/rustdoc/stability.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 927bec4251e57..ce9e1bcf4883a 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -369,8 +369,8 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: if let (Some(a), Some(b)) = (s1, s2) { match (a.is_stable(), b.is_stable()) { (true, true) | (false, false) => {} - (false, true) => return Ordering::Less, - (true, false) => return Ordering::Greater, + (false, true) => return Ordering::Greater, + (true, false) => return Ordering::Less, } } let lhs = i1.name.unwrap_or(kw::Empty); diff --git a/tests/rustdoc/stability.rs b/tests/rustdoc/stability.rs index 5d8286d8116f2..c4d7118d07ff0 100644 --- a/tests/rustdoc/stability.rs +++ b/tests/rustdoc/stability.rs @@ -3,9 +3,9 @@ #![unstable(feature = "test", issue = "none")] // @has stability/index.html -// @has - '//ul[@class="item-table"]/li[1]//a' Unstable -// @has - '//ul[@class="item-table"]/li[2]//a' AaStable -// @has - '//ul[@class="item-table"]/li[3]//a' ZzStable +// @has - '//ul[@class="item-table"]/li[1]//a' AaStable +// @has - '//ul[@class="item-table"]/li[2]//a' ZzStable +// @has - '//ul[@class="item-table"]/li[3]//a' Unstable #[stable(feature = "rust2", since = "2.2.2")] pub struct AaStable;