Description
Code in doc comments may require specific Cargo features or platforms, but currently the syntax for disabling doctests is non-obvious, verbose, and by mixing languages and syntaxes, it doesn't play well with Markdown syntax highlighting:
#![cfg_attr(feature = "alloc", doc = " ```")]
#![cfg_attr(not(feature = "alloc"), doc = " ```ignore")]
//! code
//! ```
I suggest supporting #![cfg(…)]
inside doctests, injected into the test code in a way that disables a block of code containing the test. Currently #![cfg(feature = …)]
doesn't work at all in doctests, because it gets hoisted to be a real crate attribute, and ends up disabling entire the test module.
//! ```rust
//! #![cfg(feature = "alloc")] // proposed syntax
//! code
//! ```
In the implementation I think it would require wrapping "everything_else" code in extra { }
, and keeping #![cfg(feature = …)]
attrs in the code, instead of extracting them and hoisting them to the top level of the doctest crate.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status