Standard-library error features by Rust version, the thiserror 1 to 2 migration, and anyhow notes, so advice matches the project's MSRV and dependency versions.
Contents
Standard library
| Rust | Feature | Before it |
|---|---|---|
| 1.13 | the ? operator (for Result) | the try! macro |
| 1.22 | ? on Option | .ok_or(..)? / match |
| 1.26 | main may return Result<(), E: Debug> | std::process::exit after printing |
| 1.30 | Error::source (replaces cause) | Error::cause (deprecated) |
| 1.34 | TryFrom/TryInto | custom fallible constructors |
| 1.42 | matches! macro | match .. { X => true, _ => false } |
| 1.61 | std::process::ExitCode and Termination for custom exit codes | process::exit(n) |
| 1.65 | std::backtrace::Backtrace; let ... else | the backtrace crate; nested match |
| 1.81 | core::error::Error (the Error trait in core, usable in no_std) | std-only errors or crate-specific traits |
Notes:
Backtrace::capture()respectsRUST_BACKTRACEandRUST_LIB_BACKTRACE;Backtrace::force_capture()always captures. Capturing is expensive: do it at error creation in rare paths only.fn main() -> Result<(), E>printsError: {e:?}(the Debug form) and exits with code 1.Error::descriptionis deprecated (since 1.42); implementDisplayinstead.
thiserror 1 -> 2
thiserror 2.0 (November 2024) is a small migration for most code:
| Area | Change |
|---|---|
no_std | supported: disable default features (default-features = false) to use core::error::Error |
| MSRV | raised (thiserror 2 needs a newer Rust than 1.x did; check the crate's rust-version) |
| Raw identifiers in messages | a field r#type is referred to as {type} in #[error("..")], not {r#type} |
| Generated code | refers to ::thiserror paths, so the crate deriving Error needs thiserror as a direct dependency (not only a re-export) |
Migration steps: bump to thiserror = "2", cargo check, fix any raw-identifier placeholders, run tests that
pin Display text. Both majors can coexist in one dependency graph (different crates).
anyhow
- anyhow 1.x is stable and backwards compatible;
anyhow::ErrorrequiresSend + Sync + 'staticsources. - Backtraces: on Rust 1.65+ anyhow uses
std::backtraceand captures whenRUST_BACKTRACE=1orRUST_LIB_BACKTRACE=1is set; printed by the{:?}report. Result<T, anyhow::Error>alias:anyhow::Result<T>;anyhow::Ok(v)helps type inference in closures.- Formats:
{}outermost message,{:#}whole chain on one line joined by:,{:?}multi-line report withCaused by:and the backtrace,{:#?}struct-style debug. - Alternatives with similar APIs:
eyre/color-eyre(customisable reports),miette(diagnostics with source spans),error-stack(typed contexts with attachments).
Still unstable
| Feature | Stable alternative |
|---|---|
try blocks (try { .. }) | an immediately-called closure `( |
Error::provide / generic member access | store data (backtraces, codes) in fields and expose accessors |
Try trait for custom types (? on your own type) | return Result/Option, or convert with .into() |
never type (!) in more positions | std::convert::Infallible |
MSRV guidance
- Below 1.81: no
core::error::Error;no_stdlibraries need their own error trait or a feature-gated std impl. - Below 1.65: no
std::backtrace; use thebacktracecrate or skip backtraces. - Below 1.61: no
ExitCode; exit codes needprocess::exit(accept ERR013 there, or upgrade). - Check thiserror 2's own
rust-versionbefore upgrading a crate with an old MSRV; staying on thiserror 1 is fine if the MSRV cannot move.
rust-borrow-checker-error-explainer
Explain and fix Rust borrow-checker, ownership, move and lifetime compiler errors: E0382 use of moved value, E0499 cannot borrow as mutable more than once, E0502 also borrowed as immutable, E0505, E0506, E0503, E0507 cannot move out of index/Rc/reference, E0515 return reference to local, E0597 does not live long enough, E0716 temporary value dropped while borrowed, E0373 closure may outlive (spawn needs move), E0521 borrowed data escapes, E0384, E0596, E0594, E0381, E0713, 'lifetime may not live long enough', RefCell 'already borrowed: BorrowMutError' panics. Ranks fixes from restructuring (split borrows, entry API, split_at_mut, get_disjoint_mut, mem::take, Option::take, indices, thread::scope) down to clone and Rc<RefCell>/Arc<Mutex>; never unsafe. Covers NLL limits (get-or-insert), iterator invalidation, closure captures, self-referential structs. Ships std-only Rust triage tools.
rust-cargo-workspace-designer
Design, review and fix Cargo workspaces: when to split a crate (compile time, boundaries, publishing, proc-macros), crates/* vs apps/ + crates/ layouts, virtual manifest vs root package, members/exclude/default-members, resolver 2 vs 3 (MSRV-aware, edition 2024), [workspace.package] and [workspace.dependencies] inheritance, [workspace.lints], root-only profiles (lto, codegen-units), additive features with dep: and weak ?/ syntax, feature unification pitfalls, internal path + version deps, publish = false, Cargo.lock and MSRV policy, xtask, CI with --locked, nextest, rust-cache, sccache, cargo-hack/deny/machete/udeps/semver-checks, and cargo build --timings. Ships a workspace auditor and crate-graph tool.
rust-lifetime-annotation-advisor
Decide when Rust lifetime annotations are needed and which ones: the three elision rules, structs holding references (struct Parser<'a>), owned vs borrowed (String, &str, Cow<'a, str>, Arc<str>), one vs several lifetimes, 'a: 'b bounds, T: 'static misconceptions, Box<dyn Trait + 'a> default object lifetimes, impl Trait + '_ and edition 2024 capture rules with use<..>, variance and PhantomData, HRTB for<'a> Fn(&'a T), GATs and lending iterators, async fn and tokio::spawn 'static, self-referential structs (ouroboros, self_cell, indices, arenas), Rc/Arc to escape lifetime soup. Ships std-only Rust checkers for redundant, missing, unused and over-restrictive lifetimes.
rust-tokio-async-service-builder
Build and review production async Rust services on Tokio 1.x and axum 0.8: runtime choice (#[tokio::main] multi_thread vs current_thread, Builder), axum routing with /{id} paths, State, extractors, IntoResponse error types, axum::serve with_graceful_shutdown, tower/tower-http middleware (TraceLayer, TimeoutLayer, CorsLayer, ConcurrencyLimitLayer, RequestBodyLimitLayer), Arc<AppState>, std vs tokio Mutex, JoinSet, TaskTracker, CancellationToken, select! cancel safety, bounded mpsc, oneshot, broadcast, watch, actors, Semaphore, timeouts, retries, spawn_blocking, sqlx PgPool, reqwest Client reuse, tracing, tests with start_paused and oneshot, Dockerfile. Fixes 'future cannot be sent between threads safely', E0373, Rc or MutexGuard held across await, 'Cannot start a runtime from within a runtime', 'Path segments must not start with :'. Ships std-only Rust scanners and a compiling axum 0.8 scaffold.
rust-trait-design-reviewer
Review and design Rust traits and generic APIs: generics vs impl Trait vs dyn Trait (static vs dynamic dispatch), dyn compatibility / object safety (generic methods, Self returns, where Self: Sized, error[E0038] not dyn compatible / cannot be made into an object), associated types vs generic parameters, blanket impls, coherence and orphan rule (E0117, E0119, E0210), newtype, extension, sealed and marker traits, supertraits and trait upcasting (1.86), async fn in traits (1.75) and the Send bound problem (trait_variant, async-trait), RPITIT, GATs, From/Into/TryFrom/AsRef/Borrow, std trait checklist (Debug, Clone, PartialEq, Hash, Default, Display, Error, Send/Sync, serde feature), #[must_use], #[non_exhaustive], semver hazards, Deref abuse, builders, typestate, PhantomData, Box<dyn Error + Send + Sync>, Fn traits, mockall.
rust-unsafe-block-auditor
Audit unsafe Rust for soundness: inventory every unsafe block, unsafe fn, unsafe impl/trait, extern block and unsafe attribute, check // SAFETY: comments and # Safety docs, and classify each as sound, needs-justification or likely UB, proposing safe alternatives first. Covers the five unsafe superpowers, aliasing (Stacked/Tree Borrows), invalid values, MaybeUninit vs mem::zeroed/uninitialized, transmute, slice::from_raw_parts, Vec::set_len/from_raw_parts, get_unchecked, CString::as_ptr dangling, unsafe impl Send/Sync, Pin projection, FFI (extern "C", repr(C), C-unwind, Box::into_raw/from_raw), strict provenance, static mut and &raw, edition 2024 (unsafe extern, #[unsafe(no_mangle)], unsafe_op_in_unsafe_fn, env::set_var), Miri, sanitizers, cargo-fuzz, loom, cargo-geiger and clippy safety lints.