Rust errors

Rust compiler errors (E0382, E0502, E0308…) — ownership, borrowing, lifetimes and types — explained simply.

CodeErrorWhat it means
E0412: cannot find type in this scope Rust: error[E0412]: cannot find type `User` in this scope A type name isn't defined or imported in the current module.
E0432: unresolved import Rust: error[E0432]: unresolved import `crate::utils` — maybe a missing crate `utils`? A `use` path doesn't point to an existing module, crate or item.
E0308 Rust: error[E0308]: mismatched types — expected `X`, found `Y` A value’s type doesn’t match what the context expects — common with &str vs String, Option/Result vs plain va…
E0382 Rust: error[E0382]: borrow of moved value: `x` A value was moved (ownership transferred) and then used again.
Blocking waiting for file lock on package cache / build directory Cargo: Blocking waiting for file lock on package cache / on build directory Another cargo process (or rust-analyzer/IDE) holds the lock, so this command waits.
feature edition2024 is required / Cargo.lock version too new Cargo: error: failed to parse manifest — feature `edition2024` is required / lock file version 4 requires `-Znext-lockfile-bump` Your Cargo is older than the manifest or lockfile requires.
package requires rustc 1.xx or newer Cargo: error: package `home v0.5.9` cannot be built because it requires rustc 1.81 or newer, while the currently active rustc version is 1.78.0 A dependency's minimum supported Rust version (MSRV) is higher than your toolchain.
E0277: the trait bound is not satisfied Rust: error[E0277]: the trait bound `Foo: Display` is not satisfied / `Rc<RefCell<T>>` cannot be sent between threads safely A type doesn't implement a trait required by a function, macro or generic bound.
E0499: cannot borrow as mutable more than once at a time Rust: error[E0499]: cannot borrow `v` as mutable more than once at a time Two mutable references to the same value were alive at once, which Rust forbids.
E0502 Rust: error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable You tried to mutate a value while an immutable reference to it is still in use.
E0521: borrowed data escapes outside of function Rust: error[E0521]: borrowed data escapes outside of function — `data` escapes the function body here (tokio::spawn requires 'static) A reference was passed to something requiring `'static` (spawn tasks/threads) but it borrows local data.
there is no reactor running, must be called from the context of a Tokio 1.x runtime Rust: thread 'main' panicked: there is no reactor running, must be called from the context of a Tokio 1.x runtime A Tokio API (timer, TCP, `tokio::spawn`) was used outside a running Tokio runtime.
E0004: non-exhaustive patterns Rust: error[E0004]: non-exhaustive patterns: `None` not covered A `match` doesn't handle every possible value of the type.
E0015: cannot call non-const function in constants Rust: error[E0015]: cannot call non-const function `String::from` in constants A `const`/`static` initializer used something that can't run at compile time.
E0038: the trait cannot be made into an object Rust: error[E0038]: the trait `Shape` cannot be made into an object (not dyn compatible) You used `dyn Trait` for a trait whose methods aren't object-safe (generic methods, `Self` returns, `Sized`).
E0061: this function takes N arguments but M were supplied Rust: error[E0061]: this function takes 2 arguments but 1 argument was supplied A call has too few or too many arguments for the function signature.
E0133: call to unsafe function requires unsafe block Rust: error[E0133]: call to unsafe function `foo` is unsafe and requires unsafe function or block You called an `unsafe` function (or dereferenced a raw pointer / accessed a `static mut`) outside `unsafe`.
E0373: closure may outlive the current function Rust: error[E0373]: closure may outlive the current function, but it borrows `v`, which is owned by the current function A closure borrowing a local is passed somewhere that may outlive it (thread::spawn, tokio::spawn, returned cl…
E0599: no method named found for type Rust: error[E0599]: no method named `push_str` found for struct `Vec<String>` in the current scope The type doesn't have that method — wrong type, trait not in scope, or missing derive/feature.
E0608: cannot index into a value of type Rust: error[E0608]: cannot index into a value of type `HashSet<i32>` / `String` cannot be indexed by `{integer}` The type doesn't support `[]` indexing (or not with that index type).
failed to run custom build command for openssl-sys Cargo: error: failed to run custom build command for `openssl-sys v0.9.99` — Could not find directory of OpenSSL installation / pkg-config not found The `openssl-sys` crate can't find OpenSSL headers/libraries (or pkg-config) to link against.
E0369: binary operation cannot be applied to type Rust: error[E0369]: binary operation `+` cannot be applied to type `Foo` / cannot add `&str` to `&str` An operator (`+`, `==`, `
E0425: cannot find value in this scope Rust: error[E0425]: cannot find value `x` in this scope The identifier (variable, function, constant) isn't defined where it's used.
E0433: failed to resolve: use of undeclared type or module Rust: error[E0433]: failed to resolve: use of undeclared type `HashMap` A path starts with a name that isn't in scope (a type or module you didn't import).
E0728: await is only allowed inside async functions and blocks Rust: error[E0728]: `await` is only allowed inside `async` functions and blocks You used `.await` in a normal (sync) function or closure.
E0752: main function is not allowed to be async Rust: error[E0752]: `main` function is not allowed to be `async` `async fn main()` needs a runtime attribute (Tokio/async-std), the std `main` can't be async.
panic: already borrowed: BorrowMutError Rust: thread 'main' panicked at src/main.rs:8:9: already borrowed: BorrowMutError / already mutably borrowed: BorrowError A `RefCell` was borrowed in conflicting ways at runtime (a mutable borrow while another borrow was alive).
cargo: failed to select a version for the requirement Cargo: error: failed to select a version for the requirement `serde = "^2.0"` — candidate versions found which didn't match: 1.0.197 Cargo can't find a version of a dependency satisfying the constraints you (or other crates) set.
cargo: failed to get from registry (spurious network error) Cargo: warning: spurious network error (2 tries remaining): [35] SSL connect error / error: failed to download from `https://index.crates.io/...` Cargo couldn't reach crates.io (network, proxy, TLS or DNS issues).
error: linker `cc` not found Rust: error: linker `cc` not found — note: No such file or directory (os error 2) Rust needs a C linker (gcc/clang) to produce executables, and none is installed.
E0381: used binding isn't initialized Rust: error[E0381]: used binding `x` is possibly-uninitialized A variable might be read before every code path assigned it.
panic: attempt to divide by zero Rust: thread 'main' panicked at src/main.rs:3:13: attempt to divide by zero Integer division or remainder by zero.
panic: index out of bounds: the len is N but the index is M Rust: thread 'main' panicked at src/main.rs:5:5: index out of bounds: the len is 3 but the index is 3 A Vec/array/slice was indexed past its length.
PoisonError: poisoned lock: another task failed inside Rust: thread 'main' panicked: called `Result::unwrap()` on an `Err` value: PoisonError { .. } — poisoned lock: another task failed inside A thread panicked while holding a `Mutex`/`RwLock`, so the lock is "poisoned" and `lock().unwrap()` panics fo…
E0063: missing field in initializer of struct Rust: error[E0063]: missing field `age` in initializer of `User` A struct literal doesn't set all fields.
E0271: type mismatch resolving associated type Rust: error[E0271]: type mismatch resolving `<impl Iterator as Iterator>::Item == i32` A trait's associated type (Iterator::Item, Future::Output) doesn't match what's expected.
E0282: type annotations needed Rust: error[E0282]: type annotations needed for `Vec<_>` / consider giving `x` an explicit type The compiler can't infer a type from the available information.
E0384: cannot assign twice to immutable variable Rust: error[E0384]: cannot assign twice to immutable variable `x` You reassigned a variable declared without `mut`.
E0505: cannot move out of value because it is borrowed Rust: error[E0505]: cannot move out of `s` because it is borrowed You moved a value while a reference to it was still in use.
E0596: cannot borrow as mutable, as it is not declared as mutable Rust: error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable You called a `&mut` method (or took `&mut`) on a binding/reference that isn't mutable.
E0603: module/function/struct is private Rust: error[E0603]: function `helper` is private You used an item that isn't `pub` from outside its module.
E0616: field of struct is private Rust: error[E0616]: field `name` of struct `User` is private You accessed a struct field that isn't `pub` from outside its module.
E0716: temporary value dropped while borrowed Rust: error[E0716]: temporary value dropped while borrowed — creates a temporary value which is freed while still in use A reference points to a temporary that's dropped at the end of the statement.
thread 'main' has overflowed its stack (SIGABRT) Rust: thread 'main' has overflowed its stack — fatal runtime error: stack overflow Recursion (or huge stack allocations) exhausted the thread's stack.
panic: called Option::unwrap() on a None value Rust: thread 'main' panicked at src/main.rs:4:20: called `Option::unwrap()` on a `None` value `unwrap()` (or `expect`) was called on `None`, so the program panicked.
Cannot start a runtime from within a runtime (Tokio) Rust: thread 'main' panicked: Cannot start a runtime from within a runtime — a function like `block_on` tried to block a thread that drives async tasks Blocking code (`block_on`, `reqwest::blocking`) was called inside an async context.
E0507: cannot move out of a shared reference / index Rust: error[E0507]: cannot move out of `self.name` which is behind a shared reference You tried to take ownership of a value through a reference (or from a Vec/Option behind `&`).
E0597: borrowed value does not live long enough Rust: error[E0597]: `x` does not live long enough — borrowed value does not live long enough A reference outlives the value it points to (the value is dropped first).
panic: attempt to subtract with overflow Rust: thread 'main' panicked at src/main.rs:4:13: attempt to subtract with overflow An arithmetic operation overflowed (in debug builds) — commonly `usize` underflow like `0 - 1`.
panic: called Result::unwrap() on an Err value Rust: thread 'main' panicked at src/main.rs:5:36: called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit } `unwrap()`/`expect()` was called on an `Err`, and the error value is shown in the panic message.
error: toolchain 'stable' is not installed / override toolchain not found rustup: error: toolchain 'nightly-x86_64-unknown-linux-gnu' is not installed / error: no override and no default toolchain set rustup can't find the toolchain requested by `rust-toolchain.toml`, an override, or no default is set.
E0106: missing lifetime specifier Rust: error[E0106]: missing lifetime specifier — this function's return type contains a borrowed value, but the signature does not say which one of `x`'s 2 lifetimes it is borrowed from The compiler can't infer which input reference the returned/stored reference is tied to.
E0658: use of unstable library feature Rust: error[E0658]: use of unstable library feature `let_chains` / `#![feature]` may not be used on the stable release channel Your code uses a nightly-only feature on the stable toolchain.