Skip to content

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

@fmease

Description

@fmease

Found while playing around with https://godbolt.org/z/sYY6WM8eb which was provided in rust-lang/rfcs#3444 (comment). 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coercionsArea: implicit and explicit `expr as Type` coercionsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.T-typesRelevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions