C.W.K.
Stream
Lesson 06 of 06 · published

Reading the Compiler Like a Mentor

~12 min · foundations, compiler, errors, clippy, mindset

Level 0Rust Curious
0 XP0/80 lessons0/19 achievements
0/100 XP to next level100 XP to go0% complete

You'll spend more time reading compiler output than almost anything else in Rust. The good news: Rust's errors are arguably the best in any mainstream language. Learning to read them is learning Rust.

Anatomy of an error

A Rust error has the same parts every time: an error code (E0382), a one-line summary, the span (the exact source pointed at with carets), and often a help: or note: suggesting the fix. Read it top to bottom. The summary tells you what; the span tells you where; the help tells you how.

rustc --explain

Every error code has a full writeup. rustc --explain E0382 prints a complete explanation with examples of the bug and the fix. When an error is unfamiliar, that's your first move — before any web search.

Warnings vs errors

Errors stop compilation; warnings don't, but ignore them at your peril. An unused variable, an unused import, a value you forgot to use — warnings are the compiler noticing a smell. Keep your build warning-clean from day one; it's far easier than digging out of a hundred later.

clippy — the compiler's opinionated cousin

cargo clippy goes beyond correctness into idiom: it catches a manual loop that should be an iterator, a verbose pattern with a cleaner form, a needless clone. It's like having a Rust mentor review every line. (Full tooling track later.)

The error message is the lesson. Rust front-loads the teaching into the compiler. Every error you actually read — instead of blindly pasting the suggested fix — is a concept you won't have to learn the hard way later.

Pippa's note

The reframe that made Rust click for me: the compiler isn't a gate I have to get past. It's a reviewer who already read my code and knows where it breaks. When I started reading errors as 'here's what I'd flag in review' instead of 'you failed,' the whole language softened.

Code

A real error, read top to bottom·text
error[E0382]: borrow of moved value: `s`
 --> src/main.rs:4:20
  |
2 |     let s = String::from("hi");
3 |     let s2 = s;        // value moved here
4 |     println!("{}", s); // value borrowed here after move
  |                    ^ value borrowed here after move
  |
  = help: consider cloning the value if the performance cost is acceptable
Your two debugging reflexes·bash
rustc --explain E0382   # full explanation of any error code
cargo clippy            # idiom + lint pass over the whole project

External links

Exercise

Write a tiny program that triggers a compiler error you haven't seen yet (try assigning to an immutable variable, or using a value after moving it). Don't fix it. Run rustc --explain on the error code it gives you, then write down — in your own words — exactly what rule you broke.
Hint
The point isn't the fix. It's building the habit of reading the error as information, not as rejection. That habit is the whole Ownership track's prerequisite.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue
💛 by Ttoriwarm

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.