TryBugHunt

Rust debugging exercises

Rust guarantees memory safety at compile time, but logical defects and runtime panics still occur: calling .unwrap() on a None Option crashes in production, slicing a String by raw byte indices splits multi-byte UTF-8 characters, and double-borrowing a RefCell panics dynamically.

These exercises train you to fix real Rust bugs: safe error handling with ? and match, UTF-8 character indexing, channel synchronization, and iterator exhaustion.

See the exercisesDo it as a 30-day pathFilter and search

Practise by topic

How to debug a Rust function

  1. Read the panic message. Rust panics give precise failure explanations, like 'called Option::unwrap() on a None value' or 'byte index is not a char boundary'.
  2. Avoid raw unwrap() in production logic. Replace unwrap() with unwrap_or, unwrap_or_else, or pattern matching.
  3. Respect UTF-8 boundaries. In Rust, String indexing is by byte, not character. Use .chars() or .char_indices() to handle unicode safely.
  4. Check integer overflow. In debug mode, u8 / i32 additions panic on overflow. Use saturating_add or checked_add when bounds are unpredictable.
  5. Audit RefCell borrow scopes. Ensure RefCell::borrow_mut guards are dropped before attempting a second borrow in the same execution path.

The exercises

Medium

What you will practise

Questions

Are these compiler errors or runtime bugs?

BugHunt focuses on logic errors, runtime panics, and edge cases where code compiles but produces incorrect behavior.

Do I need cargo installed?

No. Test verification runs through BugHunt with instant feedback in your browser.