1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//!
//! Bug reproducer test for missing Seed import in non-deterministic mode.
//!
//! ## Root Cause
//!
//! The `hrng_non_deterministic` module's `private` namespace (line 9-12) did not import the
//! `Seed` type from the crate root, but the `master_with_seed()` function at line 114 used
//! `Seed` in its signature. When the `determinism` feature was disabled (making
//! `hrng_non_deterministic` the active implementation), compilation failed with:
//!
//! ```text
//! error[E0412]: cannot find type `Seed` in this scope
//! --> src/hrng_non_deterministic.rs:114:30
//! |
//! 114 | pub fn master_with_seed(_: Seed) -> Self
//! | ^^^^
//! ```
//!
//! The `hrng_deterministic` module had the correct import pattern (`use crate::*;` at line 12),
//! but this pattern was not replicated in the non-deterministic variant. The `Seed` type is
//! defined in `src/seed.rs` and conditionally exported via `lib.rs` when `not(feature = "no_std")`.
//!
//! ## Why Not Caught
//!
//! 1. **Default feature masking**: The `determinism` feature is enabled by default in `Cargo.toml`,
//! meaning normal `cargo test` runs used `hrng_deterministic` (which has correct imports) and
//! never exercised the non-deterministic code path.
//!
//! 2. **Missing feature matrix testing**: No CI/test configuration explicitly tested the
//! `--no-default-features` build, which would have caught this immediately.
//!
//! 3. **Doc test scope limitation**: The doc test in `hrng_non_deterministic.rs:105-111` includes
//! a usage example of `master_with_seed()`, but doc tests are compiled in a different context
//! where the import requirements may differ, failing to catch the missing import in the actual
//! module implementation.
//!
//! 4. **No integration test for non-deterministic mode**: All existing integration tests in
//! `tests/basic_test.rs` are feature-gated with `#[cfg(feature = "determinism")]`, leaving
//! the non-deterministic mode untested.
//!
//! ## Fix Applied
//!
//! Added the missing import to `src/hrng_non_deterministic.rs` at line 13-14:
//!
//! ```rust
//! mod private
//! {
//! use core :: { ops ::Deref, ops ::DerefMut };
//! #[ cfg(not(feature = "no_std")) ]
//! use crate ::Seed; // Added this line
//! ```
//!
//! The import is feature-gated with `#[cfg(not(feature = "no_std"))]` to match the feature gate
//! on the `master_with_seed()` function, ensuring the import is only present when the `Seed`
//! type is actually available (seed module is conditionally compiled in lib.rs:46 with the same gate).
//!
//! ## Prevention
//!
//! 1. **Feature matrix testing**: Add CI jobs that test with `--no-default-features` and all
//! feature permutations to catch feature-gated code paths.
//!
//! 2. **Integration tests for both modes**: Create tests that explicitly verify both deterministic
//! and non-deterministic modes work correctly, not just feature-gated tests for one mode.
//!
//! 3. **Shared test fixtures**: When dual implementations exist (deterministic/non-deterministic),
//! create shared test fixtures that both implementations must pass, ensuring API parity.
//!
//! 4. **Import consistency linting**: Consider using workspace-level lints or custom tooling to
//! ensure symmetric modules (like `hrng_deterministic` and `hrng_non_deterministic`) have
//! consistent import patterns.
//!
//! ## Pitfall
//!
//! **Dual implementation symmetry assumption**: Developers may assume that if one implementation
//! compiles, the mirror implementation will also compile, especially when feature flags swap
//! between them. This is false - each feature-gated code path must be independently verified.
//!
//! **Doc test false confidence**: The presence of a passing doc test for `master_with_seed()`
//! in the non-deterministic module gave false confidence that the code was correct. Doc tests
//! compile in a different module context (`#[doc]`) and may have different import resolution
//! than the actual implementation.
//!
//! **Default feature masking**: Default-enabled features effectively hide code paths from
//! standard development workflows (`cargo test`, `cargo build`). Critical code paths should
//! not be behind default-disabled features unless intentionally opt-in.
//!