#[cfg(doctest)] not set?

โš“ Rust    ๐Ÿ“… 2025-11-21    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: #[cfg(doctest)] not set?

Hi. Why would the following fail during cargo test, please:

// src/lib.rs:
/// ```
/// #[cfg(not(doctest))]
/// compile_error!("NOT DOCTEST!");
/// ```
pub const _: () = {};

cargo test:

...
running 1 test
test src/lib.rs - _ (line 1) ... FAILED

failures:

---- src/lib.rs - _ (line 1) stdout ----
error: NOT DOCTEST!
 --> src/lib.rs:3:1
  |
4 | compile_error!("NOT DOCTEST!");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Couldn't compile the test.

And #[cfg(doctest)] is not set in the crate being compiled either:

// src/lib.rs:
#[cfg(not(doctest))]
compile_error!("NOT DOCTEST!");

cargo test:

Compiling cfg_doctest v0.1.0 (/tmp/cfg_doctest)
error: NOT DOCTEST!
 --> src/lib.rs:2:1
  |
2 | compile_error!("NOT DOCTEST!");

I can understand that one of them could be designed to fail - but both?!

The nearest open issue I can find is cfg(doctest) doesn't work as expected ยท Issue #67295 ยท rust-lang/rust ยท GitHub, but unsure if relevant.

3 posts - 2 participants

Read full topic

๐Ÿท๏ธ Rust_feed