Open
Description
I tried this code:
#![feature(type_alias_impl_trait)]
pub type Tait = impl Iterator<Item = u64>;
#[define_opaque(Tait)]
pub fn f() -> Tait {
loop {}
IntoIterator::into_iter([])
}
I expected to see this happen: This code should compile.
Instead, this happened: An error is generated.
warning: unreachable expression
--> <source>:8:5
|
7 | loop {}
| ------- any code following this expression is unreachable
8 | IntoIterator::into_iter([])
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable expression
|
= note: `#[warn(unreachable_code)]` on by default
error: item does not constrain `Tait::{opaque#0}`
--> <source>:6:8
|
6 | pub fn f() -> Tait {
| ^
|
= note: consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]`
note: this opaque type is supposed to be constrained
--> <source>:3:17
|
3 | pub type Tait = impl Iterator<Item = u64>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error; 1 warning emitted
Compiler returned: 1
This happens when the function’s body contains an an unconditional diverging expression (such as loop {}
or panic!()
). If the diverging expression is wrapped in if true { ... }
, the code compiles fine.
Godbolt link: https://godbolt.org/z/T65dMvG6o
Note that the same code compiles fine with -Z next-solver
: https://godbolt.org/z/nsqT36bWE
Meta
rustc --version --verbose
:
rustc 1.89.0-nightly (6f6971078 2025-05-28)
binary: rustc
commit-hash: 6f69710780d579b180ab38da4c1384d630f7bd31
commit-date: 2025-05-28
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Backtrace
<backtrace>