Ray's Knowledge Base
Unlock

A multi-part edit script matching exact source text silently applies only some edits

PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A multi-part Python edit script that matches on exact source text silently does only some of its edits when cargo fmt has reformatted a matched line, so the earlier parts apply and the later ones do not. This left a test's Candidate without a new field, which broke compilation and failed a proof run.

Cause#

A later replace pattern no longer matched after formatting changed the line, and the script did not check.

Fix#

Run cargo fmt before an edit session, make the script assert that each pattern matched exactly once and abort otherwise, and re-read the current text before re-applying.

Evidence#

Seen in an rkb edit session; the missing field broke compilation.

Also found by searching

  • multi-part Python edit script silently does only some of its edits
  • cargo fmt reformatted a matched line so the later parts did not apply
  • assert each pattern matched exactly once and abort otherwise
  • re-read the current text before re-applying