Rust Compiler Errors, Explained
The Rust compiler is strict, but its error messages are precise once you know how to read them. Paste what cargo build or rustc printed, and the lookup finds every error code in it, with a quick fix and a link to the full explanation.
Paste what cargo build printed, or just type a code such as E0502. Nothing leaves your browser.
Common Rust errors
These 22 errors cover most of what beginners hit, especially from the borrow checker. Each page has a short program that triggers the error, the compiler’s real output, why Rust rejects the code, and fixes that compile. Every example was checked with rustc 1.88, using the 2024 edition that cargo new sets up.
Ownership and moves
Borrowing
Lifetimes and dangling references
Mutability
Types and traits
Structs and fields
Names, paths and modules
Pattern matching
How to read a Rust error message
Every Rust compiler error has the same parts. Here’s the output for E0382, the most common ownership error:
error[E0382]: borrow of moved value: `title`
--> src/main.rs:8:15
|
6 | let title = String::from("Rust errors explained");
| ----- move occurs because `title` has type `String`, which does not implement the `Copy` trait
7 | print_len(title);
| ----- value moved here
8 | println!("{title}");
| ^^^^^^^ value borrowed here after move
|
note: consider changing this parameter type in function `print_len` to borrow instead if owning the value isn't necessary
--> src/main.rs:1:17
|
1 | fn print_len(s: String) {
| --------- ^^^^^^ this parameter takes ownership of the value
| |
| in this function
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value if the performance cost is acceptable
|
7 | print_len(title.clone());
| ++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0382`.- The code and headline.
error[E0382]is the error code, and the text after it says what went wrong. The code is what you look up. - The location.
--> src/main.rs:8:15means the filesrc/main.rs, line 8, column 15. - The labels. The
^^^underline marks where the error happened. The---underlines mark the places that led to it: here, wheretitlewas created and where it moved. - Notes and help. A
noteadds context. Ahelpsuggests a fix, often as a small diff where+marks code to add. - The long explanation. The last line names
rustc --explain E0382, which prints the official explanation in your terminal.
Several errors at once? Fix the first one and build again. One mistake often causes more errors further down, and those disappear with it.
Learn the rules behind the errors
Most errors on this page come from a few rules, and each has its own lesson with diagrams:
- Ownership: every value has one owner, and assignment moves it. Behind E0382, E0505 and E0507.
- References and Borrowing: many readers or one writer, and no reference may outlive its data. Behind E0502, E0499, E0596, E0106, E0597, E0515 and E0716.
- Variables and Mutability: variables can’t change unless declared
mut. Behind E0384. - Structs and Match: every field set, every case handled. Behind E0063, E0609 and E0004.
Can’t find your error here? The lookup links every code to the official Rust error index .