Skip to content

Compile error in main code when doc-testing a crate that has the same name as a module #68488

Open
@HeroicKatora

Description

@HeroicKatora

In a crate that has the same name as a top-level module, exporting a name from this module causes rustdoc (and only rustdoc) to error when it is ran.

// Crate name: `this_crate`.
mod this_crate { pub struct Item; }

pub use this_crate::Item;
error[E0659]: `this_crate` is ambiguous
> cargo test --doc
    Finished test [unoptimized + debuginfo] target(s) in 0.00s
   Doc-tests this_crate
error[E0659]: `this_crate` is ambiguous (name vs any other name during import resolution)
 --> /tmp/test_dir/no-alloc/src/lib.rs:7:9
  |
7 | pub use this_crate::Item;
  |         ^^^^^^^^^^ ambiguous name
  |
  = note: `this_crate` could refer to a crate passed with `--extern`
  = help: use `::this_crate` to refer to this crate unambiguously
note: `this_crate` could also refer to the module defined here
 --> /tmp/test_dir/no-alloc/src/lib.rs:1:1
  |
1 | mod this_crate { pub struct Item; }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: use `crate::this_crate` to refer to this module unambiguously

error: aborting due to previous error

For more information about this error, try rustc --explain E0659.

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
> echo $?
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.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