rust.ignored_result
Correctness
Medium
Detects Result values that are ignored without explicit handling.
Why It Matters
Section titled “Why It Matters”Ignoring Results hides real errors:
- Silent failures — Operations fail without any indication
- Data loss — Writes fail but code continues
- Inconsistent state — Partial operations leave broken state
- Debugging nightmare — Failures manifest far from their origin
Rust’s #[must_use] exists to catch this, but Unfault finds patterns the compiler misses.
Example
Section titled “Example”// ❌ Beforefn process() { fs::write("output.txt", data); // Result ignored! database.execute(query); // Did it succeed? channel.send(message); // What if it failed?}// ✅ Afterfn process() -> Result<(), Error> { fs::write("output.txt", data)?; database.execute(query)?; channel.send(message)?; Ok(())}What Unfault Detects
Section titled “What Unfault Detects”- Result-returning functions whose return value is discarded
let _ = result;patterns (explicit ignore but still risky)- Missing
?propagation
Auto-Fix
Section titled “Auto-Fix”Unfault adds ? operator to propagate errors.
Explicit Ignore Patterns
Section titled “Explicit Ignore Patterns”// When you truly don't care (document why)let _ = optional_cleanup(); // Best effort, we're shutting down
// Or assert it's infallibledebug_assert!(result.is_ok());
// For fire-and-forget loggingif let Err(e) = log_metric(data) { eprintln!("Failed to log metric: {}", e); // Continue - metrics aren't critical}Must Use Attribute
Section titled “Must Use Attribute”// Library authors should mark fallible functions#[must_use = "this `Result` may be an `Err` variant denoting failure"]pub fn send_message(&self, msg: Message) -> Result<(), Error> { // ...}