Quick Ref: Troubleshooting ​
Updated Mar 2026Common Compiler Errors ​
Ownership & Borrow Errors ​
E0382: Use of moved value ​
rust
// ERROR
let s = String::from("hello");
let s2 = s;
println!("{s}"); // Error: s was moved
// FIX: Clone or borrow
let s2 = s.clone(); // Option 1: Clone
let s2 = &s; // Option 2: BorrowE0502: Cannot borrow as mutable because also borrowed as immutable ​
rust
// ERROR
let mut v = vec![1, 2, 3];
let first = &v[0];
v.push(4); // Error: v is mutably borrowed
println!("{first}");
// FIX: Finish using immutable borrow first
let mut v = vec![1, 2, 3];
let first = v[0]; // Copy the value (i32 is Copy)
v.push(4);
println!("{first}");E0499: Cannot borrow as mutable more than once ​
rust
// ERROR
let mut s = String::from("hello");
let r1 = &mut s;
let r2 = &mut s; // Error: second mutable borrow
// FIX: Scope the borrows
let mut s = String::from("hello");
{
let r1 = &mut s;
r1.push_str(" world");
} // r1 goes out of scope
let r2 = &mut s; // Now OKE0507: Cannot move out of borrowed content ​
rust
// ERROR
fn first(v: &Vec<String>) -> String {
v[0] // Error: can't move out of &Vec
// FIX: Clone or return reference
fn first(v: &Vec<String>) -> String {
v[0].clone() // Clone the value
}
fn first(v: &[String]) -> &str {
&v[0] // Return a reference
}Lifetime Errors ​
E0106: Missing lifetime specifier ​
rust
// ERROR
fn longest(x: &str, y: &str) -> &str {
if x.len() > y.len() { x } else { y }
}
// FIX: Add lifetime annotation
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
if x.len() > y.len() { x } else { y }
}E0597: Does not live long enough ​
rust
// ERROR
let r;
{
let s = String::from("hello");
r = &s; // Error: s doesn't live long enough
}
println!("{r}");
// FIX: Extend lifetime or own the data
let s = String::from("hello");
let r = &s;
println!("{r}");Type Errors ​
E0308: Mismatched types ​
rust
// ERROR
fn add(a: i32, b: i32) -> i32 { a + b }
let result = add(1.0, 2.0); // Error: expected i32, found f64
// FIX: Use correct types or convert
let result = add(1, 2); // Correct types
let result = add(1.0 as i32, 2); // Explicit castE0277: Trait not satisfied ​
rust
// ERROR
fn print_it<T: std::fmt::Display>(item: T) {
println!("{item}");
}
print_it(vec![1, 2, 3]); // Error: Vec doesn't implement Display
// FIX: Use Debug trait instead, or implement Display
fn print_it<T: std::fmt::Debug>(item: T) {
println!("{item:?}");
}E0599: Method not found ​
rust
// ERROR
let s = "hello";
s.push_str(" world"); // Error: &str has no method push_str
// FIX: Use the right type
let mut s = String::from("hello");
s.push_str(" world"); // String has push_strTrait Errors ​
E0119: Conflicting implementations ​
rust
// ERROR: Can't implement external trait for external type
impl Display for Vec<String> { } // Error: orphan rule
// FIX: Newtype pattern
struct MyVec(Vec<String>);
impl Display for MyVec { ... }E0038: Object safety violation ​
rust
// ERROR
trait Cloneable {
fn clone_it(&self) -> Self; // Returns Self — not object safe
}
let x: &dyn Cloneable; // Error
// FIX: Remove Self from return or use associated type
trait Cloneable {
fn clone_it(&self) -> Box<dyn Cloneable>;
}Module Errors ​
E0432: Unresolved import ​
rust
// ERROR
use my_module::MyStruct; // Error: not found
// Common causes:
// 1. Module not declared: add `mod my_module;` in lib.rs/main.rs
// 2. Item is private: add `pub` to the item
// 3. Wrong path: check crate::, super::, self:: prefixesE0603: Item is private ​
rust
// ERROR
mod inner {
struct Secret; // Private by default
}
let s = inner::Secret; // Error: private
// FIX: Make it public
mod inner {
pub struct Secret;
}Async Errors ​
Future is not Send ​
rust
// ERROR
let data = Rc::new(42);
tokio::spawn(async move {
println!("{data}"); // Error: Rc is not Send
});
// FIX: Use Arc
let data = Arc::new(42);
tokio::spawn(async move {
println!("{data}"); // Arc is Send
});Holding MutexGuard across await ​
rust
// ERROR
let mutex = tokio::sync::Mutex::new(0);
let guard = mutex.lock().await;
some_async_fn().await; // Guard held across await point!
drop(guard);
// FIX: Scope the guard
{
let mut guard = mutex.lock().await;
*guard += 1;
} // Guard dropped before await
some_async_fn().await;Debugging Tools ​
| Tool | Command | Purpose |
|---|---|---|
| Backtrace | RUST_BACKTRACE=1 cargo run | Full stack trace on panic |
| Clippy | cargo clippy | Catch common mistakes |
| Miri | cargo +nightly miri test | Detect undefined behavior |
| Expand | cargo expand | See macro expansions |
| Rust Analyzer | IDE integration | Real-time error checking |
Quick Fixes Cheatsheet ​
| Problem | Quick Fix |
|---|---|
| "value moved here" | Add .clone() or change to & |
| "doesn't live long enough" | Move declaration to outer scope |
| "expected X, found Y" | Add as Type or .into() |
| "trait Display not implemented" | Use {:?} instead of {}, or derive Debug |
| "cannot find X in this scope" | Add use import or mod declaration |
| "unused variable" | Prefix with _: _unused |
| "unused Result" | Add let _ = or handle with ? |
| "overflow in arithmetic" | Use checked_add() or wrapping_add() |
| "index out of bounds" | Use .get() which returns Option |
| "closures can only be coerced to fn if they don't capture" | Remove captures or use Box<dyn Fn> |