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:
| Level | Meaning | Applied by default |
|---|---|---|
format-only | Changes layout only. | yes |
behavior-preserving | Changes the text, not what the program does. | yes |
local-edit | Changes one spot, and nothing outside it can notice. | yes |
api-changing | Changes something other code relies on, such as a parameter name callers can pass by name. | no |
target-changing | Changes where or how the program runs, such as moving data to the GPU or narrowing a number. | no |
requires-human-review | Plausible, 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:
| Repair | What it does | Offered with |
|---|---|---|
add-import | Import a name that resolves in exactly one module. | MER_TYP_034 MER_TYP_043 |
arrow-return-type | Drop the -> before a return type. | MER_PAR_001 |
cast-to-slot-type | Convert 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-annotation | Drop the : before a type annotation. | MER_PAR_001 |
concat-to-formatted-string | Rewrite a + chain joining text to values as one f-string. | MER_TYP_002 |
drop-extra-arguments | Drop positional arguments a call does not declare. | MER_TYP_030 |
drop-iterator-accessor | Drop a keys accessor on a keyed collection and iterate it directly. | MER_TYP_033 |
if-colon | Write : in place of then, or after an inline else. | MER_PAR_001 |
interpolation-quotes | Write the string literals inside an f-string’s braces with the other quote. | MER_LEX_012 |
let-mut-to-var | Rewrite a let mut binding as var. | MER_PAR_001 |
let-to-var | Rebind an immutable declaration as mutable. | MER_TYP_042 |
move-into-main | Move statements written beside main into it, in order, ahead of what it already does. | MER_TYP_069 |
null-to-none | Rewrite null, nil or nullptr as None. | MER_TYP_034 |
println-bang | Drop the ! from a macro-style call. | MER_LEX_001 |
qualify-variant-pattern | Prefix a bare variant pattern with the enum that declares it. | MER_TYP_038 |
remove-unused-import | Delete a use line nothing reads, or the unread names in a selection. | MER_IMP_005 |
rename-to-suggestion | Rewrite 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-binding | Prefix a binding nothing reads with _ to say the value is not meant to be read. | MER_TYP_071 MER_TYP_072 |
word-operator | Rewrite !, && or || as not, and or or. | MER_LEX_001 MER_PAR_020 |