Skip to content

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

Open
@RalfJung

Description

@RalfJung

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 rust-lang/miri#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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions