diff options
| author | aur-build <aur-build@localhost> | 2026-11-20 23:53:42 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-20 23:53:42 +0000 |
| commit | 66814ddb86009de7a519f167db634dab3e924fa8 (patch) | |
| tree | 6598e2099aec29160d0c05be3201605c829c05f5 /src/sandbox/loopback.rs | |
| parent | 3936ef9fa3428908880eb98282eea7c83f6e610b (diff) | |
| download | aur-build-66814ddb86009de7a519f167db634dab3e924fa8.tar.gz aur-build-66814ddb86009de7a519f167db634dab3e924fa8.zip | |
src: keep every remaining test-only item out of the release build
The auditor was right and my "Rust has no test-conditional visibility" defence
was wrong. Two shapes do it, and both are now used wherever the item allows.
For free functions, methods, consts and statics: one body behind two visibility
declarations.
#[cfg(feature = "test-support")] pub fn probe(..) -> .. { probe_impl(..) }
#[cfg(not(feature = "test-support"))] pub(crate) fn probe(..) -> .. { probe_impl(..) }
fn probe_impl(..) -> .. { .. }
The value lives once in a private `*_impl` / `*_VALUE`, so the aliases cannot
drift apart.
For types: a private inner module holding the real definition, re-exported under
a feature gate.
mod kata_backend { pub struct KataBackend { .. } }
#[cfg(feature = "test-support")] pub use kata_backend::KataBackend;
#[cfg(not(feature = "test-support"))] pub(crate) use kata_backend::KataBackend;
A `pub` item inside a private module has no nameable path from outside, but it is
visible enough to appear in a public trait signature — which is why `Exit`, the
return type of `Sandbox::run`, narrows this way and would not as a plain
`pub(crate) struct`. `ReleaseState` earns its keep the same route: `ReleaseRow`
is public and its `state` field is typed here.
Verified with an external crate against the built library: naming `Exit`,
`SandboxInfo`, `KataBackend`, `LoopbackBackend`, `RemoteBackend`, `ReleaseState`,
`BulkRefusal` or `LogTail` from a release build is `error[E0603]: .. is private`;
with `test-support` the same program compiles.
Where narrowing needed a re-export split by feature (`db::MIGRATIONS`,
`model::ReleaseState`) the alias is split; where nothing in the crate used the
alias (`watch::sync_mirror`) it is gone rather than gated.
Diffstat (limited to 'src/sandbox/loopback.rs')
| -rw-r--r-- | src/sandbox/loopback.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/sandbox/loopback.rs b/src/sandbox/loopback.rs index 7847fdc..9629206 100644 --- a/src/sandbox/loopback.rs +++ b/src/sandbox/loopback.rs @@ -7,10 +7,31 @@ use crate::config::Config; use crate::error::{Error, Result}; use crate::sandbox::{Cmd, Exit, Sandbox, SandboxBackend, SandboxInfo, SandboxSpec}; -pub struct LoopbackBackend { - cfg: Config, +/// The real definition. The module is private, so this `pub` +/// is not a nameable path from outside; the alias below is the +/// only way to reach it, and the alias is what carries the +/// feature-conditional visibility. +mod loopback_backend { + use super::*; + // `pub` fields inside a private module are not nameable from + // outside; they stay readable by the impls below. + + pub struct LoopbackBackend { + pub cfg: Config, + } } +/// The default backend, built by `backend_for`. A failure test builds one to inject a fault. +/// +/// `pub` only under `test-support`. Production reaches the type +/// through its own module and never names it from outside; the +/// outside reader that needs the name is a test. +#[cfg(feature = "test-support")] +pub use loopback_backend::LoopbackBackend; + +#[cfg(not(feature = "test-support"))] +pub(crate) use loopback_backend::LoopbackBackend; + impl LoopbackBackend { pub fn new(cfg: &Config) -> Self { Self { cfg: cfg.clone() } |
