TAIT: `item does not constrain` after diverging expression
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the minimal type_alias_impl_trait example from the issue with the reported nightly compiler, then compare its behavior with -Z next-solver. Trace the handling of the unconditional diverging expression and #[define_opaque]; the issue is resolved when the example compiles without the erroneous item does not constrain error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100