Repository navigation
fix(stageleft_tool): re-export dev-dependencies in trybuild-mode __deps - #104
Merged
akainth015 merged 1 commit intoSep 29, 2026
Conversation
…eps` In trybuild mode, staged `#[cfg(test)]` code is kept behind the test-mode feature, and the generated crate makes dev-dependencies available under that same feature. However, `__deps` only re-exported `[dependencies]`, so spliced code which names a dev-only crate (e.g. a type from a dev-only crate used as a type parameter in a test) failed to resolve with E0433. `gen_deps_module` now takes the test-mode feature. When it is set (trybuild mode), `[dev-dependencies]` and `[target.'cfg(..)'.dev-dependencies]` are also collected, with each declaration gated on the test-mode feature and merged with any regular declaration of the same crate: - dev-only: gated on the test-mode feature - dev + non-optional regular: ungated (unchanged) - dev + optional regular: gated on any of the regular gates or the test-mode feature - target-specific dev: gated on both the target cfg and the test-mode feature The same gate applies to the runtime `add_deps_reexport` registration. The `__deps` generated by `gen_final!` (build.rs) passes no test-mode feature, so its output is unchanged. Adds unit tests covering the gating cases above, package renames, and that dev-dependencies are ignored without a test-mode feature.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
In trybuild mode (
gen_staged_trybuildwith a test-mode feature), staged#[cfg(test)]code is kept behind the test-mode feature, and the generated crate makes the original crate's dev-dependencies available under that same feature. However, the generated__depsmodule only re-exports[dependencies], so spliced code that names a dev-only crate fails to resolve.For example, with a crate whose test uses a type from a dev-only crate as a type parameter:
the generated code (which starts with
use <crate>::__staged::__deps::*;) containsmy_test_helper::Codecand fails to compile:Change
gen_deps_modulenow takes the test-mode feature. When set (trybuild mode), it also collects[dev-dependencies]and[target.'cfg(..)'.dev-dependencies], gating each declaration on the test-mode feature and merging it with any regular declaration of the same crate, so the existing merge semantics apply:__depsgatecfg(any(feature = "<test>"))cfg(any(<regular gates>, any(feature = "<test>")))cfg(all(<target cfg>, any(feature = "<test>")))The same gate applies to the runtime
add_deps_reexportregistration, and package renames are handled as for regular dependencies. Since Cargo does not allowoptionaldev-dependencies, dev declarations are only ever gated on the test-mode feature.The
__depsgenerated fromgen_final!(build.rs) passes no test-mode feature, so its output is unchanged (thestaged_depssnapshot is untouched).Tests
cargo test --workspace --all-targetsandcargo clippy --workspace --all-targets -- -D warningspass.mainand passes with this change.