Appendices
Appendix A — Compiler-error decoder: the 15 errors you will actually see
| Code | Message (short) | What it means | Usual fix | Chapter |
|---|---|---|---|---|
| E0382 | use of moved value | you used a value after giving it away | borrow (&x), clone, or restructure |
6 |
| E0499 | cannot borrow as mutable more than once | two &mut alive at once |
shorten one borrow, split the borrow | 7 |
| E0502 | cannot borrow as mutable because also borrowed as immutable | reading and writing overlap | finish reading first; copy the value out | 7 |
| E0505 | cannot move out because it is borrowed | moved a value while a reference to it is alive | end the borrow first | 19 |
| E0506 | cannot assign to borrowed value | wrote to something being read | reorder | 7 |
| E0597 | does not live long enough | a reference outlives its owner | move the owner to an outer scope, or own the data | 19 |
| E0515 | cannot return reference to local | returned & to a value that dies on return |
return an owned value | 13 |
| E0716 | temporary value dropped while borrowed | &String::new()-style temporaries |
bind the temporary with let first |
13 |
| E0106 | missing lifetime specifier | the output borrows from an ambiguous input | add <'a>, or return an owned type |
19 |
| E0373 | closure may outlive the current function | a thread or task closure borrows a local | move, and own the data |
20, 28 |
| E0277 | trait bound not satisfied | wrong type, or missing Send/Clone/Display... |
implement or derive the trait, change the type (Rc → Arc) |
16, 28 |
| E0308 | mismatched types | often a stray ; or a missing .into()/? |
read the expected vs found types | 5 |
| E0599 | no method found | missing trait import, or the wrong type/state | use the trait; check typestate |
16, 62 |
| E0004 | non-exhaustive patterns | a match misses a case |
add the arm (do not reach for _ by reflex) |
9 |
| E0384 | cannot assign twice to immutable variable | missing mut |
let mut |
3 |
rustc --explain E0502 prints a full explanation with examples for any
code.