-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustdoc: add an --edition flag to compile docs/doctests with a certain edition #49451
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Once CI fixed, r=me. |
@bors r=GuillaumeGomez |
📌 Commit 97aead0 has been approved by |
rustdoc: add an --edition flag to compile docs/doctests with a certain edition To correspond with the 2018 edition, this adds a (currently unstable) `--edition` flag to rustdoc that makes it compile crates and doctests with the given edition. Once this lands, Cargo should be updated to pass this flag when the edition configuration option is given.
💔 Test failed - status-travis |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1 similar comment
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors retry 3-hour timeout with |
…uillaumeGomez rustdoc: add an --edition flag to compile docs/doctests with a certain edition To correspond with the 2018 edition, this adds a (currently unstable) `--edition` flag to rustdoc that makes it compile crates and doctests with the given edition. Once this lands, Cargo should be updated to pass this flag when the edition configuration option is given.
What is missing to get this --edition flag onto stable? 1 year later I still need to use edition2018 on doctests in a crate that has edition="2018" in its Cargo.toml |
This flag was stabilized alongside the 2018 edition in #54057. Cargo was passing it to rustdoc based on the Cargo.toml even earlier, starting in rust-lang/cargo#5299. What problems are you having? |
I have a doctest in an edition2018 crate like: /// ```
/// # use crate::SomeStruct;
/// let s= SomeStruct::new();
/// ```
which did not find SomeStruct without adding the edition2018 flag explicitly to each doctest with a |
Is that the entire doctest? Where is |
I have compiled this minimal example, please run it with #![allow(dead_code)]
pub struct SomeStruct {}
impl SomeStruct {
/// Always returns true
///
/// # Example
///
/// ```edition2018
/// # use crate::SomeStruct;
/// let s = SomeStruct {};
/// assert!(!s.foo());
/// ```
pub fn foo(&self) -> bool {
true
}
}
fn main() {} Works fine without any errors. If I remove edition2018 from line 10 though, it fails with
If I go back to the edition2015 import format, that also fixes the error:
|
Adding just $ rustdoc +stable --test f.rs --extern f=libf.rlib
running 1 test
test f.rs - SomeStruct::foo (line 10) ... FAILED
failures:
---- f.rs - SomeStruct::foo (line 10) stdout ----
error[E0432]: unresolved import `crate::SomeStruct`
--> f.rs:11:5
|
4 | use crate::SomeStruct;
| ^^^^^^^^^^^^^^^^^ no `SomeStruct` in the root
thread 'f.rs - SomeStruct::foo (line 10)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:321:13
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
failures:
f.rs - SomeStruct::foo (line 10)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out Note that this is the same as taking the marker off the doctest and compiling with $ rustdoc +stable --test f.rs --extern f=libf.rlib --edition=2018
running 1 test
test f.rs - SomeStruct::foo (line 10) ... FAILED
failures:
---- f.rs - SomeStruct::foo (line 10) stdout ----
error[E0432]: unresolved import `crate::SomeStruct`
--> f.rs:11:5
|
4 | use crate::SomeStruct;
| ^^^^^^^^^^^^^^^^^ no `SomeStruct` in the root
thread 'f.rs - SomeStruct::foo (line 10)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:321:13
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
failures:
f.rs - SomeStruct::foo (line 10)
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out For completeness, here is the output i received with your original sample: $ rustdoc +stable --test f.rs --extern f=libf.rlib
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out |
The reason the test fails anyway is because the path EDIT: It's also worth noting that even |
Wow, that was a big oversight from me. 🙍♂️ Thanks for helping out. Is there a way to reduce sensitivity of doctest code to crate renames? I tried |
Not that i know of - since the doctests are meant to be example code listed in documentation, it fits that they would need to use the public name for everything. (And the setup of always being compiled as a standalone binary means that no "relative" path would work, either - the items in the original crate are always treated as an external crate.) |
To correspond with the 2018 edition, this adds a (currently unstable)
--edition
flag to rustdoc that makes it compile crates and doctests with the given edition. Once this lands, Cargo should be updated to pass this flag when the edition configuration option is given.