Description
When using attribute an attribute like #[doc = include_str("../doc/docs.md")]
to include documentation from a file, if the file contains doctests, the resolution of relative paths in the test at compile time has changed. For example, if doc/docs.md
uses include_bytes!
, previously the path would need to be relative to the file containing #[doc]
, but in 1.82.0, it is relative to docs/docs.md
.
This is easily worked around by using absolute paths like concat!(env!("CARGO_MANIFEST_DIR"), "/src/foo")
, and I don't know if this behaviour is actually defined anywhere, but I thought I'd report it anyway.
Code
A minimal reproduction of this issue is here: https://github.com/andrewhickman/doctestissue. The doctest in this repo passes in 1.82.0 but fails to compile in 1.83.0 with
> cargo test --doc
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.01s
Doc-tests doctestissue
running 1 test
test src\../doc/docs.md - (line 3) ... FAILED
failures:
---- src\../doc/docs.md - (line 3) stdout ----
error: couldn't read `src\../doc\foo`: The system cannot find the file specified. (os error 2)
--> src\../doc/docs.md:4:12
|
3 | assert_eq!(include_bytes!("foo"), &[]);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error
Couldn't compile the test.
failures:
src\../doc/docs.md - (line 3)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s
error: doctest failed, to rerun pass `--doc`
Version it worked on
Rust 1.82.0 runs the doctest in the reproduction successfully
Version with regression
rustc --version --verbose
:
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-pc-windows-msvc
release: 1.83.0
LLVM version: 19.1.1
Metadata
Metadata
Assignees
Labels
Type
Projects
Status