Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Rust tells: unwrap, clone and RefCell to appease the compiler
card 1 of 6
Clean build, but what did it trade?
builds on: Silencing the checker: type escapes and suppressions, Error handling idioms across languages
You added a `cache` field to a Rust service and asked the agent to fix the borrow-checker errors. Five minutes later: `cargo build` clean, tests green. The diff adds three `.clone()` calls and swaps two `?` for `.unwrap()`. It also turns `cache: Cache` into `cache: Rc<RefCell<Cache>>`. Nothing looks like `unsafe` or `#[allow]`. Is this finished?
Terms on this card
- cargo build
- The standard Rust command that compiles a project and its dependencies.
- .unwrap()
- Rust method on Option/Result that returns the inner value, or panics if it is None or Err.
- .clone()
- Makes an independent copy of a value. Changes to the copy don't affect the original. For Rc/Arc it only copies the pointer.
- ?
- Rust operator that returns early from the function with the Err (or None), passing the error to the caller instead of panicking.
- unsafe
- Rust keyword that permits operations the compiler cannot check, such as raw pointer access; the programmer takes over the guarantee.
Lesson goal: Recognise Rust-specific shortcuts: `.unwrap()`/`.expect()` on fallible paths, `.clone()` scattered to dodge borrow errors, and `Rc<RefCell<_>>` or `Arc<Mutex<_>>` used where ownership needed redesigning. Explain the panics and runtime borrow failures these trade for a clean compile. ·
the whole lesson