Open
Description
I tried this code:
fn foo() -> Result<(), u8> {
Ok(())
}
fn test() -> Result<(), u8> {
let f: fn() -> _ = foo as _;
f()?;
Ok(())
}
I expected to see this happen:
Type inference on f
should work correctly.
Instead, this happened:
When switching to 2024 edition something odd is happening and inference results in confusing compilation error:
error[E0271]: type mismatch resolving `<Result<(), u8> as Try>::Output == !`
--> src/lib.rs:7:5
|
7 | f()?;
| ^^^^ expected `!`, found `()`
|
= note: expected type `!`
found unit type `()`
The same code works fine on 2021 edition and I don't understand why 2024 breaks.
Replacing -> _
with explicit -> Result<(), u8>
helps, but it is too verbose and hurts readability.
Meta
rustc --version --verbose
:
1.86.0-nightly
(2025-01-21 ed43cbcb882e7c06870a)