From 74d77d058b29568b6fa8b08a7a16295a15e8df51 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 18 Apr 2022 10:04:31 -0400 Subject: [PATCH 1/7] mark ptr-int-transmute test as no_run --- library/core/src/intrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 8e02ca8431744..f1b73d15d1e74 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -981,7 +981,7 @@ extern "rust-intrinsic" { /// /// Turning a pointer into a `usize`: /// - /// ``` + /// ```no_run /// let ptr = &0; /// let ptr_num_transmute = unsafe { /// std::mem::transmute::<&i32, usize>(ptr) From 9b36a4783101c86a7b6597804e59dae076459653 Mon Sep 17 00:00:00 2001 From: Adrian Palacios Date: Mon, 2 May 2022 14:41:21 +0000 Subject: [PATCH 2/7] Fix typo in `offset_from` documentation --- library/core/src/ptr/const_ptr.rs | 2 +- library/core/src/ptr/mut_ptr.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 7ef2e95542bba..45964c3a444fe 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -518,7 +518,7 @@ impl *const T { } /// Calculates the distance between two pointers. The returned value is in - /// units of T: the distance in bytes is divided by `mem::size_of::()`. + /// units of T: the distance in bytes divided by `mem::size_of::()`. /// /// This function is the inverse of [`offset`]. /// diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 56f9c84f5af6f..ff5207c1a06e1 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -696,7 +696,7 @@ impl *mut T { } /// Calculates the distance between two pointers. The returned value is in - /// units of T: the distance in bytes is divided by `mem::size_of::()`. + /// units of T: the distance in bytes divided by `mem::size_of::()`. /// /// This function is the inverse of [`offset`]. /// From 13b45aa6c66c8075acc95ea94d8c5cbc24a3a203 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 4 May 2022 15:39:18 +0200 Subject: [PATCH 3/7] Add rotation animation on settings button when loading --- src/librustdoc/html/static/css/rustdoc.css | 12 ++++++++++++ src/librustdoc/html/static/js/main.js | 2 +- src/librustdoc/html/static/js/settings.js | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 81c12be8e83c0..12059e0b9c4b5 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1401,6 +1401,18 @@ pre.rust { cursor: pointer; } +@keyframes rotating { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} +#settings-menu.rotate img { + animation: rotating 2s linear infinite; +} + #help-button { font-family: "Fira Sans", Arial, sans-serif; text-align: center; diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 1dfd9c762c46e..1f41d62bde346 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -300,8 +300,8 @@ function loadCss(cssFileName) { document.head.append(script); } - getSettingsButton().onclick = event => { + addClass(getSettingsButton(), "rotate"); event.preventDefault(); loadScript(window.settingsJS); }; diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 43b24245ab2e8..04c64cbb54846 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -272,5 +272,6 @@ if (!isSettingsPage) { switchDisplayedElement(settingsMenu); } + removeClass(getSettingsButton(), "rotate"); }, 0); })(); From cb131d2b4a1a56676c5f21bcf74ab373900eca2f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 5 May 2022 20:03:34 +0900 Subject: [PATCH 4/7] Add a regression test for #64173 and #66152 --- .../lifetimes/issue-64173-unused-lifetimes.rs | 19 ++++++++++ .../issue-64173-unused-lifetimes.stderr | 35 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs create mode 100644 src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr diff --git a/src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs new file mode 100644 index 0000000000000..8080dd7dc34db --- /dev/null +++ b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.rs @@ -0,0 +1,19 @@ +use std::mem::size_of; + +struct Foo<'s> { //~ ERROR: parameter `'s` is never used + array: [(); size_of::<&Self>()], + //~^ ERROR: generic `Self` types are currently not permitted in anonymous constants +} + +// The below is taken from /~https://github.com/rust-lang/rust/issues/66152#issuecomment-550275017 +// as the root cause seems the same. + +const fn foo() -> usize { + 0 +} + +struct Bar<'a> { //~ ERROR: parameter `'a` is never used + beta: [(); foo::<&'a ()>()], //~ ERROR: a non-static lifetime is not allowed in a `const` +} + +fn main() {} diff --git a/src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr new file mode 100644 index 0000000000000..a487cbea5371b --- /dev/null +++ b/src/test/ui/lifetimes/issue-64173-unused-lifetimes.stderr @@ -0,0 +1,35 @@ +error[E0658]: a non-static lifetime is not allowed in a `const` + --> $DIR/issue-64173-unused-lifetimes.rs:16:23 + | +LL | beta: [(); foo::<&'a ()>()], + | ^^ + | + = note: see issue #76560 for more information + = help: add `#![feature(generic_const_exprs)]` to the crate attributes to enable + +error: generic `Self` types are currently not permitted in anonymous constants + --> $DIR/issue-64173-unused-lifetimes.rs:4:28 + | +LL | array: [(); size_of::<&Self>()], + | ^^^^ + +error[E0392]: parameter `'s` is never used + --> $DIR/issue-64173-unused-lifetimes.rs:3:12 + | +LL | struct Foo<'s> { + | ^^ unused parameter + | + = help: consider removing `'s`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0392]: parameter `'a` is never used + --> $DIR/issue-64173-unused-lifetimes.rs:15:12 + | +LL | struct Bar<'a> { + | ^^ unused parameter + | + = help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0392, E0658. +For more information about an error, try `rustc --explain E0392`. From 87b6326d672f5d40b14460bdedebf4f69288fb6a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 5 May 2022 20:19:40 +0200 Subject: [PATCH 5/7] Improve settings loading strategy by loading CSS and JS at the same time to prevent the style to be applied afterwards on slow connections --- src/librustdoc/html/static/js/main.js | 3 +++ src/librustdoc/html/static/js/settings.js | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 1dfd9c762c46e..a6b64cd54af86 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -303,6 +303,9 @@ function loadCss(cssFileName) { getSettingsButton().onclick = event => { event.preventDefault(); + // Sending request for the CSS and the JS files at the same time so it will + // hopefully be loaded when the JS will generate the settings content. + loadCss("settings"); loadScript(window.settingsJS); }; diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js index 43b24245ab2e8..ac483dbb41973 100644 --- a/src/librustdoc/html/static/js/settings.js +++ b/src/librustdoc/html/static/js/settings.js @@ -3,7 +3,7 @@ /* eslint prefer-const: "error" */ /* eslint prefer-arrow-callback: "error" */ // Local js definitions: -/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme, loadCss */ +/* global getSettingValue, getVirtualKey, updateLocalStorage, updateSystemTheme */ /* global addClass, removeClass, onEach, onEachLazy, NOT_DISPLAYED_ID */ /* global MAIN_ID, getVar, getSettingsButton, switchDisplayedElement, getNotDisplayedElem */ @@ -207,9 +207,6 @@ }, ]; - // First, we add the settings.css file. - loadCss("settings"); - // Then we build the DOM. const el = document.createElement("section"); el.id = "settings"; From 4fcbc53820ab423bbeb41f07822369aa05da1d68 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 5 May 2022 21:38:15 +0200 Subject: [PATCH 6/7] Implement [OsStr]::join --- library/std/src/ffi/os_str.rs | 17 +++++++++++++++++ library/std/src/ffi/os_str/tests.rs | 14 ++++++++++++++ library/std/src/lib.rs | 2 ++ 3 files changed, 33 insertions(+) diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 9b5e5d6c0cc4b..dd316bdb2c6ce 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1222,6 +1222,23 @@ impl OsStr { } } +#[unstable(feature = "slice_concat_ext", issue = "27747")] +impl> alloc::slice::Join<&OsStr> for [S] { + type Output = OsString; + + fn join(slice: &Self, sep: &OsStr) -> OsString { + let Some(first) = slice.first() else { + return OsString::new(); + }; + let first = first.borrow().to_owned(); + slice[1..].iter().fold(first, |mut a, b| { + a.push(sep); + a.push(b.borrow()); + a + }) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Borrow for OsString { #[inline] diff --git a/library/std/src/ffi/os_str/tests.rs b/library/std/src/ffi/os_str/tests.rs index 283f2b577e896..d7926749aae20 100644 --- a/library/std/src/ffi/os_str/tests.rs +++ b/library/std/src/ffi/os_str/tests.rs @@ -84,6 +84,20 @@ fn test_os_string_reserve_exact() { assert!(os_string.capacity() >= 33) } +#[test] +fn test_os_string_join() { + let strings = [OsStr::new("hello"), OsStr::new("dear"), OsStr::new("world")]; + assert_eq!("hello", strings[..1].join(OsStr::new(" "))); + assert_eq!("hello dear world", strings.join(OsStr::new(" "))); + assert_eq!("hellodearworld", strings.join(OsStr::new(""))); + assert_eq!("hello.\n dear.\n world", strings.join(OsStr::new(".\n "))); + + assert_eq!("dear world", strings[1..].join(&OsString::from(" "))); + + let strings_abc = [OsString::from("a"), OsString::from("b"), OsString::from("c")]; + assert_eq!("a b c", strings_abc.join(OsStr::new(" "))); +} + #[test] fn test_os_string_default() { let os_string: OsString = Default::default(); diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 97c30c422827e..d70befa9d20c8 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -241,6 +241,7 @@ #![feature(intra_doc_pointers)] #![feature(lang_items)] #![feature(let_chains)] +#![feature(let_else)] #![feature(linkage)] #![feature(min_specialization)] #![feature(must_not_suspend)] @@ -300,6 +301,7 @@ #![feature(toowned_clone_into)] #![feature(try_reserve_kind)] #![feature(vec_into_raw_parts)] +#![feature(slice_concat_trait)] // // Library features (unwind): #![feature(panic_unwind)] From 2ed38cdbdd3670790aaf3d48ab2bbdf10dad290b Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 6 May 2022 07:28:06 +0900 Subject: [PATCH 7/7] Add `track_caller` to `DefId::expect_local()` --- compiler/rustc_span/src/def_id.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index d5f806308cf41..6b529d5e0837b 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -279,6 +279,7 @@ impl DefId { } #[inline] + #[track_caller] pub fn expect_local(self) -> LocalDefId { self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self)) }