Cargo test randomly ignores all ```no_run and fails
⚓ Rust 📅 2025-10-21 👤 surdeus 👁️ 2I have some docs with pre-formatted text and just examples of code that I don't want to run as doctests. I annotated all them with no_run after ```, as the docs suggest. And suddenly cargo started to run them sometimes, and complain of all the possible deadly sins: wrong syntax, global variables, etc.
Chances of this happening is like 1 of 2.
To be sure, I dropped the entire target directory, but the effect is still the same.
What can be the reason for this?
Reasons I can think of:
- doc comments with Cyrillic
- saving files in VSCode, and then running the tests in a separate bash shell (but after I leave VSCode, and run
cargo tin the shell multiple times, the randomness is still there)
Example of doc comments:
/// Граф с 5 перекрёстками, все дороги двусторонние.
/// ```no_run
/// 0
/// +---0,3----o---2,10----+
/// | | |
/// | |1,6 |
/// | | |
/// 1 o---4,7----o2---8,11---o 3
/// | | |
/// | |9,14 |
/// | | |
/// +---5,13---o---12,15---+
/// 4
/// ```
pub fn four_squares_graph2() -> Graph {
(the triple backquote here is for convenience: when I hover the function name in tests, I see its doc formatted, and can view the ascii diagram)
Edit: I found out that if there's text at 1 space from ///, and then there's blank doc line, and then text intented with 5 spaces, the latter is treated as preformatted text, and ever highlighted in VSCode, but not seen as doctest by cargo.
3 posts - 3 participants
🏷️ Rust_feed