The dead-code ratchet is blind to expect(dead_code), so the budget can fall without the suppression falling
- Dominant language
- Rust
- Stars
- 41k
- Forks
- 3.6k
- Avg merge
- 13h 59m
- Merged PRs (30d)
- 299
Description
`scripts/check-dead-code-budget.py` counts one spelling:
```python
PATTERN = re.compile(r"allow\(\s*dead_code\b")
```
`expect(dead_code)` is a suppression too, and the ratchet cannot see it. So
rewriting `#[allow(dead_code)]` as `#[expect(dead_code)]` lowers the budget
number by the full count while removing no dead code at all.
## This already happened, in the sweep the ratchet was built to measure
`137fb70a9` (#5587) removed 119 `allow(dead_code)` and added 92
`expect(dead_code)`. The budget recorded a 115-point improvement. Real
suppression sites went from 384 to 363 — **a reduction of 21**.
On `main` today:
```
allow(dead_code) 244 <- the only thing the ratchet counts
expect(dead_code) 109 <- invisible to it
---
total 353 against a recorded budget of 254
```
The gate passes. It is measuring a spelling, not a property.
## Why `expect` makes this worse rather than better
`#[expect]` is the better attribute — it errors when the lint *stops* firing, so
it cannot rot silently the way `#[allow]` does. That is precisely why a sweep
will keep converting toward it, and precisely why the ratchet will keep reading
those conversions as progress. Left alone, the number drifts to zero while the
suppressed surface stays where it is.
## Ask
Count both spellings. `expect` is still worth preferring, so if the two should
not be weighted equally, track them as two numbers rather than one — but do not
leave a gate whose headline figure improves when nothing changed.
A regression test would also help: the peer budget scripts have
`scripts/test_check_runtime_contract_budget.py` and
`test_check_persistence_backlog_budget.py`; there is no
`test_check_dead_code_budget.py`.
## Evidence
Counts above are from `origin/main` at `bce761083`:
```sh
grep -rEo 'allow\(\s*dead_code' crates --include='*.rs' | wc -l # 244
grep -rEo 'expect\(\s*dead_code' crates --include='*.rs' | wc -l # 109
python3 -c "import json;print(json.load(open('scripts/dead-code-budget.json'))['total'])" # 254
```
Found while adversarially re-verifying a claim that #5587 was complete. It is
not — but that is #5587's problem. This is the gate's.
Contributor guide
Research direction
Start with scripts/check-dead-code-budget.py and inspect the existing budget data in scripts/dead-code-budget.json. Compare its counting behavior with the Rust suppression forms described in the issue, then add coverage following scripts/test_check_runtime_contract_budget.py or test_check_persistence_backlog_budget.py. Done means the gate accounts for both suppression spellings and the regression test fails if either is ignored.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100