Skip to content

Rollup of 6 pull requests #141379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
})
}
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
Expand Down
8 changes: 1 addition & 7 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Information about the item’s deprecation, if present.
pub deprecation: Option<Deprecation>,
Expand Down
26 changes: 26 additions & 0 deletions tests/rustdoc-gui/collapse-trait-impl.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Checks that individual trait impls can only be collapsed via clicking directly on the summary element

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": ""})
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-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": ""})
1 change: 1 addition & 0 deletions tests/rustdoc-gui/src/test_docs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl Foo {
pub fn warning2() {}
}

/// <a href="#implementations"><code id="trait-impl-link-in-summary">A collapsible trait impl with a link</code></a>
impl AsRef<str> for Foo {
fn as_ref(&self) -> &str {
"hello"
Expand Down
11 changes: 11 additions & 0 deletions tests/rustdoc-json/attrs/inline.rs
Original file line number Diff line number Diff line change
@@ -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() {}
6 changes: 3 additions & 3 deletions tests/ui/transmute/unnecessary-transmutation.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/transmute/unnecessary-transmutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 1 addition & 7 deletions tests/ui/transmute/unnecessary-transmutation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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