Closed as not planned
Description
I tried this code:
use core::convert::Infallible;
pub trait UnwrapInfallible<T> {
#[must_use]
fn unwrap_infallible(self) -> T;
}
impl<T> UnwrapInfallible<T> for Result<T, Infallible> {
#[inline]
fn unwrap_infallible(self) -> T {
match self {
Ok(value) => value,
}
}
}
fn main() {
let result: Result<(), Infallible> = Ok(());
let result2: Result<u32, Infallible> = Ok(1);
result.unwrap_infallible();
let _u = result2.unwrap_infallible();
}
I expected to see this happen: no warnings
Instead, this happened: warning from unused ()
from result.unwrap_infallible()
:
warning: unused return value of
UnwrapInfallible::unwrap_infallible that must be used
Meta
rustc --version --verbose
:
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-pc-windows-msvc
release: 1.86.0
LLVM version: 19.1.7
It's also in latest nightly: 2025-5-29