-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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: Doctest merging: Remove superfluous library search path logic #138436
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const STATUS: bool = dep_a_a::STATUS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const STATUS: bool = dep_b_b::STATUS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const STATUS: bool = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const STATUS: bool = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! ``` | ||
//! assert!(dep_a::STATUS); | ||
//! ``` | ||
//! | ||
//! ``` | ||
//! assert!(dep_b::STATUS); | ||
//! ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//! Since PR <https://github.com/rust-lang/rust/pull/137899>, merged doctests reside in so-called | ||
//! "bundle" crates which are separate from the actual "runner" crates that contain the necessary | ||
//! scaffolding / infrastructure for executing the tests by utilizing the unstable crate `test` | ||
//! and the internal lang feature `rustc_attrs`. | ||
//! | ||
//! In the light of this two-crate setup (per edition), this test ensures that rustdoc can handle | ||
//! mergeable doctests with direct and transitive dependencies (which would become ("first-degree") | ||
//! transitive and "second-degree" transitive dependencies of the runner crates, respectively). | ||
//! | ||
//! While this is about doctest merging which is only available in Rust 2024 and beyond, | ||
//! we also test Rust 2021 here to ensure that in this specific scenario rustdoc doesn't | ||
//! grossly diverge in observable behavior. | ||
|
||
use run_make_support::{bare_rustc, rustdoc}; | ||
|
||
fn main() { | ||
// Re. `bare_rustc` over `rustc` (which would implicitly add `-L.`): | ||
// This test is all about verifying that rustdoc is able to find dependencies | ||
// and properly propagates library search paths etc. | ||
// Anything implicit like that would only obfuscate this test or even | ||
// accidentally break it. | ||
|
||
// | ||
// Build crate `a_a` and its dependent `a` which is the direct dependency of | ||
// the doctests inside `doctest.rs` *and* of crate `doctest` itself! | ||
// | ||
|
||
bare_rustc().current_dir("deps").input("dep_a_a.rs").crate_type("lib").run(); | ||
|
||
bare_rustc().input("dep_a.rs").crate_type("lib").args(["--extern=dep_a_a", "-Ldeps"]).run(); | ||
|
||
// | ||
// Build crate `b_b` and its dependent `b` which is the direct dependency of | ||
// the first doctest in `doctest.rs` *but not* of crate `doctest` itself! | ||
// | ||
|
||
bare_rustc().current_dir("deps").input("dep_b_b.rs").crate_type("lib").run(); | ||
|
||
bare_rustc().input("dep_b.rs").crate_type("lib").args(["--extern=dep_b_b", "-Ldeps"]).run(); | ||
|
||
// | ||
// Collect and run the doctests inside `doctest.rs`. | ||
// | ||
|
||
for edition in ["2021", "2024"] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also explicitly add a "2015" edition, since that IIRC influences extern prelude behavior (in 2015, |
||
// NB: `-Ldependency=<path>` only adds *transitive* dependencies to | ||
// the search path contrary to `-L<path>`. | ||
|
||
rustdoc() | ||
.input("doctest.rs") | ||
.crate_type("lib") | ||
.edition(edition) | ||
// Adds crate `a` as a dep of `doctest` *and* its contained doctests. | ||
// Also registers transitive dependencies. | ||
.extern_("dep_a", "libdep_a.rlib") | ||
.arg("-Ldependency=deps") | ||
// Adds crate `b` as a dep of `doctest`'s contained doctests. | ||
// Also registers transitive dependencies. | ||
.args([ | ||
"-Zunstable-options", | ||
"--doctest-compilation-args", | ||
"--extern=dep_b=libdep_b.rlib -Ldependency=deps", | ||
]) | ||
.arg("--test") | ||
.arg("--test-args=--test-threads=1") | ||
.run(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note for additional context: This didn't apply to doctest-only dependencies "anyway"1 as registered via
-Zunstable-options --doctest-compilation-args
as noted here: #137899 (comment)Footnotes
Very unlikely to occur in practice due to Cargo's dominance which doesn't support that. ↩