using `super` in doctests errors
Open
Nobody has claimed this yet.
A-diagnostics
A-doctests
A-resolve
D-terse
T-rustdoc
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
/// ```
/// type Y = ();
/// mod m {
/// use super::Y;
/// fn f() -> Y {}
/// }
/// ```
pub struct X;
in lib.rs.
I expected to see this happen: successful cargo test
Instead, this happened:
cargo test
Compiling rust v0.0.0 (/tmp/tmp)
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.13s
Running unittests src/lib.rs (target/debug/deps/rust-48a0867617020c3e)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Doc-tests rust
running 1 test
test src/lib.rs - X (line 1) ... FAILED
failures:
---- src/lib.rs - X (line 1) stdout ----
error[E0432]: unresolved import `super::Y`
--> src/lib.rs:4:9
|
5 | use super::Y;
| ^^^^^^^^ no `Y` in the root
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0432`.
Couldn't compile the test.
failures:
src/lib.rs - X (line 1)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s
error: doctest failed, to rerun pass `--doc`
The same error happens when using super::Y directly in the return type.
Meta
rustc --version --verbose:
rustc 1.83.0-nightly (8d6b88b16 2024-09-11)
binary: rustc
commit-hash: 8d6b88b168e45ee1624699c19443c49665322a91
commit-date: 2024-09-11
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure from the lib.rs snippet by running cargo test. Then trace the doctest compilation path responsible for module resolution and inspect how super is handled. Done means the doctest compiles successfully and cargo test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100