Skip to content

rustdoc: doctest-xcompile passes when it shouldn't #139924

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

Open
bugadani opened this issue Apr 16, 2025 · 2 comments
Open

rustdoc: doctest-xcompile passes when it shouldn't #139924

bugadani opened this issue Apr 16, 2025 · 2 comments
Labels
A-cross Area: Cross compilation A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@bugadani
Copy link
Contributor

In the following example, both doctests pass, even though they are identical except for the annotation (one of them is no_run, the other compile_fail).

Command to run: cargo test --doc -Zdoctest-xcompile -Zbuild-std=core,panic_abort --target riscv32imac-unknown-none-elf

[package]
name = "rustdoc-issue"
version = "0.1.0"
edition = "2024"

[dependencies]
esp-hal = { version = "1.0.0-beta.0", features = ["esp32c6", "unstable"] }
#![no_std]

#[macro_export]
macro_rules! pre {
    () => {
        r#"
        # #![no_std]
        # #![no_main]
        #
        # use esp_hal as _;
        #
        # #[panic_handler]
        # fn panic(_ : &core::panic::PanicInfo) -> ! {
        #     loop {}
        # }

        # fn example() {
        "#
    };
}

/// ```rust,compile_fail
#[doc = crate::pre!()]
/// let mut x = 5;
/// x += 2;
/// }
/// ```
fn _foo() {}

/// ```rust,no_run
#[doc = crate::pre!()]
/// let mut x = 5;
/// x += 2;
/// }
/// ```
fn _foo2() {}

Since the no_run test case compiles, I would expect the compile_fail example to fail. I can only trigger this behaviour if I reference esp_hal - I'm not sure if other third party dependencies would trigger it. Without the external dependency, the annotation works as expected.

rustc --version
rustc 1.88.0-nightly (092a284ba 2025-04-13)
@bugadani bugadani added the C-bug Category: This is a bug. label Apr 16, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2025
@fmease fmease added A-cross Area: Cross compilation A-doctests Area: Documentation tests, run by rustdoc requires-nightly This issue requires a nightly compiler in some way. labels Apr 16, 2025
@jieyouxu jieyouxu added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 17, 2025
@ehuss
Copy link
Contributor

ehuss commented Apr 17, 2025

I believe the issue here is that no_run does not actually compile or link the test. It does the equivalent of cargo check, which works for that example. The compile_fail one does the full build/linking, but the linking fails, and thus it passes.

(This is mostly unrelated to cross-compiling, any post-analysis error will cause this.)

There is more discussion of this in #49514.

@bugadani
Copy link
Contributor Author

Ah great, so what I really need is a check_fail annotation :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross Area: Cross compilation A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

No branches or pull requests

5 participants