docs / Miri for Agents / Repairs — miri fix

Repairs — miri fix

A repair is an edit the compiler is sure of. When a diagnostic carries one, miri fix can write it. Without --apply it only shows what it would do:

$ miri fix tally.mi
tally.mi:9:18 [MER_PAR_020]
  '&&' is not a valid operator in Miri
  repair word-operator: Write `&&` as `and`.
    replace `&&` with `and` at 219
exit status 0

miri fix FILE --apply --yes writes every repair in the file in one go. (--yes confirms the write when there is no terminal to ask at, which is always the case for an agent.)

How safe is a repair?

Every diagnostic code has a fixSafety level. miri fix --apply writes the first three on its own and refuses the rest unless you add --allow-risky:

LevelMeaningApplied by default
format-onlyChanges layout only.yes
behavior-preservingChanges the text, not what the program does.yes
local-editChanges one spot, and nothing outside it can notice.yes
api-changingChanges something other code relies on, such as a parameter name callers can pass by name.no
target-changingChanges where or how the program runs, such as moving data to the GPU or narrowing a number.no
requires-human-reviewPlausible, but a person should look first.no

Every repair

The list the miri-lang pack carries, with the diagnostic codes that can offer each repair:

RepairWhat it doesOffered with
add-importImport a name that resolves in exactly one module.MER_TYP_034 MER_TYP_043
arrow-return-typeDrop the -> before a return type.MER_PAR_001
cast-to-slot-typeConvert a number with as to the width of the place it is stored; a value outside that width’s range is truncated or rounded.MER_TYP_002
colon-annotationDrop the : before a type annotation.MER_PAR_001
concat-to-formatted-stringRewrite a + chain joining text to values as one f-string.MER_TYP_002
drop-extra-argumentsDrop positional arguments a call does not declare.MER_TYP_030
drop-iterator-accessorDrop a keys accessor on a keyed collection and iterate it directly.MER_TYP_033
if-colonWrite : in place of then, or after an inline else.MER_PAR_001
interpolation-quotesWrite the string literals inside an f-string’s braces with the other quote.MER_LEX_012
let-mut-to-varRewrite a let mut binding as var.MER_PAR_001
let-to-varRebind an immutable declaration as mutable.MER_TYP_042
move-into-mainMove statements written beside main into it, in order, ahead of what it already does.MER_TYP_069
null-to-noneRewrite null, nil or nullptr as None.MER_TYP_034
println-bangDrop the ! from a macro-style call.MER_LEX_001
qualify-variant-patternPrefix a bare variant pattern with the enum that declares it.MER_TYP_038
remove-unused-importDelete a use line nothing reads, or the unread names in a selection.MER_IMP_005
rename-to-suggestionRewrite a name as the one spelling the help offers in its place.MER_IMP_003 MER_TYP_033 MER_TYP_034 MER_TYP_038 MER_TYP_043
underscore-unread-bindingPrefix a binding nothing reads with _ to say the value is not meant to be read.MER_TYP_071 MER_TYP_072
word-operatorRewrite !, && or || as not, and or or.MER_LEX_001 MER_PAR_020