Skip to content

TAIT: item does not constrain after diverging expression #141779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
narpfel opened this issue May 30, 2025 · 0 comments
Open

TAIT: item does not constrain after diverging expression #141779

narpfel opened this issue May 30, 2025 · 0 comments
Labels
A-type-system Area: Type system C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@narpfel
Copy link
Contributor

narpfel commented May 30, 2025

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>

@narpfel narpfel added the C-bug Category: This is a bug. label May 30, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2025
@Noratrieb Noratrieb added A-type-system Area: Type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants