rust-lang / rust-lang/rust

Order-dependent LUB coercion under next solver involving TAIT & `NeverToAny`

Open
#149,078 12 comments 0 reactions 1 assignee View on GitHub

@jackh726 is already working on this.

Since Jan 23, 2026.

A-coercions A-impl-trait C-bug F-type_alias_impl_trait I-lang-radar T-types WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Found while playing around with https://godbolt.org/z/sYY6WM8eb which was provided in https://github.com/rust-lang/rfcs/pull/3444#issuecomment-3550026818. I have no idea what's going on.

The following code compiles under -Znext-solver (I doubt it should but I've got no clue):

#![feature(type_alias_impl_trait)]

enum Enum {
    Variant,
}

fn main() {
    type Opaque = impl ?Sized;
    let _: Enum = match true {
        false => (loop {}) as Opaque,
        true => Opaque::Variant,
    };
}

However, if you swap the two match arms it'll no longer compile:

#![feature(type_alias_impl_trait)]

enum Enum {
    Variant,
}

fn main() {
    type Opaque = impl ?Sized;
    let _: Enum = match true {
        true => Opaque::Variant,
        false => (loop {}) as Opaque,
    };
}
error[E0599]: no associated item named `Variant` found for type `_` in the current scope
  --> coerce.rs:10:25
   |
10 |         true => Opaque::Variant,
   |                         ^^^^^^^ associated item not found in `_`

Note that under the old solver neither version compiles. Both yield:

error[E0599]: no associated item named `Variant` found for opaque type `Opaque` in the current scope
  --> coerce.rs:11:25
   |
11 |         true => Opaque::Variant,
   |                         ^^^^^^^ associated item not found in `Opaque`

error[E0620]: cast to unsized type: `!` as `Opaque`
  --> coerce.rs:10:18
   |
10 |         false => (loop {}) as Opaque,
   |                  ^^^^^^^^^^^^^^^^^^^
   |
help: consider using a box or reference as appropriate
  --> coerce.rs:10:18
   |
10 |         false => (loop {}) as Opaque,
   |                  ^^^^^^^^^
Meta

rustc -Vv:

rustc 1.93.0-nightly (3d461af2a 2025-11-18)
binary: rustc
commit-hash: 3d461af2a23456a2676aadb13b4253c87bdfe28d
commit-date: 2025-11-18
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.