Skip to content

rustdoc incorrectly evaluates and fails due to panic in zerocopy #122758

Closed
@Mark-Simulacrum

Description

@Mark-Simulacrum

This code:

extern crate zerocopy;

pub use std::cell::RefMut as LockGuard;

with Cargo.toml:

[package]
name = "test-rustdoc-bug"
version = "0.1.0"
edition = "2021"

[dependencies]
zerocopy = "0.7.32"

produces the following error:

$ RUSTDOCFLAGS="-Zunstable-options --document-hidden-items" cargo +nightly doc
 Documenting test-rustdoc-bug v0.1.0 (/Users/mark/test-rustdoc-bug)
error[E0080]: evaluation of `<std::cell::RefMut<'_, [u8]> as zerocopy::ByteSlice>::INTO_REF_INTO_MUT_ARE_SOUND` failed
    --> /Users/mark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.32/src/lib.rs:5238:9
     |
5238 |         panic!("Ref::into_ref and Ref::into_mut are unsound when used with core::cell::RefMut; see https://github.com/google/zerocopy/issues/716")
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Ref::into_ref and Ref::into_mut are unsound when used with core::cell::RefMut; see https://github.com/google/zerocopy/issues/716', /Users/mark/.cargo/registry/src/index.crates.io-6f17d22bba15001f/zerocopy-0.7.32/src/lib.rs:5238:9
     |
     = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0080`.
error: could not document `test-rustdoc-bug`

This seems to happen on all(?) of current stable (1.77), beta (1.78), and nightly (1.79, 3c85e56 2024-03-18) but I'm suspicious that there's some kind of new breakage here in 1.78, because this broke rust-lang/rust's CI on similar code (in rustc_data_structures): #122754 (comment) while performing a bump of the bootstrap compiler from 1.77 to 1.78. This minimal example appears to reproduce across all versions. Tagging this as a regression for now despite lacking a minimal reproducer demonstrating that.

I think this is likely a bug of some kind in rustdoc regardless, because presumably it's not intentional that we should fail to document (benign-looking) code like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions