From 838e742ea49648d63461b41ea330a9a1ed086c02 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Fri, 9 May 2025 20:28:51 +0200 Subject: [PATCH 01/10] rustdoc: Fix links in trait impl docs --- src/librustdoc/html/static/js/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index a7ce2bf9048bf..7b1a61a3ffa45 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -1179,8 +1179,10 @@ function preLoadCss(cssUrl) { onEachLazy(document.querySelectorAll(".toggle > summary:not(.hideme)"), el => { // @ts-expect-error + // Clicking on the summary's contents should not collapse it, + // but links within should still fire. el.addEventListener("click", e => { - if (e.target.tagName !== "SUMMARY" && e.target.tagName !== "A") { + if (!e.target.matches("summary, a, a *")) { e.preventDefault(); } }); From 31ae60d30d96b32c35a3dd5239a68997c9d4a27d Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sat, 10 May 2025 19:24:59 +0200 Subject: [PATCH 02/10] gui test --- tests/rustdoc-gui/collapse-trait-impl.goml | 23 ++++++++++++++++++++++ tests/rustdoc-gui/src/test_docs/lib.rs | 1 + 2 files changed, 24 insertions(+) create mode 100644 tests/rustdoc-gui/collapse-trait-impl.goml diff --git a/tests/rustdoc-gui/collapse-trait-impl.goml b/tests/rustdoc-gui/collapse-trait-impl.goml new file mode 100644 index 0000000000000..dc1170a831aef --- /dev/null +++ b/tests/rustdoc-gui/collapse-trait-impl.goml @@ -0,0 +1,23 @@ +// Checks that individual trait impls can only be collapsed via clicking directly on the summary element +include: "utils.goml" + +go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" +assert-attribute: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) + +// Collapse the trait impl doc. The actual clickable area is outside the element, hence offset. +click-with-offset: ("summary:has(#trait-impl-link-in-summary)", {"x": -15, "y": 5}) +assert-attribute-false: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) + +// Clicks on the text should be ignored +click: "summary:has(#trait-impl-link-in-summary) > .impl" +assert-window-property: ({"pageYOffset": "0"}) + +// But links should still work +click: "#trait-impl-link-in-summary" +assert-window-property-false: ({"pageYOffset": "0"}) + +// As well as clicks on elements within links +go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" +assert-window-property: ({"pageYOffset": "0"}) +click: "#trait-impl-link-in-summary" +assert-window-property-false: ({"pageYOffset": "0"}) diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs index bb0015b8f9c43..e8afe8b568727 100644 --- a/tests/rustdoc-gui/src/test_docs/lib.rs +++ b/tests/rustdoc-gui/src/test_docs/lib.rs @@ -79,6 +79,7 @@ impl Foo { pub fn warning2() {} } +/// A collapsible trait impl with a link impl AsRef for Foo { fn as_ref(&self) -> &str { "hello" From bd23ee2382ae8f940771dc08be5e234f6963ba72 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sat, 10 May 2025 19:48:13 +0200 Subject: [PATCH 03/10] gui test different link --- tests/rustdoc-gui/collapse-trait-impl.goml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rustdoc-gui/collapse-trait-impl.goml b/tests/rustdoc-gui/collapse-trait-impl.goml index dc1170a831aef..5f95dcc01c11c 100644 --- a/tests/rustdoc-gui/collapse-trait-impl.goml +++ b/tests/rustdoc-gui/collapse-trait-impl.goml @@ -13,7 +13,7 @@ click: "summary:has(#trait-impl-link-in-summary) > .impl" assert-window-property: ({"pageYOffset": "0"}) // But links should still work -click: "#trait-impl-link-in-summary" +click: "summary:has(#trait-impl-link-in-summary) a:has(#trait-impl-link-in-summary)" assert-window-property-false: ({"pageYOffset": "0"}) // As well as clicks on elements within links From b8d55544c5442a3d556c54af9a1956e1578da0e4 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sun, 11 May 2025 07:58:18 +0200 Subject: [PATCH 04/10] remove superfluous import --- tests/rustdoc-gui/collapse-trait-impl.goml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/rustdoc-gui/collapse-trait-impl.goml b/tests/rustdoc-gui/collapse-trait-impl.goml index 5f95dcc01c11c..9b2e76a3ef912 100644 --- a/tests/rustdoc-gui/collapse-trait-impl.goml +++ b/tests/rustdoc-gui/collapse-trait-impl.goml @@ -1,5 +1,4 @@ // Checks that individual trait impls can only be collapsed via clicking directly on the summary element -include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" assert-attribute: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) From 4516a5b96bbf8ba39dd74913aac7297c0c0f2ab6 Mon Sep 17 00:00:00 2001 From: SpecificProtagonist Date: Sun, 11 May 2025 08:02:19 +0200 Subject: [PATCH 05/10] better checks --- tests/rustdoc-gui/collapse-trait-impl.goml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/rustdoc-gui/collapse-trait-impl.goml b/tests/rustdoc-gui/collapse-trait-impl.goml index 9b2e76a3ef912..4db02e5239b5e 100644 --- a/tests/rustdoc-gui/collapse-trait-impl.goml +++ b/tests/rustdoc-gui/collapse-trait-impl.goml @@ -6,17 +6,21 @@ assert-attribute: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) // Collapse the trait impl doc. The actual clickable area is outside the element, hence offset. click-with-offset: ("summary:has(#trait-impl-link-in-summary)", {"x": -15, "y": 5}) assert-attribute-false: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) +click-with-offset: ("summary:has(#trait-impl-link-in-summary)", {"x": -15, "y": 5}) +assert-attribute: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) // Clicks on the text should be ignored click: "summary:has(#trait-impl-link-in-summary) > .impl" -assert-window-property: ({"pageYOffset": "0"}) +assert-attribute: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) // But links should still work click: "summary:has(#trait-impl-link-in-summary) a:has(#trait-impl-link-in-summary)" assert-window-property-false: ({"pageYOffset": "0"}) +assert-attribute: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) // As well as clicks on elements within links go-to: "file://" + |DOC_PATH| + "/test_docs/struct.Foo.html" assert-window-property: ({"pageYOffset": "0"}) click: "#trait-impl-link-in-summary" assert-window-property-false: ({"pageYOffset": "0"}) +assert-attribute: ("details:has(#trait-impl-link-in-summary)", {"open": ""}) From de8e8641ae8194009b13dcca997e1eaa991b2888 Mon Sep 17 00:00:00 2001 From: bendn Date: Tue, 29 Apr 2025 13:06:21 +0700 Subject: [PATCH 06/10] dont handle bool transmute --- .../src/check_unnecessary_transmutes.rs | 3 +-- tests/ui/transmute/unnecessary-transmutation.fixed | 6 +++--- tests/ui/transmute/unnecessary-transmutation.rs | 4 ++-- tests/ui/transmute/unnecessary-transmutation.stderr | 8 +------- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs b/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs index 8da17a056e31b..0514de3ea13fb 100644 --- a/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs +++ b/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs @@ -9,6 +9,7 @@ use crate::errors::UnnecessaryTransmute as Error; /// Check for transmutes that overlap with stdlib methods. /// For example, transmuting `[u8; 4]` to `u32`. +/// We chose not to lint u8 -> bool transmutes, see #140431 pub(super) struct CheckUnnecessaryTransmutes; impl<'tcx> crate::MirLint<'tcx> for CheckUnnecessaryTransmutes { @@ -98,8 +99,6 @@ impl<'a, 'tcx> UnnecessaryTransmuteChecker<'a, 'tcx> { (Uint(_), Float(ty)) => err(format!("{}::from_bits({arg})", ty.name_str())), // bool → { x8 } (Bool, Int(..) | Uint(..)) => err(format!("({arg}) as {}", fn_sig.output())), - // u8 → bool - (Uint(_), Bool) => err(format!("({arg} == 1)")), _ => return None, }) } diff --git a/tests/ui/transmute/unnecessary-transmutation.fixed b/tests/ui/transmute/unnecessary-transmutation.fixed index bf7d769348aaf..f6478c5aa5c2f 100644 --- a/tests/ui/transmute/unnecessary-transmutation.fixed +++ b/tests/ui/transmute/unnecessary-transmutation.fixed @@ -81,13 +81,13 @@ fn main() { let y: i64 = f64::to_bits(1f64).cast_signed(); //~^ ERROR - let z: bool = (1u8 == 1); - //~^ ERROR + let z: bool = transmute(1u8); + // clippy let z: u8 = (z) as u8; //~^ ERROR let z: bool = transmute(1i8); - // no error! + // clippy let z: i8 = (z) as i8; //~^ ERROR } diff --git a/tests/ui/transmute/unnecessary-transmutation.rs b/tests/ui/transmute/unnecessary-transmutation.rs index b9de529f1cccd..ab0af03acc2ec 100644 --- a/tests/ui/transmute/unnecessary-transmutation.rs +++ b/tests/ui/transmute/unnecessary-transmutation.rs @@ -82,12 +82,12 @@ fn main() { //~^ ERROR let z: bool = transmute(1u8); - //~^ ERROR + // clippy let z: u8 = transmute(z); //~^ ERROR let z: bool = transmute(1i8); - // no error! + // clippy let z: i8 = transmute(z); //~^ ERROR } diff --git a/tests/ui/transmute/unnecessary-transmutation.stderr b/tests/ui/transmute/unnecessary-transmutation.stderr index a19f1bebf16fd..59e933bbc81b9 100644 --- a/tests/ui/transmute/unnecessary-transmutation.stderr +++ b/tests/ui/transmute/unnecessary-transmutation.stderr @@ -239,12 +239,6 @@ error: unnecessary transmute LL | let y: i64 = transmute(1f64); | ^^^^^^^^^^^^^^^ help: replace this with: `f64::to_bits(1f64).cast_signed()` -error: unnecessary transmute - --> $DIR/unnecessary-transmutation.rs:84:23 - | -LL | let z: bool = transmute(1u8); - | ^^^^^^^^^^^^^^ help: replace this with: `(1u8 == 1)` - error: unnecessary transmute --> $DIR/unnecessary-transmutation.rs:86:21 | @@ -257,5 +251,5 @@ error: unnecessary transmute LL | let z: i8 = transmute(z); | ^^^^^^^^^^^^ help: replace this with: `(z) as i8` -error: aborting due to 36 previous errors +error: aborting due to 35 previous errors From 78d3ea14f700037860db6cf98728cede523c7aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 20 May 2025 15:16:16 +0200 Subject: [PATCH 07/10] Add bors environment to CI This will be used to access secrets once we move off rust-lang-ci. --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93316b9cff7b1..0bce8389d8ec2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,15 @@ jobs: needs: [ calculate_matrix ] runs-on: "${{ matrix.os }}" timeout-minutes: 360 + # The bors environment contains secrets required for elevated workflows (try and auto builds), + # which need to access e.g. S3 and upload artifacts. We want to provide access to that + # environment only on the try/auto branches, which are only accessible to bors. + # This also ensures that PR CI (which doesn't get write access to S3) works, as it cannot + # access the environment. + # + # We only enable the environment for the rust-lang/rust repository, so that rust-lang-ci/rust + # CI works until we migrate off it (since that repository doesn't contain the environment). + environment: ${{ ((github.repository == 'rust-lang/rust' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/auto')) && 'bors') || '' }} env: CI_JOB_NAME: ${{ matrix.name }} CI_JOB_DOC_URL: ${{ matrix.doc_url }} From 4502ae8c69f7f672108a64181c1f15013fafa9c4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 21 May 2025 13:41:58 +0200 Subject: [PATCH 08/10] bump stdarch --- library/stdarch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/stdarch b/library/stdarch index 1dfaa4db24797..b6e2249e388f5 160000 --- a/library/stdarch +++ b/library/stdarch @@ -1 +1 @@ -Subproject commit 1dfaa4db2479753a46a3e90f2c3c89d89d0b21f1 +Subproject commit b6e2249e388f520627544812649b77b0944e1a2e From 8cdfabd230282f11a04de6d638546bf52ba0bf24 Mon Sep 17 00:00:00 2001 From: Alona Enraght-Moony Date: Wed, 21 May 2025 19:43:45 +0000 Subject: [PATCH 09/10] rustdoc-json: Remove false docs and add test for inline attribute The docs about how `#[inline]` was represented isn't true. Updates the comment, and adds a test. CC https://www.github.com/rust-lang/rust/issues/137645 --- src/rustdoc-json-types/lib.rs | 8 +------- tests/rustdoc-json/attrs/inline.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 tests/rustdoc-json/attrs/inline.rs diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 64223b5b75896..0b8a906529466 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -180,19 +180,13 @@ pub struct Item { /// /// Does not include `#[deprecated]` attributes: see the [`Self::deprecation`] field instead. /// - /// Some attributes appear in pretty-printed Rust form, regardless of their formatting + /// Attributes appear in pretty-printed Rust form, regardless of their formatting /// in the original source code. For example: /// - `#[non_exhaustive]` and `#[must_use]` are represented as themselves. /// - `#[no_mangle]` and `#[export_name]` are also represented as themselves. /// - `#[repr(C)]` and other reprs also appear as themselves, /// though potentially with a different order: e.g. `repr(i8, C)` may become `repr(C, i8)`. /// Multiple repr attributes on the same item may be combined into an equivalent single attr. - /// - /// Other attributes may appear debug-printed. For example: - /// - `#[inline]` becomes something similar to `#[attr="Inline(Hint)"]`. - /// - /// As an internal implementation detail subject to change, this debug-printing format - /// is currently equivalent to the HIR pretty-printing of parsed attributes. pub attrs: Vec, /// Information about the item’s deprecation, if present. pub deprecation: Option, diff --git a/tests/rustdoc-json/attrs/inline.rs b/tests/rustdoc-json/attrs/inline.rs new file mode 100644 index 0000000000000..74f5f36f03f3b --- /dev/null +++ b/tests/rustdoc-json/attrs/inline.rs @@ -0,0 +1,11 @@ +//@ is "$.index[?(@.name=='just_inline')].attrs" '["#[inline]"]' +#[inline] +pub fn just_inline() {} + +//@ is "$.index[?(@.name=='inline_always')].attrs" '["#[inline(always)]"]' +#[inline(always)] +pub fn inline_always() {} + +//@ is "$.index[?(@.name=='inline_never')].attrs" '["#[inline(never)]"]' +#[inline(never)] +pub fn inline_never() {} From cff790c98e9601281accf86f9c80cf894727564b Mon Sep 17 00:00:00 2001 From: waffle Date: Wed, 21 May 2025 23:43:57 +0200 Subject: [PATCH 10/10] add doc alias `replace_first` for `str::replacen` --- library/alloc/src/str.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 8766fd904b074..f1b1734b8b2d0 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -320,6 +320,7 @@ impl str { /// ``` #[cfg(not(no_global_oom_handling))] #[rustc_allow_incoherent_impl] + #[doc(alias = "replace_first")] #[must_use = "this returns the replaced string as a new allocation, \ without modifying the original"] #[stable(feature = "str_replacen", since = "1.16.0")]