rust-lang / rust-lang/rust

TAIT regression and slowdown with the next solver

Open
#151,988 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-type_alias_impl_trait WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(type_alias_impl_trait)]
// #![recursion_limit = "8"]
type MultiUse<'a> = impl Sized;

struct Invar<'a>(*mut &'a ());

fn mk_invar<'a>() -> Invar<'a> { todo!() }

fn use_sized(f: impl FnOnce(MultiUse<'_>)) {}

#[define_opaque(MultiUse)]
fn use_multi<'a>() -> MultiUse<'a> {
    use_sized(|x| {});
    mk_invar()
}

I expected to see this happen: codes compiles quickly as with the old solver.

Instead, this happened: this code fails to compile and it takes a long time to fail depending on recursion_limit.
Output:

error: higher-ranked subtype error
  --> code.rs:13:5
   |
13 |     use_sized(|x| {});
Meta

rustc --version --verbose:

rustc 1.95.0-dev
binary: rustc
host: x86_64-unknown-linux-gnu
release: 1.95.0-dev
LLVM version: 21.1.8
Analysis

During typecking the expr use_sized(|x| {}), there's a ?0t as FnOnce<(free alias, )>::Output=() projection goal which keeps registering opaque types with new regions to the storage. By doing that it triggers re-evaluation.
Since the projection goal is ambiguous, it gets evaluated again.

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.

Research direction

Start by compiling the provided minimal reproduction with the reported rustc version and compare its behavior with the old solver. Trace type checking for use_sized(|x| {}), focusing on the ambiguous projection goal and repeated opaque-type registration described in the analysis. Done means the example compiles quickly without the higher-ranked subtype error or recursion-limit-dependent slowdown.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.