Open
Description
The following code does not compile but the 2 commented alternatives compile:
#![feature(never_type)]
#![feature(try_blocks)]
fn bar(_: Result<impl Into<!>, u32>) {
// fn bar(_: Result<impl Into<()>, u32>) {
// fn bar(_: Result<!, u32>) {
unimplemented!()
}
pub fn foo(x: Result<!, u32>) {
bar(try { x? });
}
The error is:
error[E0277]: the trait bound `!: From<()>` is not satisfied
--> src/lib.rs:11:9
|
11 | bar(try { x? });
| --- ^^^^^^--^^
| | | |
| | | this tail expression is of type `Result<(), u32>`
| | the trait `From<()>` is not implemented for `!`, which is required by `(): Into<!>`
| required by a bound introduced by this call
|
= note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #48950 <https://github.com/rust-lang/rust/issues/48950> for more information)
= help: did you intend to use the type `()` here instead?
= note: required for `()` to implement `Into<!>`
For some reason, rustc believes that the try block should return ()
instead of !
.
Meta
rustc --version --verbose
:
rustc 1.80.0-nightly (7d83a4c13 2024-05-06)
binary: rustc
commit-hash: 7d83a4c131ab9ae81a74c6fd825c827d74a2881d
commit-date: 2024-05-06
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4
Metadata
Metadata
Assignees
Labels
Category: This is a bug.`#![feature(never_type)]``#![feature(try_blocks)]`Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.