Description
Code
my_module.rs
//! Malformed example
//!
//! ```
//! not valid rust code
//! ```
lib.rs
/// Some outer doc, remove/comment it to get the output I would expect
pub mod my_module;
cargo +nightly test --doc
Current output
cargo +nightly test --doc
Compiling doctest_wrong_line v0.1.0 (/doctest_wrong_line)
Finished test [unoptimized + debuginfo] target(s) in 0.02s
Doc-tests doctest_wrong_line
running 1 test
test src/lib.rs - my_module (line 4) ... FAILED
failures:
---- src/lib.rs - my_module (line 4) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `valid`
--> src/lib.rs:5:5
|
3 | not valid rust code
| ^^^^^ expected one of 8 possible tokens
error: aborting due to previous error
Couldn't compile the test.
failures:
src/lib.rs - my_module (line 4)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
error: doctest failed, to rerun pass `--doc`
Desired output
cargo +nightly test --doc
Compiling doctest_wrong_line v0.1.0 (/doctest_wrong_line)
Finished test [unoptimized + debuginfo] target(s) in 0.02s
Doc-tests doctest_wrong_line
running 1 test
test src/my_module.rs - my_module (line 3) ... FAILED
failures:
---- src/my_module.rs - my_module (line 3) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `valid`
--> src/my_module.rs:4:5
|
3 | not valid rust code
| ^^^^^ expected one of 8 possible tokens
error: aborting due to previous error
Couldn't compile the test.
failures:
src/my_module.rs - my_module (line 3)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
error: doctest failed, to rerun pass `--doc`
Rationale and extra context
the lines indicate lib.rs as the location where the failure happens which is not correct though I understand it may appear so to the compiler given it might be fusing the doc content at some point and not keep sub blocks original span (though it's confusing as I ended up in my lib.rs at a location that did not exist)
Basically adding a /// comment on top of the module on the lib.rs should not be modifying the span of the docstring coming from the module
In my case it indicated a non existent line in a rather small lib.rs
Other cases
No response
Anything else?
I tried various combinations of keywords to find related issues in the repo but could not find any (though some look similar they use an include macro which is not the case here #81070)
Thanks for the high quality of the tooling, those are edge cases which happen because well, if it can happen it will 😄
Cheers
Metadata
Metadata
Assignees
Labels
Type
Projects
Status