rust
Rust Compiler Errors
Error codes emitted by the Rust compiler (rustc), covering type checking, borrow checking, pattern matching, and other compile-time diagnostics.
77 codes
· All codes 77 codes
- E0001 Unreachable Match Arm A match arm will never be reached because a preceding pattern already covers all possible values for that case. This typically occurs when patterns are ordered incorrectly, such as a wildcard placed before more specific arms.
- E0004 Non-exhaustive Match A match expression does not cover all possible values of the matched type. The compiler requires that every possible input has a corresponding pattern; add the missing patterns or a wildcard arm.
- E0005 Refutable Pattern in Binding A let binding uses a pattern that is not guaranteed to match in all cases. Patterns in let statements must be irrefutable; use match or if let for patterns that can fail.
- E0015 Non-const in Const Context A non-const function was called inside a constant or static expression. All functions used in const contexts must be marked with the const keyword so they can be evaluated at compile time.
- E0023 Wrong Pattern Field Count A pattern attempts to destructure an enum variant with the wrong number of fields. The pattern must provide exactly one sub-pattern per field in the variant definition.
- E0025 Duplicate Field Binding The same struct field is bound more than once in a single destructuring pattern. Each field may only appear once in a pattern.
- E0026 Nonexistent Struct Field A struct pattern references a field name that does not exist in the struct definition. Field names in patterns must match those declared in the struct.
- E0027 Missing Struct Pattern Fields A pattern matching a struct does not specify sub-patterns for all of the struct's fields. Either name every field explicitly or use .. to ignore the remaining fields.
- E0046 Missing Trait Items A type implements a trait but omits required methods or associated items that have no default implementation. Every non-default item declared in the trait must be provided in the impl block.
- E0050 Wrong Method Parameter Count A trait method implementation has a different number of parameters than the method declared in the trait. The implementation signature must match the trait signature exactly.
- E0054 Cast to Bool An attempt was made to cast a numeric type to bool using the as operator, which Rust does not permit. Use a comparison expression such as x != 0 to convert a number to a boolean.
- E0061 Wrong Argument Count A function was called with a number of arguments that does not match its signature. Rust does not support optional or variadic arguments in regular functions, so the call must supply exactly the expected number.
- E0062 Duplicate Struct Field Init A struct field is specified more than once in a struct initialiser expression. Each field must be assigned exactly one value.
- E0063 Missing Struct Field Init A struct initialiser does not provide a value for one or more required fields. All fields must be explicitly assigned when constructing a struct.
- E0072 Recursive Type Without Indirection A struct or enum references itself directly without indirection, producing a type of infinite size. Wrap the recursive reference in a heap-allocated pointer such as Box, Rc, or Arc.
- E0080 Constant Evaluation Failed The compiler could not evaluate a constant expression, typically due to division by zero or integer overflow. Constant values must be computable at compile time without undefined behaviour.
- E0106 Missing Lifetime Parameter A reference type in a struct, enum, or type alias is missing a lifetime annotation. Lifetime parameters must be declared and applied explicitly when references are stored in data structures.
- E0107 Wrong Generic Argument Count The wrong number of generic type or lifetime arguments was supplied when using a generic item. The count must exactly match the item's declaration.
- E0116 Impl on Foreign Type An inherent impl block was defined for a type from another crate. Rust only permits inherent implementations on types defined within the current crate.
- E0117 Orphan Rule Violation A trait from an external crate is being implemented for a type also from an external crate. Rust's coherence rules require that at least one of the trait or the implementing type be local to the current crate.
- E0119 Conflicting Trait Implementations Two implementations of the same trait exist for an overlapping set of types. This often occurs when a blanket impl conflicts with a more specific impl for the same type.
- E0120 Drop on Invalid Type The Drop trait was implemented for a trait object, reference, or other non-concrete type. Drop may only be implemented for structs, enums, and unions.
- E0121 Placeholder in Item Signature The type placeholder _ was used in an item's signature, such as a function return type or static declaration, where an explicit type is required. The _ placeholder is only valid in local variable bindings where the type can be inferred.
- E0124 Duplicate Struct Field Name A struct is declared with two or more fields sharing the same name. All field names within a struct must be unique.
- E0128 Forward Declared Type Default A type parameter default references another type parameter that has not yet been declared. Type parameter defaults are evaluated left to right and may only reference previously declared parameters.
- E0133 Unsafe Code Outside Block An unsafe operation such as dereferencing a raw pointer or calling an unsafe function was used outside of an unsafe block or unsafe function. Rust requires such operations to be explicitly enclosed in unsafe to make the potential hazard visible.
- E0152 Duplicate Lang Item A lang item already provided by the standard library has been redefined. Lang items should only be defined once; this error commonly occurs when writing a no_std crate that conflicts with an existing definition.
- E0201 Duplicate Associated Item Two associated items (methods, types, or constants) share the same name within a single impl block. Each associated item name must be unique within an implementation.
- E0210 Orphan Rule Type Parameter A foreign trait is implemented for a type parameter that is not covered by a local type. The orphan rule requires that uncovered type parameters be preceded by a local type in the trait's type argument list.
- E0220 Undefined Associated Type An associated type name was used that is not defined in the trait being referenced. Check the trait definition for the correct associated type names.
- E0229 Misplaced Associated Constraint An associated item constraint such as A = Bar was used in an invalid position. Associated item constraints must be placed in trait bounds or where clauses, not directly inside type argument lists.
- E0252 Duplicate Import Name Two items imported with use statements share the same name in the current scope. Disambiguate by renaming one import with the as keyword.
- E0261 Undeclared Lifetime A lifetime parameter such as 'a was used in a function, struct, or impl block without first being declared in the generic parameter list. Lifetimes must be declared before they can be referenced.
- E0277 Trait Bound Not Satisfied A type used in a context that requires a particular trait does not implement that trait. Either implement the required trait for the type or use a type that already satisfies the bound.
- E0283 Ambiguous Type Inference The compiler cannot infer a unique type for a value because multiple types satisfy the applicable trait bounds. Add an explicit type annotation to resolve the ambiguity.
- E0308 Type Mismatch An expression's type does not match what is expected at that location. This is one of the most common rustc errors, arising when passing arguments of the wrong type, assigning incompatible types, or mismatching function return types.
- E0317 Missing else Branch An if expression without an else block is used in a context that expects a non-() type. Because an if without else returns () on the non-taken branch, its result cannot be assigned to a variable of another type.
- E0369 Binary Operation Not Supported A binary operator was applied to a type that does not implement the corresponding trait from std::ops. Implement the required trait for the type or use a compatible operand type.
- E0382 Use After Move A variable was used after its value was moved to another binding. Rust's ownership model permits a value to have only one owner at a time; once moved, the original variable is no longer valid.
- E0384 Immutable Variable Reassignment A new value was assigned to a variable declared without the mut keyword. Variables in Rust are immutable by default; add mut to the declaration to allow reassignment.
- E0391 Circular Trait Dependency Two or more traits depend on each other in a cycle, which the compiler cannot resolve. Restructure the trait hierarchy to eliminate the circular dependency.
- E0401 Inner Item Uses Outer Generic A nested item such as an inner function or struct tries to use a generic parameter from its enclosing scope. Inner items are treated as top-level definitions and must explicitly redeclare any generic parameters they require.
- E0403 Duplicate Generic Parameter Multiple type parameters with the same name were declared in the same generic item. All type parameter names within a single generic context must be distinct.
- E0404 Expected Trait, Found Type A non-trait type such as a struct or type alias was used in a position that requires a trait, such as in an impl statement or as a generic bound. Only traits may appear in these positions.
- E0405 Trait Not in Scope A trait referenced in an impl or bound has not been imported or defined in the current scope. Add the appropriate use statement or check for a misspelling.
- E0407 Method Not in Trait A method was provided in a trait implementation that is not declared in the trait definition. Only methods explicitly defined in the trait may appear in its impl blocks.
- E0412 Unresolved Type Name A type name was used that is not declared or imported in the current scope. Common causes include a missing use statement, a typo in the type name, or an undeclared type alias.
- E0416 Duplicate Pattern Binding The same identifier was bound more than once in a single pattern. Each name in a pattern must be unique, as binding the same variable to two different values is ambiguous.
- E0425 Unresolved Name A variable, function, module, or other identifier was referenced that does not exist or has not been defined in the current scope. Check for typos, missing declarations, or missing use statements.
- E0428 Duplicate Definition A type, value, or module was defined more than once with the same name in the same scope. Each name may only be bound to one definition within a given scope.
- E0432 Unresolved Import A use statement refers to a module or item that cannot be found. Common causes include misspelling the path, a missing dependency in Cargo.toml, or the item not being publicly exported.
- E0433 Undeclared Crate or Module A crate, module, or type was referenced that has not been declared or imported. Ensure the dependency is listed in Cargo.toml and imported with a use statement, or check for a typo in the path.
- E0434 Inner Function Captures Environment An inner function defined with fn attempts to access variables from its enclosing scope, which is not permitted. Use a closure instead of an inner fn to capture the surrounding environment.
- E0499 Multiple Mutable Borrows A variable was borrowed mutably more than once simultaneously. Rust permits at most one active mutable reference to a value at any point in time to prevent data races.
- E0500 Closure Borrows Borrowed Variable A closure captures a variable that is already borrowed elsewhere in the enclosing scope. The conflicting borrow must end before the closure can capture the same variable.
- E0502 Conflicting Borrow Kinds A variable was borrowed with one mutability while an active borrow of the opposite mutability still exists. Rust does not permit a mutable borrow to coexist with any other borrow of the same value.
- E0505 Move While Borrowed A value was moved while an active borrow to it still exists. Moving transfers ownership and would invalidate any outstanding references to the value.
- E0506 Assign to Borrowed Value An attempt was made to assign a new value to a variable that is currently borrowed. The assignment would invalidate the existing reference, violating Rust's borrowing rules.
- E0507 Move Out of Borrow An attempt was made to move a value out of a borrowed reference. Borrowing grants temporary access but not ownership, so the value cannot be moved elsewhere while it is borrowed.
- E0515 Return Reference to Local A function attempts to return a reference to a local variable or temporary that will be dropped when the function returns. Return an owned value instead, as the referenced data would no longer exist after the function ends.
- E0516 Unsupported typeof Keyword The typeof keyword was used to obtain a type, but it is reserved and not implemented in Rust. Use explicit type annotations or rely on type inference instead.
- E0517 Invalid repr Attribute Target A #[repr(..)] attribute was placed on an item type that does not support it. For example, repr(C) is only valid on structs and enums, while repr(u8) is only valid on enums.
- E0560 Unknown Struct Field A struct initialiser includes a field name that does not exist in the struct definition. Check the struct declaration for the correct field names.
- E0562 impl Trait Outside Signature The impl Trait syntax was used outside of a function argument or return-type position. This syntax is only valid in function signatures, not in variable declarations or other item positions.
- E0594 Assign to Immutable Variable A new value was assigned to a variable or field that was not declared as mutable. Declare the binding with mut to permit assignment after initialisation.
- E0596 Cannot Mutably Borrow Immutable A mutable reference was requested for a variable that was not declared as mutable. Add the mut keyword to the variable's declaration to allow mutable borrowing.
- E0597 Value Dropped While Borrowed A value goes out of scope while it is still referenced by another variable. The borrow outlives the value's lifetime, which would produce a dangling reference.
- E0599 Method Not Found A method was called on a type that does not implement that method. Either implement the method for the type or use a type that already provides it.
- E0601 Missing main Function A binary crate was compiled without a main function as the program entry point. Add a fn main() to the crate root.
- E0603 Private Item Access An attempt was made to access a private item from outside the module where it is defined. Mark the item pub to expose it, or access it through a public API provided by the module.
- E0605 Invalid Type Cast An as cast was attempted between non-primitive types, or between a primitive and a non-primitive type. The as operator is restricted to casts between compatible primitive types.
- E0614 Dereference of Non-pointer The dereference operator * was applied to a type that does not implement Deref. Only reference types and types that explicitly implement std::ops::Deref can be dereferenced.
- E0616 Private Field Access A struct field was accessed from outside the module in which it is declared. Struct fields are private by default; mark the field pub or add a public accessor method.
- E0618 Call of Non-function A value that is not a function or closure was invoked with (). Only functions, closures, and types implementing the Fn traits may be called with parentheses.
- E0620 Cast to Unsized Type An as cast targeted an unsized type such as a bare slice [T]. Unsized types cannot be held by value; cast to a reference or pointer to an unsized type instead.
- E0635 Unknown Feature Flag A #![feature(...)] attribute specified a feature name that does not exist in the Rust compiler. Check the Rust nightly feature list for valid feature names.
- E0658 Unstable Feature Used An unstable Rust feature was used on a stable or beta compiler. Either switch to a nightly toolchain and add the corresponding #![feature(...)] attribute, or avoid the unstable feature.