Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix B — Compiler Errors Decoded

Error Families

Read the Code as an Invariant Violation

ownershipE0382 E0505 E0507who owns this now?lifetimeE0106 E0515 E0597 E0716what outlives what?traitE0277 E0038 E0599what capability is missing?typeE0282 E0283 E0308what story is ambiguous?
CodePlain EnglishInvariant being violatedCommon root causeCanonical fix
E0106A borrowed relationship was not spelled outReturned or stored references must be tied to valid ownersMultiple input references or borrowed structs without explicit lifetimesAdd lifetime parameters that describe the relationship
E0277A type does not satisfy a required capabilityGeneric code may only assume declared trait boundsMissing impl, wrong bound, or wrong typeAdd the trait bound, use a compatible type, or implement the trait
E0282Type inference cannot determine a concrete typeThe compiler needs one unambiguous type storycollect(), parse(), or generic constructors without enough contextAdd a type annotation or turbofish
E0283Multiple type choices are equally validAmbiguous trait/type resolution must be resolved explicitlyConversion or generic APIs with several candidatesProvide an explicit target type
E0308The expression does not evaluate to the type you claimedEach expression path must agree on typeMissing semicolon understanding, wrong branch types, wrong return typeConvert values or change the function/variable type
E0038A trait cannot be turned into a trait objectRuntime dispatch needs object-safe traitsReturning Self, generic methods, or Sized assumptions in a dyn traitRedesign the trait or use generics instead of trait objects
E0373A closure may outlive borrowed data it capturesEscaping closures must not carry dangling borrowsSpawning threads/tasks with non-'static capturesUse move, clone owned data, or use scoped threads
E0382You used a value after moving itA moved owner is no longer validPassing ownership into a function or assignment, then reusing original bindingBorrow instead, return ownership back, or clone intentionally
E0432Import path not foundModule paths must resolve to actual itemsWrong module path or forgotten pubFix use path or visibility
E0433Name or module cannot be resolvedNames must exist in scope and dependency graphMissing crate/module declaration or typoAdd dependency/import/module declaration
E0499Multiple mutable borrows overlapThere may be only one active mutable referenceHolding one &mut while creating anotherShorten borrow scope or restructure data access
E0502Shared and mutable borrows overlapAliasing and mutation cannot coexistReading from a value while also mutably borrowing itEnd the shared borrow earlier or split operations
E0505Value moved while still borrowedA borrow must remain valid until its last useMoving a value into a function/container while a reference to it still existsReorder operations or clone/borrow differently
E0507Tried to move out of borrowed contentBorrowed containers may not lose owned fields implicitlyPattern-matching or method calls that move from &T or &mut TClone, use mem::take, or change ownership structure
E0515Returned reference points to local dataReturned borrows must outlive the functionReturning &str/&T derived from a local String/VecReturn owned data or tie the borrow to an input
E0521Borrowed data escapes its allowed scopeA closure/body cannot leak a shorter borrow outwardCapturing short-lived refs into spawned work or returned closuresOwn the data or widen the source lifetime correctly
E0596Tried to mutate through an immutable pathMutation requires a mutable binding or mutable borrowMissing mut or using &T instead of &mut TAdd mutability at the right layer
E0597Borrowed value does not live long enoughThe owner disappears before the borrow endsReferencing locals that die before use completesExtend owner lifetime or reduce borrow lifetime
E0599No method found for type in current contextMethods require the type or trait to actually provide themMissing trait import or wrong receiver typeImport the trait, adjust the type, or call the right method
E0716Temporary value dropped while borrowedReferences to temporaries cannot outlive the temporary expressionBorrowing from chained temporary valuesBind the temporary to a named local before borrowing

Error Reading Habits

  1. Read the first sentence of the error for the category.
  2. Read the labeled spans for the actual conflicting operations.
  3. Ask which invariant is broken: ownership, lifetime, trait capability, or type agreement.
  4. Use rustc --explain CODE when the category is new to you.