Skip to content

rust.ignored_result

Correctness Medium

Detects Result values that are ignored without explicit handling.

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.

// ❌ Before
fn process() {
fs::write("output.txt", data); // Result ignored!
database.execute(query); // Did it succeed?
channel.send(message); // What if it failed?
}
// ✅ After
fn process() -> Result<(), Error> {
fs::write("output.txt", data)?;
database.execute(query)?;
channel.send(message)?;
Ok(())
}
  • Result-returning functions whose return value is discarded
  • let _ = result; patterns (explicit ignore but still risky)
  • Missing ? propagation

Unfault adds ? operator to propagate errors.

// When you truly don't care (document why)
let _ = optional_cleanup(); // Best effort, we're shutting down
// Or assert it's infallible
debug_assert!(result.is_ok());
// For fire-and-forget logging
if let Err(e) = log_metric(data) {
eprintln!("Failed to log metric: {}", e);
// Continue - metrics aren't critical
}
// 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> {
// ...
}