Uh oh!
There was an error while loading. Please reload this page.
rustdoc: add an --edition flag to compile docs/doctests with a certain edition - #49451
Conversation
rust-highfive
commented
Mar 28, 2018
(rust_highfive has picked a reviewer for you, use r? to override) |
QuietMisdreavus
commented
Mar 28, 2018
GuillaumeGomez
commented
Mar 28, 2018
Once CI fixed, r=me. |
QuietMisdreavus
commented
Mar 29, 2018
@bors r=GuillaumeGomez |
bors
commented
Mar 29, 2018
📌 Commit 97aead0 has been approved by |
bors
commented
Mar 30, 2018
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.
bors
commented
Mar 31, 2018
💔 Test failed - status-travis |
TimNN
commented
Mar 31, 2018
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
TimNN
commented
Mar 31, 2018
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 |
kennytm
commented
Apr 1, 2018
@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.
bors
commented
Apr 1, 2018
wigy-opensource-developer
commented
Apr 2, 2019
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 |
QuietMisdreavus
commented
Apr 3, 2019
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 |
QuietMisdreavus
commented
Apr 3, 2019
Is that the entire doctest? Where is |
I have compiled this minimal example, please run it with #![allow(dead_code)]pubstructSomeStruct{}implSomeStruct{/// Always returns true////// # Example////// ```edition2018/// # use crate::SomeStruct;/// let s = SomeStruct {};/// assert!(!s.foo());/// ```pubfnfoo(&self) -> bool{true}}fnmain(){}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: |
QuietMisdreavus
commented
Apr 3, 2019
Adding just $ rustdoc +stable --test f.rs --extern f=libf.rlibrunning 1 testtest f.rs - SomeStruct::foo (line 10) ... FAILEDfailures:---- 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 rootthread 'f.rs - SomeStruct::foo (line 10)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:321:13note: 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 outNote 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=2018running 1 testtest f.rs - SomeStruct::foo (line 10) ... FAILEDfailures:---- 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 rootthread 'f.rs - SomeStruct::foo (line 10)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:321:13note: 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 outFor completeness, here is the output i received with your original sample: $ rustdoc +stable --test f.rs --extern f=libf.rlibrunning 0 teststest 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 |
QuietMisdreavus
commented
Apr 3, 2019
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)
--editionflag 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.