Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
HeroicKatora opened this issue Jan 23, 2020 · 5 comments
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@HeroicKatora
Copy link
Contributor

HeroicKatora commented Jan 23, 2020

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

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 23, 2020
HeroicKatora added a commit to HeroicKatora/static-alloc that referenced this issue Jan 23, 2020
Ensures that the used names are unique even if the crate is itself
available under its name during compilation.

See rust-lang/rust#68488
HeroicKatora added a commit to HeroicKatora/static-alloc that referenced this issue Jan 23, 2020
Ensures that the used names are unique even if the crate is itself
available under its name during compilation.

See rust-lang/rust#68488
HeroicKatora added a commit to HeroicKatora/static-alloc that referenced this issue Jan 23, 2020
Ensures that the used names are unique even if the crate is itself
available under its name during compilation.

See rust-lang/rust#68488
@ollie27
Copy link
Member

ollie27 commented Jan 24, 2020

This should have been fixed recently by #68357. It errors correctly for me using rustdoc 1.42.0-nightly (41f41b235 2020-01-23). Does it still reproduce for you with the latest nightly?

@HeroicKatora
Copy link
Contributor Author

HeroicKatora commented Jan 24, 2020

@ollie27 The latest nightly errors, so I should probably change the title.

You mean the correct behaviour is erroring? I did not realize this. It seems quite surprising to me that the crate itself compiles (cargo build) but then would not succeed in doc tests due to code that is not actually within a doctest.

@HeroicKatora HeroicKatora changed the title Compile error but success when doc-testing a crate that has the same name as a module Compile error in main code when doc-testing a crate that has the same name as a module Jan 24, 2020
@ollie27
Copy link
Member

ollie27 commented Jan 28, 2020

Yeah, actually that error does look wrong. cargo seems to pass --extern this_crate=<path to libthis_crate.rlib> to rustdoc --test which rustdoc either needs to ignore or shouldn't be passed at all.

@ollie27 ollie27 added the A-doctests Area: Documentation tests, run by rustdoc label Jan 28, 2020
@joshlf
Copy link
Contributor

joshlf commented Nov 3, 2023

Chiming in to say that this is affecting us in zerocopy now (though we can probably work around it).

@LGFae
Copy link

LGFae commented Feb 25, 2025

I have also run into this issue just now.

Is there an easy way of disabling rustdoc when running cargo test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Status: No status
Development

No branches or pull requests

5 participants