Compiler errors
Every page here takes one compiler error and answers the only questions that matter: what does the
compiler actually mean, why did this code trigger it, and what are the ways to fix it. The output
shown is the real thing, copied from rustc, including the compiler’s own suggestion.
If you arrived from a search result, you are in the right place.
Articles
Section titled “Articles”- How to read a Rust compiler error messagethe anatomy: what, where, why, and the help block
- How to fix error E0382: borrow of moved valueborrow, clone, or restructure
- How to fix error E0384: cannot assign twice to immutable variablethe missing mut, and where to put it
- How to fix error E0499: cannot borrow as mutable more than oncescopes, and splitting the borrow
- How to fix error E0502: cannot borrow as mutable while it is borrowed as immutablethe read that outlives its welcome
- How to fix error E0505: cannot move out of a value because it is borroweddrop the borrow before the move
- How to fix error E0507: cannot move out of borrowed contentclone, take, or borrow deeper
- How to fix error E0596: cannot borrow as mutable, as it is not declared as mutablethe binding versus the field
- How to fix error E0597: borrowed value does not live long enoughreading the drop points in the note
- How to fix error E0716: temporary value dropped while borrowedbind it to a name first
- How to fix error E0425: cannot find value in this scopescope, imports, and typos the compiler cannot guess
- How to fix error E0432: unresolved importthe path is wrong, or the module is private
- How to fix error E0433: undeclared crate or modulefrom the module tree down
- How to fix error E0308: mismatched typesthe file, line, and column the compiler named
- How to fix error E0277: the trait bound is not satisfiedthree common causes, and how to tell them apart
- How to fix error E0106: missing lifetime specifierwhen the compiler needs to be told
- How to fix error E0282: type annotations neededgive the compiler one concrete type
- How to fix error E0599: no method named X found for type Ythe trait is not in scope
- How to fix error E0603: module is privatewhere pub belongs, and where it does not
Coming up (17)
- How to fix error E0614: type cannot be dereferencedone * too many, or one too few
- How to fix error E0658: use of unstable featurenightly, or a different way to write it
- How to fix error E0765: unstable library featuresame answer, different origin
- How to fix error E0463: can’t find cratethe dependency is missing, or the target is not installed
- How to fix error E0004: non-exhaustive patterns in a matchthe arm you forgot, and the catch-all you should not want
- How to fix error E0061: this function takes N arguments but M were suppliedthe argument you forgot, usually self
- How to fix “closure may outlive the current function”borrow or move, decided by intent
- How to fix “cannot move a value into an async block”what move onto an async block actually captures
- How to fix “recursive type has infinite size”Box, Rc, or a Vec to break the cycle
- How to fix “the size for values of type X cannot be known at compilation time”Sized, and why it is everywhere
- How to fix “cannot return value referencing local variable”return the owned value instead
- How to fix “cannot move out of X, which is behind a shared reference”clone, take, or Copy
- How to fix “borrowed data escapes outside of closure”the closure outlives the borrow
- How to fix “overflow evaluating the requirement”recursive trait bounds and how to stop them
- How to fix “cannot infer type for type parameter”the annotation goes on the call, not the function
- How to fix “mismatched types: expected (), found i32”the missing semicolon, and the missing return
- How to fix “requires that X is borrowed for ’static”owned data, or a leak you meant to make