From c05276ae7b5996049be7b34e497021e3e28156cd Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 2 Feb 2022 12:52:58 +0100 Subject: [PATCH 01/13] Stabilize pin_static_ref. --- library/core/src/pin.rs | 4 ++-- library/std/src/lib.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 09fc6df542975..8cae48e4aba2b 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -798,7 +798,7 @@ impl Pin<&'static T> { /// /// This is safe, because `T` is borrowed for the `'static` lifetime, which /// never ends. - #[unstable(feature = "pin_static_ref", issue = "78186")] + #[stable(feature = "pin_static_ref", since = "1.60.0")] #[rustc_const_unstable(feature = "const_pin", issue = "76654")] pub const fn static_ref(r: &'static T) -> Pin<&'static T> { // SAFETY: The 'static borrow guarantees the data will not be @@ -851,7 +851,7 @@ impl Pin<&'static mut T> { /// /// This is safe, because `T` is borrowed for the `'static` lifetime, which /// never ends. - #[unstable(feature = "pin_static_ref", issue = "78186")] + #[stable(feature = "pin_static_ref", since = "1.60.0")] #[rustc_const_unstable(feature = "const_pin", issue = "76654")] pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> { // SAFETY: The 'static borrow guarantees the data will not be diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 4f44a3183a6ec..c53101538ecb1 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -310,7 +310,6 @@ #![feature(panic_internals)] #![feature(panic_can_unwind)] #![feature(panic_unwind)] -#![feature(pin_static_ref)] #![feature(platform_intrinsics)] #![feature(portable_simd)] #![feature(prelude_import)] From bc4b0a774cb371e047310c6777477c754aedbb7e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 14 Feb 2022 21:42:18 +0100 Subject: [PATCH 02/13] Fix macro reexports duplicates in the sidebar --- src/librustdoc/html/render/context.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 2455d56bd2b3f..a7f852a432c82 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -250,6 +250,8 @@ impl<'tcx> Context<'tcx> { fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap> { // BTreeMap instead of HashMap to get a sorted output let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new(); + let mut inserted: FxHashMap> = FxHashMap::default(); + for item in &m.items { if item.is_stripped() { continue; @@ -258,13 +260,16 @@ impl<'tcx> Context<'tcx> { let short = item.type_(); let myname = match item.name { None => continue, - Some(ref s) => s.to_string(), + Some(s) => s, }; - let short = short.to_string(); - map.entry(short).or_default().push(( - myname, - Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))), - )); + if inserted.entry(short).or_default().insert(myname) { + let short = short.to_string(); + let myname = myname.to_string(); + map.entry(short).or_default().push(( + myname, + Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))), + )); + } } if self.shared.sort_modules_alphabetically { From d9ea7bc98d760b1bfabf192bbadf7e73df0ade68 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 14 Feb 2022 21:42:36 +0100 Subject: [PATCH 03/13] Add test for duplicated macros in the sidebar --- src/test/rustdoc-gui/duplicate-macro-reexport.goml | 14 ++++++++++++++ src/test/rustdoc-gui/src/test_docs/lib.rs | 3 +++ src/test/rustdoc-gui/src/test_docs/macros.rs | 4 ++++ 3 files changed, 21 insertions(+) create mode 100644 src/test/rustdoc-gui/duplicate-macro-reexport.goml create mode 100644 src/test/rustdoc-gui/src/test_docs/macros.rs diff --git a/src/test/rustdoc-gui/duplicate-macro-reexport.goml b/src/test/rustdoc-gui/duplicate-macro-reexport.goml new file mode 100644 index 0000000000000..c79b3a220c42c --- /dev/null +++ b/src/test/rustdoc-gui/duplicate-macro-reexport.goml @@ -0,0 +1,14 @@ +// This test ensures that there is no macro duplicates in the sidebar. +goto: file://|DOC_PATH|/test_docs/macro.a.html +// Waiting for the elements in the sidebar to be rendered. +wait-for: ".sidebar-elems .others .macro" +// Check there is only one macro named "a" listed in the sidebar. +assert-count: ( + "//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='a']", + 1, +) +// Check there is only one macro named "b" listed in the sidebar. +assert-count: ( + "//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='b']", + 1, +) diff --git a/src/test/rustdoc-gui/src/test_docs/lib.rs b/src/test/rustdoc-gui/src/test_docs/lib.rs index 2068d1d6f39af..348b1a65c786c 100644 --- a/src/test/rustdoc-gui/src/test_docs/lib.rs +++ b/src/test/rustdoc-gui/src/test_docs/lib.rs @@ -271,3 +271,6 @@ impl EmptyTrait1 for HasEmptyTraits {} impl EmptyTrait2 for HasEmptyTraits {} #[doc(cfg(feature = "some-feature"))] impl EmptyTrait3 for HasEmptyTraits {} + +mod macros; +pub use macros::*; diff --git a/src/test/rustdoc-gui/src/test_docs/macros.rs b/src/test/rustdoc-gui/src/test_docs/macros.rs new file mode 100644 index 0000000000000..07b2b97926d43 --- /dev/null +++ b/src/test/rustdoc-gui/src/test_docs/macros.rs @@ -0,0 +1,4 @@ +#[macro_export] +macro_rules! a{ () => {}} +#[macro_export] +macro_rules! b{ () => {}} From 4b5beae0b2626bd8936856494b06d60b9a6e42ac Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 15 Feb 2022 15:17:22 +0100 Subject: [PATCH 04/13] adapt static-nobundle test to use llvm-nm No functional changes intended. This updates the test case to use llvm-nm instead of the system nm. This fixes an instance over at the experimental build of rustc with HEAD LLVM: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/8380#ef6f41b5-8595-49a6-be37-0eff80e0ccb5 It is related to https://github.com/rust-lang/rust/pull/94001. The issue is that this test uses the system nm, which may not be recent enough to understand the update to uwtable. This replaces the test to use the llvm-nm that should be recent enough (consistent with the LLVM sources we use to build rustc). --- src/test/run-make-fulldeps/static-nobundle/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/run-make-fulldeps/static-nobundle/Makefile b/src/test/run-make-fulldeps/static-nobundle/Makefile index 8f78c401a1141..001081798a6e4 100644 --- a/src/test/run-make-fulldeps/static-nobundle/Makefile +++ b/src/test/run-make-fulldeps/static-nobundle/Makefile @@ -9,8 +9,10 @@ all: $(call NATIVE_STATICLIB,aaa) $(RUSTC) bbb.rs --crate-type=rlib # Check that bbb does NOT contain the definition of `native_func` - nm $(TMPDIR)/libbbb.rlib | $(CGREP) -ve "T _*native_func" - nm $(TMPDIR)/libbbb.rlib | $(CGREP) -e "U _*native_func" + # We're using the llvm-nm instead of the system nm to ensure it + # is compatible with the LLVM bitcode generated by rustc. + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbbb.rlib | $(CGREP) -ve "T _*native_func" + "$(LLVM_BIN_DIR)/llvm-nm" $(TMPDIR)/libbbb.rlib | $(CGREP) -e "U _*native_func" # Check that aaa gets linked (either as `-l aaa` or `aaa.lib`) when building ccc. $(RUSTC) ccc.rs -C prefer-dynamic --crate-type=dylib --print link-args | $(CGREP) -e '-l[" ]*aaa|aaa\.lib' From 0647e3890435b387f7815e0e9bfb1786e1787d9f Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Wed, 16 Feb 2022 14:13:09 +0100 Subject: [PATCH 05/13] add llvm-nm to bootstrap dist bin's --- src/bootstrap/dist.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 472ee3fb01474..17a8fde0ccfea 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -2060,6 +2060,7 @@ impl Step for RustDev { "llvm-bcanalyzer", "llvm-cov", "llvm-dwp", + "llvm-nm", ] { tarball.add_file(src_bindir.join(exe(bin, target)), "bin", 0o755); } From e5f7239e36bf6aa5f5bea0388a6b766cd5e8d151 Mon Sep 17 00:00:00 2001 From: Chris Copeland Date: Wed, 16 Feb 2022 22:02:58 -0800 Subject: [PATCH 06/13] use BOOL for TCP_NODELAY setsockopt value on Windows This issue was found by the Wine project and mitigated there [1]. Windows' setsockopt expects a BOOL (a typedef for int) for TCP_NODELAY [2]. Windows itself is forgiving and will accept any positive optlen and interpret the first byte of *optval as the value, so this bug does not affect Windows itself, but does affect systems implementing Windows' interface more strictly, such as Wine. Wine was previously passing this through to the host's setsockopt, where, e.g., Linux requires that optlen be correct for the chosen option, and TCP_NODELAY expects an int. [1]: https://source.winehq.org/git/wine.git/commit/d6ea38f32dfd3edbe107a255c37e9f7f3da06ae7 [2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt --- library/std/src/sys/windows/net.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/windows/net.rs b/library/std/src/sys/windows/net.rs index aa6400aeefa0d..5de1231378488 100644 --- a/library/std/src/sys/windows/net.rs +++ b/library/std/src/sys/windows/net.rs @@ -407,11 +407,11 @@ impl Socket { } pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { - net::setsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY, nodelay as c::BYTE) + net::setsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY, nodelay as c::BOOL) } pub fn nodelay(&self) -> io::Result { - let raw: c::BYTE = net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)?; + let raw: c::BOOL = net::getsockopt(self, c::IPPROTO_TCP, c::TCP_NODELAY)?; Ok(raw != 0) } From 5cf827421e0b5467fa50f897e2625d691835a109 Mon Sep 17 00:00:00 2001 From: pierwill Date: Thu, 17 Feb 2022 13:07:33 -0600 Subject: [PATCH 07/13] Add module-level docs for `rustc_middle::query` --- compiler/rustc_middle/src/query/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 43cfe6f3b8a7a..be86f1e92744e 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1,3 +1,9 @@ +//! Defines the various compiler queries. +//! +//! For more information on the query system, see +//! ["Queries: demand-driven compilation"](https://rustc-dev-guide.rust-lang.org/query.html). +//! This chapter includes instructions for adding new queries. + // Each of these queries corresponds to a function pointer field in the // `Providers` struct for requesting a value of that type, and a method // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way From f7448a77e4d9ddb2e0b52905a6a89cab86ea35f6 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sun, 6 Feb 2022 02:20:53 +0100 Subject: [PATCH 08/13] core: Implement trim functions on byte slices Co-authored-by: Jubilee Young --- library/core/src/slice/ascii.rs | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index 080256f493f5f..a4ad85c9202bc 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -80,6 +80,84 @@ impl [u8] { pub fn escape_ascii(&self) -> EscapeAscii<'_> { EscapeAscii { inner: self.iter().flat_map(EscapeByte) } } + + /// Returns a byte slice with leading ASCII whitespace bytes removed. + /// + /// 'Whitespace' refers to the definition used by + /// `u8::is_ascii_whitespace`. + /// + /// # Examples + /// + /// ``` + /// #![feature(byte_slice_trim_ascii)] + /// + /// assert_eq!(b" \t hello world\n".trim_ascii_start(), b"hello world\n"); + /// assert_eq!(b" ".trim_ascii_start(), b""); + /// assert_eq!(b"".trim_ascii_start(), b""); + /// ``` + #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + pub const fn trim_ascii_start(&self) -> &[u8] { + let mut bytes = self; + // Note: A pattern matching based approach (instead of indexing) allows + // making the function const. + while let [first, rest @ ..] = bytes { + if first.is_ascii_whitespace() { + bytes = rest; + } else { + break; + } + } + bytes + } + + /// Returns a byte slice with trailing ASCII whitespace bytes removed. + /// + /// 'Whitespace' refers to the definition used by + /// `u8::is_ascii_whitespace`. + /// + /// # Examples + /// + /// ``` + /// #![feature(byte_slice_trim_ascii)] + /// + /// assert_eq!(b"\r hello world\n ".trim_ascii_end(), b"\r hello world"); + /// assert_eq!(b" ".trim_ascii_end(), b""); + /// assert_eq!(b"".trim_ascii_end(), b""); + /// ``` + #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + pub const fn trim_ascii_end(&self) -> &[u8] { + let mut bytes = self; + // Note: A pattern matching based approach (instead of indexing) allows + // making the function const. + while let [rest @ .., last] = bytes { + if last.is_ascii_whitespace() { + bytes = rest; + } else { + break; + } + } + bytes + } + + /// Returns a byte slice with leading and trailing ASCII whitespace bytes + /// removed. + /// + /// 'Whitespace' refers to the definition used by + /// `u8::is_ascii_whitespace`. + /// + /// # Examples + /// + /// ``` + /// #![feature(byte_slice_trim_ascii)] + /// + /// assert_eq!(b"\r hello world\n ".trim_ascii(), b"hello world"); + /// assert_eq!(b" ".trim_ascii(), b""); + /// assert_eq!(b"".trim_ascii(), b""); + /// ``` + #[unstable(feature = "byte_slice_trim_ascii", issue = "94035")] + pub const fn trim_ascii(&self) -> &[u8] { + self.trim_ascii_start().trim_ascii_end() + } } impl_fn_for_zst! { From 0f14bea448dfdafccbecbb6302a55191a763562a Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Thu, 17 Feb 2022 20:27:53 -0800 Subject: [PATCH 09/13] Optimize char_try_from_u32 The optimization was proposed by @falk-hueffner in https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Micro-optimizing.20char.3A.3Afrom_u32/near/272146171, and I simplified it a bit and added an explanation of why the optimization is correct. --- library/core/src/char/convert.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index 1774ddd7cbb2c..56dc2a594e176 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -271,7 +271,20 @@ impl FromStr for char { #[inline] const fn char_try_from_u32(i: u32) -> Result { - if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) { + // This is an optimized version of the check + // (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF), + // which can also be written as + // i >= 0x110000 || (i >= 0xD800 && i < 0xE000). + // + // The XOR with 0xD800 permutes the ranges such that 0xD800..0xE000 is + // mapped to 0x0000..0x0800, while keeping all the high bits outside 0xFFFF the same. + // In particular, numbers >= 0x110000 stay in this range. + // + // Subtracting 0x800 causes 0x0000..0x0800 to wrap, meaning that a single + // unsigned comparison against 0x110000 - 0x800 will detect both the wrapped + // surrogate range as well as the numbers originally larger than 0x110000. + // + if (i ^ 0xD800).wrapping_sub(0x800) >= 0x110000 - 0x800 { Err(CharTryFromError(())) } else { // SAFETY: checked that it's a legal unicode value From 56aba3c6259b54551ecc9560717f2024bf605caf Mon Sep 17 00:00:00 2001 From: Mizobrook-kan Date: Fri, 18 Feb 2022 12:37:48 +0800 Subject: [PATCH 10/13] document rustc_middle::mir::Field --- compiler/rustc_middle/src/mir/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 0688d7d2569f5..45bed85aac33c 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1841,6 +1841,15 @@ static_assert_size!(PlaceElem<'_>, 24); pub type ProjectionKind = ProjectionElem<(), ()>; rustc_index::newtype_index! { + /// A [newtype'd][wrapper] index type in the MIR [control-flow graph][CFG] + /// + /// A field (e.g., `f` in `_1.f`) is one variant of [`ProjectionElem`]. Conceptually, + /// rustc can identify that a field projection refers to two different regions of memory + /// or the same one between the base and the projection element. + /// Read more about projections in the [rustc-dev-guide][mir-datatypes] + /// [wrapper]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html#newtype + /// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg + /// [mir-datatypes]: https://rustc-dev-guide.rust-lang.org/mir/index.html#mir-data-types pub struct Field { derive [HashStable] DEBUG_FORMAT = "field[{}]" From 7c3ebec0caf23a11773c8291005649dd488ca2ee Mon Sep 17 00:00:00 2001 From: Mario Carneiro Date: Thu, 17 Feb 2022 22:14:54 -0800 Subject: [PATCH 11/13] fix --- library/core/src/char/convert.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs index 56dc2a594e176..139841368d6a1 100644 --- a/library/core/src/char/convert.rs +++ b/library/core/src/char/convert.rs @@ -6,8 +6,6 @@ use crate::fmt; use crate::mem::transmute; use crate::str::FromStr; -use super::MAX; - /// Converts a `u32` to a `char`. /// /// Note that all [`char`]s are valid [`u32`]s, and can be cast to one with From 621020892e1b03c467dbe4d29d9b89e4c8751a01 Mon Sep 17 00:00:00 2001 From: Mizobrook-kan Date: Fri, 18 Feb 2022 15:38:03 +0800 Subject: [PATCH 12/13] fix some typos --- compiler/rustc_middle/src/mir/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 45bed85aac33c..b1552ef96477a 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1844,8 +1844,8 @@ rustc_index::newtype_index! { /// A [newtype'd][wrapper] index type in the MIR [control-flow graph][CFG] /// /// A field (e.g., `f` in `_1.f`) is one variant of [`ProjectionElem`]. Conceptually, - /// rustc can identify that a field projection refers to two different regions of memory - /// or the same one between the base and the projection element. + /// rustc can identify that a field projection refers to either two different regions of memory + /// or the same one between the base and the 'projection element'. /// Read more about projections in the [rustc-dev-guide][mir-datatypes] /// [wrapper]: https://rustc-dev-guide.rust-lang.org/appendix/glossary.html#newtype /// [CFG]: https://rustc-dev-guide.rust-lang.org/appendix/background.html#cfg From b78123cdcf53b146da3739acc436eb883ee39d17 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 18 Feb 2022 17:31:38 +0100 Subject: [PATCH 13/13] Fix miniz_oxide types showing up in std --- library/std/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index a03da0682a5cd..e2cfd4a14acff 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -365,6 +365,10 @@ extern crate libc; #[allow(unused_extern_crates)] extern crate unwind; +#[doc(masked)] +#[allow(unused_extern_crates)] +extern crate miniz_oxide; + // During testing, this crate is not actually the "real" std library, but rather // it links to the real std library, which was compiled from this same source // code. So any lang items std defines are conditionally excluded (or else they