Repository navigation
fix(config): scope the dead_code suppressions to the fields that are unread - #300
Merged
Merged
Conversation
…unread Six `#[allow(dead_code)]` attributes sat on the config.rs structs, so each one silenced every field of its struct -- including fields added later. Two of them suppressed something (Points, Provider); the other four (Config, Plan, Endpoint, Model) silenced nothing, and the reason comment on `Config` still named a development stage that landed long ago. Measured with the compiler in the one configuration where a dead_code suppression can matter, a non-test build (`RUSTFLAGS="-D warnings" cargo build`): with every allow stripped, rustc names exactly `display_name`, `symbol`, `name` and `country`. So: drop the four inert attributes, and move the suppression for the remaining four fields onto the fields themselves, with reasons that state the invariant instead of a stage that is over. CI cannot see this class -- its only warning gate is `clippy --all-targets -- -D warnings`, and `--all-targets` compiles the parse tests, which read every field. No behaviour change: no config field is added, removed or retyped, so config/config.example.toml is untouched.
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.
Summary
Six
#[allow(dead_code)]attributes sat at struct level insrc/config.rs(lines 133, 153, 167, 176, 192, 201) —Config,Points,Provider,Plan,Endpoint,Model. A struct-level attribute silences every field of its struct, including fields added later, and one of them (Config) still carried a reason naming a development stage that landed long ago.Measured with the compiler, in the one build configuration where a
dead_codesuppression can matter — a non-test build (RUSTFLAGS="-D warnings" cargo build):Config(:133)Points(:153)display_name,symbolProvider(:167)name,countryPlan(:176)Endpoint(:192)Model(:201)With every allow stripped, rustc names exactly four fields:
display_name,symbol,name,country.Two notes on how this was established, because both matter for reading the diff:
Provider.namewrong. A plain identifier search credits it with reads that in fact belong toPlan.name(gateway.rsreadsPlan.namewhen it builds the/api/planspayload). The compiler namesProvider.nameas unread; the compiler is right and the lexical count is not — so the suppression for that field moves to the field too.Why this survived at all: CI's only warning gate is
cargo clippy --all-targets -- -D warnings, and--all-targetscompiles the test targets. The parse tests inconfig.rsassert on every field (assert_eq!(cfg.points.display_name, "点数"),p.country == "CN", …) — so in CI's view every one of these fields is read. The gate is structurally blind to the whole class "configured in TOML, never read by production": it goes red only when a field is read from nowhere at all, not when the only reader is a test.Related Issue
None — the repository has no open issues (all three are CLOSED). This change comes from this task's own reconnaissance: an audit of the repository's suppressed compiler diagnostics, motivated by the observation that a suppression outlives the condition it was written for.
Changes
Config,Plan,Endpoint,Model). Four of the six structs are covered by the compiler again, and future fields added to them can no longer be silenced by an attribute nobody revisits.Points::display_name,Points::symbol,Provider::name,Provider::country.Configclaimed “points/providers/plans 由后续 P0 网关/定价阶段消费” — that stage landed long ago, which is exactly how a stale reason keeps a wide suppressor alive.#[allow(clippy::too_many_arguments)](src/billing.rs:58,src/routes/admin_models.rs:74). Both are genuine shape suppressions (flat price fields, kept in request-struct order) and both already state their reason.config/config.example.tomland the example data are unchanged.Tests
cargo test— 392 passed, 0 failed (identical to the baseline: the change is an attribute block, and no test observes which attribute carries a suppression)cargo fmt --check— rc=0cargo clippy --all-targets -- -D warnings— rc=0A/B (compiler legs)
tmp/r153ab/ab.py— four legs, each with its ownCARGO_TARGET_DIR, eachRUSTFLAGS="-D warnings" cargo build,BASE=src/config.rsatacb8815,FIXED= this branch:L4 is the decisive leg: it removes all six attributes from the original file and gets a build failure naming the same four fields. If any of the four attributes being dropped here had been suppressing something, its field would appear in that list — so each of the four was inert, and the narrowed form covers exactly what the six covered, no more and no less. L2 == L4 is the statement that this PR moved the suppression without moving the set of unread fields.
Checklist
fix/)