rust-lang / rust-lang/rust

Diagnostic on missing "?" suggests to ignore the error entirely, which can be problematic

Open
#130,262 2 comments 0 reactions 1 assignee View on GitHub

@roife is already working on this.

Since Sep 13, 2024.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn fallible() -> Result<i32, ()> {
    Ok(42)
}

pub fn caller() -> Result<(), ()> {
    fallible();
    Ok(())
}
Current output
warning: unused `Result` that must be used
 --> src/lib.rs:6:5
  |
6 |     fallible();
  |     ^^^^^^^^^^
  |
  = note: this `Result` may be an `Err` variant, which should be handled
  = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
  |
6 |     let _ = fallible();
  |     +++++++
Desired output
Rust should suggest to add the missing `?`, not to ignore the error entirely.
Rationale and extra context

See https://github.com/rust-lang/miri/issues/3855 for an example where ignoring the error with let _ = can lead to critical bugs.

Other cases

No response

Rust Version
1.81.0
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.