AI Code Review for Rust: What to Look For
AI code review for Rust: what the borrow checker cannot catch, how unsafe blocks, unwrap panics, Send/Sync and async cancellation should be reviewed, and what Macroscope's 118-bug benchmark shows for Rust.
AI code review for Rust is worth running because the bugs that survive cargo build are logic, panic, error-handling, unsafe and async bugs that need judgment and cross-file context, and Macroscope reviews Rust pull requests on GitHub with full-repository context for each change.
Rust's compiler removes whole categories of defect that dominate review in other languages: use-after-free, data races in safe code, null dereferences. That does not automate the reviewer away. It moves the work. What remains after the borrow checker is satisfied is code that compiles, is memory-safe, and is still wrong.
TL;DR: AI Code Review for Rust
- The compiler is not the reviewer. A passing
cargo buildmeans safe Rust is memory-safe, not correct, andunsafecode can still break memory-safety invariants.- The real Rust review surface is panic paths, error handling that swallows failure,
unsafeinvariants,Send/Syncassumptions, and async cancellation.- Cross-file context matters most. Traits, impls, macros and re-exports spread one behavior across many files, so diff-only review misses the interesting failures.
- Benchmark data, labeled honestly: on Macroscope's internal 118-bug benchmark, Rust had 22 bugs. Macroscope caught 6 (27.27%) and CodeRabbit caught 10 (45.45%). Overall, across all eight languages, Macroscope caught the most bugs: 57 of 118 (48.31%).
- Use all the layers: the compiler, Clippy, cargo-audit, AI review and tests each cover a different slice.
What is AI code review for Rust?
AI code review for Rust is automated review of Rust pull requests that targets the defect classes the compiler permits: panics, lost errors, unsafe misuse, concurrency and async pitfalls, and plain logic errors.
The difference from other languages is what a reviewer can safely ignore. In Python or JavaScript, a large share of review effort goes to type confusion and null handling. In Rust the compiler owns those. That frees a reviewer, human or AI, to spend attention on intent, invariants, and the seams between modules and crates.
What can the Rust borrow checker not catch?
The borrow checker proves memory safety for safe code; it says nothing about panics, discarded errors, unsafe invariants, cancellation safety, or whether the logic does what the author intended.
Panics from unwrap, expect, indexing and arithmetic
unwrap(), expect(), slice indexing, integer division by zero and out-of-range slice bounds all compile and abort at runtime. In debug builds, integer overflow panics too, while release builds wrap by default, so the same code behaves differently by profile. The compiler has no opinion on whether a panic is acceptable at a given site. Context decides: unwrap() on a value known at compile time is fine; unwrap() on a parsed request header is an availability bug.
Error handling that silently loses information
Rust makes errors explicit but does not stop you discarding them. let _ = fallible(); compiles. So does .ok() on a Result you meant to propagate, mapping a rich error into a String, or collapsing five failure modes into one variant. The service fails correctly and tells you nothing about why.
Borrow and lifetime code that compiles but is logically wrong
Satisfying the borrow checker is not the same as modeling ownership correctly. A common pattern: a reviewer sees clone() added to make a lifetime error go away. It compiles, but now the code mutates a copy while the caller keeps reading the original, so an update is silently lost. Another: a RefCell borrow that is fine today and panics at runtime once a new caller re-enters the same method. Both pass cargo check.
Logic errors
The largest category, and the one no type system addresses. The if is inverted, the retry has no ceiling, the cache key is missing a field, the match arm for a new enum variant falls into a _ => wildcard that does the wrong thing.
How should you review unsafe blocks in Rust?
Review an unsafe block by checking the invariant it asserts, not the syntax: what must be true for this code to be sound, is that actually guaranteed, and what else in the module now depends on it.
unsafe does not switch off the borrow checker. It lets you call unsafe functions, dereference raw pointers, access mutable statics, implement unsafe traits and touch union fields, on the promise that you have upheld invariants the compiler cannot verify. A good review of an unsafe change asks:
- Is there a
// SAFETY:comment, and is it true? The comment is the claim; the surrounding code is the evidence. - Does the invariant hold across files? A raw pointer that is valid because a
Vecis never reallocated stops being valid when someone in another module adds apush. - Is the boundary sound? A safe public function wrapping
unsafeinternals must be sound for every input, not just today's callers. - Are
unsafe impl Sendorunsafe impl Syncjustified? These are promises to the whole program about thread safety.
What Rust concurrency and async bugs should review catch?
Review should catch wrong Send/Sync assumptions, lock guards held across .await, blocking calls inside async tasks, and futures that leave state half-updated when they are cancelled.
Send and Sync
Safe Rust rules out data races, but not deadlocks or logical races. Two Mutex locks taken in different orders on different paths compile cleanly and deadlock under load.
Holding a guard across an await
Holding a std::sync::MutexGuard across an .await makes the future non-Send, which fails on a multithreaded spawn but compiles on a local executor. Where it compiles, the lock is held while the task is suspended, which can stall or deadlock other tasks.
Blocking inside async
Blocking I/O, a long CPU loop or std::thread::sleep inside an async task starves the executor thread. It compiles everywhere and only shows up as latency under load.
Async cancellation
A future dropped at an .await point simply stops. If it had already written half of an update, that state stays half-written. select! branches, timeouts and request cancellation all drop futures. Reviewing async Rust means asking, at every .await, "what happens if execution never comes back here?"
Why is idiomatic Rust a correctness concern?
In Rust, the idioms usually encode a real constraint, so a non-idiomatic construct is often a latent bug or performance regression rather than a style preference.
clone()to escape a lifetime compiles and works, and can turn a borrow into an allocation in a hot path, or a shared update into a lost one.unwrap()in library code turns a caller's recoverable error into a panic and removes theirResultpath.- Rewriting an iterator chain as an indexed loop reintroduces bounds-check panics the iterator made impossible.
Vec<Box<dyn Trait>>where an enum would do trades a compile-time exhaustiveness check for runtime dispatch.
Macroscope reviews every language the same way, and its code review pipeline improvements shipped during 2026 for languages including Rust were aimed at catching more idiomatic issues per language.
How does Macroscope review Rust code?
Macroscope reviews Rust the same way it reviews every language: for each change in a GitHub pull request, an agent reads the diff and then explores the surrounding code in your repository to understand the context beyond it.
Macroscope reviews every language the same way, plus configuration, documentation and scripts, subject to file exclusions. Its published benchmark covered eight languages, Go, Java, JavaScript, Kotlin, Python, Rust, Swift and TypeScript, and Rust was one of the two largest language sets in it. The agent can also use web search for current crate and API documentation.
For Rust, the practical benefit is that the reviewer follows trait implementations, macro call sites, mod boundaries and pub use re-exports in the actual code rather than guessing from the diff. Findings arrive as inline GitHub comments with an impact explanation and, where applicable, a suggested diff. Fix It For Me can open a fix PR and iterate until CI passes.
What does benchmark data show for AI code review on Rust?
On Macroscope's internal 118-bug benchmark, Rust contributed 22 bugs; CodeRabbit detected 10 (45.45%), Cursor Bugbot 7 (31.82%), Macroscope 6 (27.27%), Graphite Diamond 3 (13.64%), and Greptile 4 of the 15 Rust bugs it was evaluated on (26.67%).
| Tool | Rust bugs detected | Rust detection rate | Overall (all 8 languages) |
|---|---|---|---|
| CodeRabbit | 10 of 22 | 45.45% | 45.76% (54 of 118) |
| Cursor Bugbot | 7 of 22 | 31.82% | 42.37% (50 of 118) |
| Macroscope | 6 of 22 | 27.27% | 48.31% (57 of 118) |
| Greptile | 4 of 15 | 26.67% | 23.61% (17 of 72) |
| Graphite Diamond | 3 of 22 | 13.64% | 18.26% (21 of 115) |
Source: Macroscope's internal code review benchmark, 118 real runtime bugs from 45 open-source repositories across eight languages.
Two things to keep in mind when reading this table:
- The Rust sample is 22 bugs. One bug is worth about 4.5 percentage points, so the per-language numbers move a lot with a handful of cases. Greptile was evaluated on fewer Rust bugs (15), so its rate is not directly comparable.
- The overall column is the larger sample. Across all 118 bugs, Macroscope had the highest detection rate. The bug detection by language page breaks down every language.
Why does cross-file analysis matter so much in Rust?
Rust's module and trait system distributes one logical behavior across a trait definition, its impls, its callers and a re-export, so the consequential Rust bug is usually "this impl no longer satisfies what a distant caller assumes."
A single change often touches a trait in one file, an impl in another, a caller elsewhere, and a pub use in lib.rs. Macros expand into code that is not textually present in the diff. Generics mean one source line has different behavior per instantiation. A reviewer confined to changed lines is badly positioned for all three.
That is why Macroscope reads beyond the diff for every change. For the general mechanics of multi-file bug detection, see how AI code review catches bugs across files.
How do you encode crate-specific Rust rules?
Write them as Check Run Agents: markdown reviewers in .macroscope/check-run-agents/ with include and exclude globs, each running as its own GitHub check.
Generic advice runs out quickly in a mature Rust codebase, because the rules that matter are local: no unwrap() outside main.rs and tests, every public error type implements a specific trait, no std::sync locks inside async modules, every unsafe block carries a // SAFETY: comment. Scope each rule to the crate it applies to so it does not fire on the CLI crate or the examples/ directory. A check is advisory by default; set conclusion: failure with input: full_diff to block merges through branch protection. The Check Run Agents guide has full examples.
You can also review locally before pushing with the Macroscope CLI: macroscope codereview opens a full-screen review in the terminal. See AI code review in the CLI.
Do you still need Clippy and cargo-audit with AI code review?
Yes: Clippy and cargo-audit are fast, deterministic and cheap, and AI review covers what needs judgment or cross-file context, so a strong Rust setup runs all of them.
cargo clippy. As of November 2026, the rust-clippy README states it includes over 800 lints, with thecorrectnessgroup denied by default andsuspicious,style,complexityandperfwarned by default. It installs withrustup component add clippy. Run it in CI; AI review should not repeat what a lint already flags.cargo audit. As of November 2026, the cargo-audit README describes it as auditing dependencies "for crates with security vulnerabilities reported to the RustSec Advisory Database." That is a dependency check, not a review of your own code.- The type system. If an invariant can be expressed as a type, express it there.
- Tests. The only thing that demonstrates behavior.
For the broader trade-off, see AI code review vs static analysis.
Frequently Asked Questions
Which programming languages does Macroscope support?
Macroscope reviews every language the same way, plus configuration, documentation and scripts, subject to file exclusions. Its published 118-bug benchmark covered Go, Java, JavaScript, Kotlin, Python, Rust, Swift and TypeScript. For language-specific guides, see Go and Swift.
Does Macroscope support Rust?
Yes. Macroscope reviews Rust pull requests on GitHub with full-repository context, the same way it reviews every other language. Rust was one of the eight languages in its benchmark, with 22 Rust bugs in the dataset.
Which AI code reviewer catches the most real bugs?
On Macroscope's internal 118-bug benchmark, Macroscope caught the most overall: 57 of 118 bugs (48.31%), ahead of CodeRabbit at 45.76% and Cursor Bugbot at 42.37%. Results vary by language: on the 22 Rust bugs, CodeRabbit caught 10 and Macroscope caught 6. See the benchmark write-up.
What tool can find bugs that span multiple files in a pull request, not just the diff?
Macroscope. For each change, an agent reads the diff and then explores the surrounding code in your repository, so it can see that a modified trait impl breaks an assumption in a caller in another module. This matters more in Rust than most languages, because traits, macros and re-exports spread behavior across files.
AI code review vs static analysis: do I need both?
Yes, for Rust especially. Clippy and cargo-audit are deterministic and catch lint-level issues and known-vulnerable dependencies cheaply. AI review handles what needs judgment and cross-file context, such as whether an unwrap() is reachable from untrusted input or whether an unsafe invariant still holds. See AI code review vs static analysis.
What are the best AI code review tools for GitHub in 2026?
The tools most teams evaluate are Macroscope, CodeRabbit, Cursor Bugbot, Greptile and Graphite Diamond, the five in Macroscope's 118-bug benchmark. Compare detection rate, comment volume and pricing model, then trial on your own repositories. The GitHub AI code review tools guide covers each in detail.
What can the Rust borrow checker not catch?
Panics from unwrap(), expect(), indexing and arithmetic; discarded or flattened errors; incorrect unsafe invariants; deadlocks and logical races; blocking calls in async code; cancellation leaving state half-updated; and ordinary logic errors.
Is unwrap() always a bug in Rust?
No, and a reviewer that flags every instance is noise. unwrap() on a value known to be valid, or in tests, is fine. It is a bug when the value comes from input, I/O, configuration or another thread, where the correct behavior is to return the error.
Can I write custom Rust review rules?
Yes. Check Run Agents are markdown-defined reviewers in .macroscope/check-run-agents/ with include and exclude globs, so you can scope a rule to one crate and run it as its own GitHub check, advisory or blocking.
How much does AI code review for Rust cost with Macroscope?
Macroscope is usage-based with no seats. Code Review is $0.05 per KB of diff in Balanced mode with a 10 KB minimum, and the average billed review from September 29 to October 28, 2026 was about 76 cents in Balanced and about 55 cents in Budget. Each new workspace gets a $100 new-workspace credit, and qualified non-commercial open source is free. See pricing.
