Rust Reading Compiler Errors
A Rust compiler error is a small report about code that did not compile. Each report also shows the code and a suggested fix.
One missing ; stops everything
Forget one semicolon and the compiler stops the build. The whole message:
fn main() {
println!("one")
println!("two");
}A typo gets a suggestion
Mistype a name and the message names the problem. It points at the word. It offers the fix it guesses you meant:
fn main() {
printn!("Hello!");
}Every error carries a code
The headline names the problem in plain words, and the code in brackets names it forever. This one says: the type you promised and the value you gave do not match.
let score: i32 = "eighty";The picture points at the place
Under the headline, the compiler draws your own code back at you. It puts ^^^ marks under the exact spot. It adds notes in the margin. It is showing, not telling.
fn main() {
let score: i32 = "eighty";
println!("score = {}", score);
}Ask for the long explanation
Any code can be looked up in the terminal. The first line of the answer is the one-sentence version of the whole page:
// In your terminal:
// $ rustc --explain E0308help: lines offer the fix
Many errors end with a help: line that shows the change, sometimes as a tiny before-and-after diff. Here it offers to add one word:
let x = 5;
x = 6;A warning is advice, not a stop sign
Warnings look similar but never block the build. Fix them when you can — an ignored warning hides the next real error in the noise.
let y = 5;Example
fn main() {
let score: i32 = 80;
let word = "eighty";
println!("score = {}, word = {}", score, word);
}Key points
- Read the first error first: later errors in the list often exist only because the first one broke the code
- The E-number in brackets is a permanent name for that exact problem — searching it finds the same help everywhere
- The line starting with --> names the file and the exact spot. src/main.rs:2:14 means line 2, column 14.
- The ^^^ marks underline the code involved.
- rustc --explain E0308 prints the compiler's own full page on an error, with broken and fixed examples
- Lines starting with note: explain why.
- Lines starting with help: offer a concrete fix you can apply.
- In short, an error report names the problem, shows the place, and suggests a fix.
In this example, every line is the fixed version of an error from this lesson. The score is a real number, not text in quotes, so no E0308. println! is spelled in full, not printn!. Every statement ends with a semicolon. When your own code errors, aim for this. Read the headline. Find the picture. Try the help. Then change one thing and compile again.
Note
The wording of an error can shift slightly between compiler versions.
The E-number does not — that is the part worth remembering.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What does rustc --explain E0308 print?