-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Usage of extern crate
fails doc tests
#33731
Comments
This is by design. It's a confusing design. The code in doc tests is (1) wrapped in |
OK, I can see why it would be done that way. However, there are still two issues:
It looks like rustdoc is just doing a blind search for the phrase EDIT: |
Yeah, it just does a blind substring search. Possibly rustdoc could look On Thu, May 19, 2016 at 12:02 PM, Osspial notifications@github.com wrote:
|
Update: Still an issue. The offending code still does a naive string search before inserting Lines 403 to 410 in ae2f299
A proper fix should scan the lines of the original string much like the way it checks for Lines 414 to 423 in ae2f299
Or even better, actually parse the code and look for the import that way. It would also fully fix #21299, since it has the same problem: the last example will fail if you replace |
Is this issue still reproducible? I stumbled upon a similar situation, but the doctest below seems to compile just fine since 1.26.0 (it fails in 1.25.0 and older). //! # Examples
//!
//! ```
//! extern crate byteorder;
//! use byteorder::ReadBytesExt;
//! ``` |
That doctest doesn't exercise the issue. The problem is that you can't use any types from your own crate in there, right. (Unless your crate is |
Test that this is compatible back to Rust 1.26.0. Rust 1.24.0 and earlier fail in the doctest due to rust-lang/rust#33731
If a doc test attempts to import any types declared in it's own crate, including the phrase
extern crate
anywhere in the code will cause the test to not compile, throwing a "unresolved import" error at the attempted import. For example, if we have structFoo
in cratebar
, with the cratebaz
declared underdev_dependencies
, these tests will all fail to compile when there's no reason for them not to:The following error log is given by
cargo test
:Rust version:
The text was updated successfully, but these errors were encountered: