Skip to content

using super in doctests errors #130274

Open
Open
@BennoLossin

Description

@BennoLossin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-doctestsArea: Documentation tests, run by rustdocA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions