From f5d970494f77d39dadf7c7d5a6a3d70221ca2da2 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sat, 21 Nov 2026 15:50:41 +0000 Subject: src,sandbox,http: three more fields nobody read, and the check that missed them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A field scan that printed its first thirty lines missed the rest. Three `pub` fields were written and never read: `SandboxSpec::disk_mb`, copied off `cfg.min_free_disk_mb` into a spec no backend consulted — the dispatcher already checks the disk itself, so the knob stayed live and the plumbing around it was dead; `SandboxInfo::warm`, computed three ways by three backends and read by nobody; and `Server::handle`, a `JoinHandle` stored and never joined, which is what detaching a thread means and so was never load-bearing. All three are gone, their construction sites with them. Four more are written-but-never-read on purpose and now say so where they are declared: `Identity::upstream_pins` and `source_digests` reach the identity digest through `canonical_json`, not through a name; `VirtualClock::_owner` is the lease, and holding it unread is the whole mechanism; the `Ab`/`Ba` pair in `hash`'s canonical-json test exist to be serialized. `the_test_helpers_are_used` only looked at `pub` items, which left the blanket `allow(dead_code)` in `tests/common` exactly as able to hide a private helper as a public one — the objection was fair, and planting `fn planted_private_helper_never_used()` proved it passed while a dead private helper sat in the file. It now scans private declarations too, and fails on both the planted function and a planted struct. --- src/db/model/mod.rs | 2 ++ src/hash.rs | 1 + src/http/mod.rs | 7 ++++--- src/pipeline/mod.rs | 1 - src/sandbox/kata.rs | 1 - src/sandbox/loopback.rs | 1 - src/sandbox/mod.rs | 4 +--- src/sandbox/remote.rs | 1 - src/time.rs | 2 ++ tests/architecture.rs | 19 ++++++++++++++++--- tests/common/mod.rs | 8 +++++--- tests/failure_modes.rs | 2 +- 12 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/db/model/mod.rs b/src/db/model/mod.rs index ba97073..aef6a47 100644 --- a/src/db/model/mod.rs +++ b/src/db/model/mod.rs @@ -53,6 +53,8 @@ pub struct Identity { pub epoch: String, pub pkgver: String, pub pkgrel: String, + // Neither field is read by name anywhere: `hash` renders the whole struct with + // `canonical_json`, so both participate in the identity digest by being here. pub upstream_pins: Vec, pub source_digests: Vec, } diff --git a/src/hash.rs b/src/hash.rs index 8a2d884..ff7f41f 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -82,6 +82,7 @@ mod tests { #[test] fn the_rendering_is_canonical_in_fact_not_in_name() { + // Read only through `canonical_json`, never by name: that is the point. #[derive(serde::Serialize)] struct Ab { alpha: String, diff --git a/src/http/mod.rs b/src/http/mod.rs index 8a00745..c95cd16 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -102,7 +102,6 @@ impl Res { /// feature-conditional visibility. mod server { pub struct Server { - pub handle: std::thread::JoinHandle<()>, pub addr: String, } } @@ -124,7 +123,9 @@ pub fn spawn(cfg: Config, db: Db) -> std::io::Result { let addr = server.server_addr().to_ip().map(|a| a.to_string()).unwrap_or_else(|| cfg.bind.clone()); let state = Arc::new(State { cfg, db }); eprintln!("aur-build listening on http://{addr}"); - let handle = std::thread::Builder::new() + // Detached on purpose: the accept loop owns the listener and runs until the + // process ends, and nothing joins it, so the handle would be stored unread. + std::thread::Builder::new() .name("http-accept".into()) .spawn(crate::time::inherit(move || { for request in server.incoming_requests() { @@ -139,7 +140,7 @@ pub fn spawn(cfg: Config, db: Db) -> std::io::Result { .ok(); } }))?; - Ok(Server { handle, addr }) + Ok(Server { addr }) } fn serve(state: Arc, mut request: tiny_http::Request) -> std::io::Result<()> { diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index e14c7a8..e571d71 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -150,7 +150,6 @@ impl Ctx { profile: self.profile.clone(), task: self.build.id.clone(), ttl: Duration::from_secs(self.cfg.lease_secs.max(1) as u64), - disk_mb: self.cfg.min_free_disk_mb, }; self.backend.acquire(&spec) } diff --git a/src/sandbox/kata.rs b/src/sandbox/kata.rs index 84a79e4..a54110a 100644 --- a/src/sandbox/kata.rs +++ b/src/sandbox/kata.rs @@ -308,7 +308,6 @@ mod kata_backend { Ok(vec![SandboxInfo { id: format!("kata@{} via {}", self.addr, self.provisioner.name()), profile: self.cfg.build_profile.clone(), - warm: !self.pending.lock().unwrap().is_empty(), }]) } } diff --git a/src/sandbox/loopback.rs b/src/sandbox/loopback.rs index 9629206..fb5ba00 100644 --- a/src/sandbox/loopback.rs +++ b/src/sandbox/loopback.rs @@ -53,7 +53,6 @@ impl SandboxBackend for LoopbackBackend { Ok(vec![SandboxInfo { id: "loopback".into(), profile: self.cfg.build_profile.clone(), - warm: true, }]) } } diff --git a/src/sandbox/mod.rs b/src/sandbox/mod.rs index ded76f0..b82647b 100644 --- a/src/sandbox/mod.rs +++ b/src/sandbox/mod.rs @@ -64,12 +64,11 @@ pub struct SandboxSpec { pub profile: String, pub task: String, pub ttl: Duration, - pub disk_mb: u64, } impl SandboxSpec { pub fn new(profile: impl Into, task: impl Into, ttl: Duration) -> Self { - Self { profile: profile.into(), task: task.into(), ttl, disk_mb: 0 } + Self { profile: profile.into(), task: task.into(), ttl } } } @@ -82,7 +81,6 @@ mod sandbox_info { pub struct SandboxInfo { pub id: String, pub profile: String, - pub warm: bool, } } diff --git a/src/sandbox/remote.rs b/src/sandbox/remote.rs index 6d369e2..8366e97 100644 --- a/src/sandbox/remote.rs +++ b/src/sandbox/remote.rs @@ -98,7 +98,6 @@ impl SandboxBackend for RemoteBackend { Ok(vec![SandboxInfo { id: format!("remote@{}", self.addr), profile: self.cfg.build_profile.clone(), - warm: !self.queue.is_empty(), }]) } } diff --git a/src/time.rs b/src/time.rs index 4f5ab7f..b0ab4ab 100644 --- a/src/time.rs +++ b/src/time.rs @@ -145,6 +145,8 @@ mod clock { // VirtualClock stays `pub`: lives in the `test-support`-gated clock module, behind the gated `virtualize()` that returns it. pub struct VirtualClock { + // Held, never read: owning the mutex *is* the virtual clock's lease, + // and dropping this guard is what releases it. _owner: MutexGuard<'static, ()>, } diff --git a/tests/architecture.rs b/tests/architecture.rs index b8de0ce..3eafcdc 100644 --- a/tests/architecture.rs +++ b/tests/architecture.rs @@ -883,6 +883,11 @@ fn the_dead_code_allowlist_names_real_items() { /// declaration. A type whose name nobody writes is still used if a field or /// method of it is: `Web::raw_request` hands back a `Raw` no test names, and /// reading `.status` off it is a use of the type. +/// +/// Private items are checked too. The blanket allowance in `tests/common` +/// excuses a private helper exactly as thoroughly as a public one, and a +/// private helper called by nothing is the harder case to notice, not the +/// easier one. #[test] fn the_test_helpers_are_used() { let common = root().join("tests/common/mod.rs"); @@ -895,9 +900,15 @@ fn the_test_helpers_are_used() { let lines: Vec<&str> = text.lines().collect(); let mut unused = Vec::new(); for (i, line) in lines.iter().enumerate() { + // `pub` and private alike: the blanket `allow(dead_code)` at the top of + // the file excuses both, so a private helper nobody calls is exactly as + // dead as a public one, and just as invisible to the compiler here. let t = line.trim_start(); - let Some(rest) = t.strip_prefix("pub ") else { continue }; - let rest = rest.trim_start(); + let indent = line.len() - t.len(); + if indent > 4 { + continue; + } + let rest = t.strip_prefix("pub ").unwrap_or(t); let Some(kind) = ["fn ", "struct ", "enum ", "const ", "static ", "type ", "trait "] .into_iter() .find(|k| rest.starts_with(k)) @@ -909,7 +920,9 @@ fn the_test_helpers_are_used() { continue; } // Everything this declaration introduces, minus the declaration itself. - let mut corpus = others.replace(&format!("pub {kind}{name}"), ""); + let mut corpus = others + .replace(&format!("pub {kind}{name}"), "") + .replace(&format!("{kind}{name}"), ""); if kind != "fn " { // Members of a struct or enum count as uses of the type. let mut depth = 0; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0b46aeb..35aad9b 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,7 +1,9 @@ // Every test binary compiles this file, so a helper that one of them uses is -// dead code in the other twenty and the lint would fire everywhere and mean -// nothing. `the_test_helpers_are_used` in tests/architecture.rs is the check -// that does matter: a helper no test names is deleted, not excused. +// dead code in the other twenty — 46 of the items below warn that way, and an +// item-scoped allowance on each would say the same thing 46 times. The check +// that does the work is `the_test_helpers_are_used` in tests/architecture.rs: +// it reads this file and fails on any item, `pub` or private, that no test +// names, so the allowance hides noise and cannot hide dead weight. #![allow(dead_code)] use std::collections::HashMap; diff --git a/tests/failure_modes.rs b/tests/failure_modes.rs index e9083a2..4e7446a 100644 --- a/tests/failure_modes.rs +++ b/tests/failure_modes.rs @@ -31,7 +31,7 @@ impl SandboxBackend for FakeBackend { Ok(Arc::new(FakeSandbox { inner, fault: self.fault })) } fn status(&self) -> Result> { - Ok(vec![SandboxInfo { id: "fake".into(), profile: "fake".into(), warm: true }]) + Ok(vec![SandboxInfo { id: "fake".into(), profile: "fake".into() }]) } } -- cgit v1.2.3