Rust uses “pattern” narrowly: a template that matches a value’s shape. “Diagram” usually means a compiler snippet, memory sketch, or documentation grammar. Read both by finding the outer shape, then the labels, then the constraints.
Start with the shape, not the syntax
When you meet Some((x, 0..=9)), do not read word by word. Ask: what is the outer constructor? Some wraps a tuple; the tuple has two slots; the first binds x, the second matches a range. Count delimiters. An unmatched bracket is often the real error. Patterns appear after let, inside match, after if let and while let, in function parameters, and in closures. Read the keyword first: a plain let needs an irrefutable pattern; match, if let, and while let accept refutable patterns. That distinction explains why let Some(x) = value; fails; use let Some(x) = value else { return; }; (let-else, Rust 1.65+) or a match.
Read a match pattern in four passes
match response {
Ok(Some(code)) if code >= 200 => println!("ok"),
Ok(None) | Err(Timeout) => println!("retry"),
other => println!("unexpected: {other:?}"),
}
Pass 1: find the scrutinee and the arms. An arm is pattern [if guard] => expression, comma-separated. Pass 2: split each pattern at top-level |; that is an or-pattern, not a closure. Pass 3: match delimiters: Ok(Some(code)) is outer Ok, inner Some, binding code. Pass 4: read guards after if; they can use bindings but do not change what the pattern matches. The final other binds; _ discards. Exhaustiveness is checked; a missing Err arm gives E0004 and a “patterns not covered” note.
Identify the five pattern kinds you will meet first
- Literal:
0,'a',true; exact match. - Binding:
x,mut x,ref x; a bare name always binds, soSome(x)binds whileSome(5)matches five. - Wildcard and rest:
_ignores one value;..ignores the rest of a tuple, struct, or slice;[first, .., last]needs at least two elements. - Destructuring:
Point { x, y },(a, b),Some(v);Point { x: px, y: py }renames fields. - Reference:
&value,&mut value; match ergonomics often lets you omit them. Read&Tin a diagram as “look through one reference”, not “copy the referent”.
Read the compiler's diagram from the outside in
Read compiler output in this order: error code, headline, snippet, carets, notes, help. A headline such as error[E0382]: borrow of moved value tells you the class; line and column numbers locate it; ^^^ marks the expression; notes point to the earlier move. Do not jump to the suggestion at the bottom. Check whether the type is Copy: an i32 is 4 bytes and copies, while a String owns heap data and moves. On a 64-bit target usize is 8 bytes. Sizes explain diagrams with a fixed stack slot and a heap pointer. Use rustc --explain E0382 for a 100–300-word explanation; use cargo check for the same type errors faster than cargo build.
Decode ownership and borrow diagrams
Ownership diagrams use boxes for values, arrows for references, and timelines for scopes. Boxes mean storage: stack frame, heap allocation, static data. A solid arrow usually means “points to”; a dashed arrow often means “moved from” or “borrowed”, but diagrams are not standardised, so read the legend. If an arrow starts at &mut T and ends at T, the borrow is exclusive: no other reference may be live over the same interval. Two immutable &T arrows may overlap. Lifetimes are intervals, not names: 'a spanning lines 3–7 means the reference must be valid for that whole interval. E0502, “cannot borrow as mutable because it is also borrowed as immutable”, is a timeline conflict; shorten one interval, copy a small value, or end the first borrow before mutating.
Read documentation diagrams without trusting them blindly
Documentation diagrams are simplified. Find the version first: edition 2015 examples can behave differently under edition 2021, and edition 2024 changes some temporary-scope and unsafe rules. Check the compiler version if a feature looks missing: let-else needs 1.65 or newer, and cargo new uses the current default edition, not necessarily the tutorial’s. In grammar diagrams, square brackets usually mean optional and | means choice; in code, | can be a closure or an or-pattern. Redraw each diagram in one sentence; if you cannot, test that part with a 10-line example.
Diagnose: “the pattern looks right but will not compile”
Symptoms: “expected pattern, found expression”, “refutable pattern in local binding”, or a caret under a | you thought opened a closure. Likely causes: a constant or function call where a pattern is required; a refutable pattern in a plain let; mixed closure and or-pattern syntax; or a bare name where you meant comparison. The fix: use literals or guards for comparisons, match/if let/let-else for refutable patterns, parenthesise the closure, and rename bindings. For E0004, add the missing variant rather than a wildcard so later changes are caught. For a move error, check whether a binding without ref moved the value.
A 20-minute drill for unfamiliar patterns
Set a timer for 20 minutes. Spend 5 minutes copying one pattern exactly, commas and braces included. Spend 5 minutes labelling every subpattern in words. Spend 5 minutes predicting each binding’s type; test with a deliberately wrong annotation such as let _: () = x; and read the reported type. Spend the last 5 minutes writing one passing and one failing input. Then redraw one diagram as three boxes: stack, heap, borrow interval. Mark which arrows are live at the error line. This is slower than copying solutions for the first week, but it builds the reading habit.
FAQ
What is the difference between a Rust pattern and an expression?
A pattern describes a shape and may bind names; an expression produces a value. Some(x) in a match arm is a pattern; Some(x) after => constructs a value. The tokens can look identical, so read the position.
Why does _ not let me use the value?
_ matches anything and binds nothing, so there is no name. Use _value to keep it, or _x to silence an unused-variable warning. A leading underscore changes warnings, not ownership.
Can I trust arrows in a Rust memory diagram?
Only after reading the legend. Arrows are a teaching convention, not Rust syntax. Check labels for &T, &mut T, Box<T>, and String; check whether the diagram shows a move, copy, or borrow. If two diagrams disagree, trust the compiler and a minimal example.