Skip to content

Add unsafe/debug hygiene ast-grep rules#2153

Merged
slepp merged 1 commit into
mainfrom
ast-grep-rules-hygiene
Jun 22, 2026
Merged

Add unsafe/debug hygiene ast-grep rules#2153
slepp merged 1 commit into
mainfrom
ast-grep-rules-hygiene

Conversation

@slepp

@slepp slepp commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Three validated hygiene rules added to the ast-grep set (rules/rust/hygiene/):

  • unsafe-without-safety (warning, 54) — flags unsafe { … } blocks without a // SAFETY: justification. The repo convention is near-universal — 3659/3713 non-test unsafe blocks (98.5%) already carry one — so the rule surfaces the 54 genuine gaps, not the convention. (A naive matcher gave 1328; the SAFETY-adjacency logic across every placement variant cut it to 54 with zero false negatives.)
  • transmute-audit (hint, 10) — inventory of mem::transmute(…) / transmute::<…>(…) sites for layout/lifetime review.
  • dbg-macro (warning, 0) — preventive guard against shipping dbg!.

Verification

  • scripts/ast-grep-lint.sh runs the full set (now 15 rules) with no load errors.
  • Per-rule hit counts, precision figures, and triage are in rules/rust/hygiene/_REPORT.md.
  • All three are non-gating (unsafe-without-safety/transmute-audit report as warning/hint; dbg-macro is empty today).

Three validated rules under rules/rust/hygiene/:

- `unsafe-without-safety` (warning): flag `unsafe` blocks lacking a
  `// SAFETY:` justification. The convention is near-universal (3659/3713
  non-test unsafe blocks carry one), so this surfaces the 54 genuine gaps,
  not the convention.
- `transmute-audit` (hint): inventory the 10 `mem::transmute` call sites for
  layout/lifetime review — the most dangerous unsafe operation.
- `dbg-macro` (warning): preventive guard against shipping `dbg!`.
@slepp slepp merged commit 7904c13 into main Jun 22, 2026
11 checks passed
@slepp slepp deleted the ast-grep-rules-hygiene branch June 22, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant