rust-lang / rust-lang/rust

Followup work from making `ValTree` recurse through `ty::Const`

Open
#150,624 1 comment 0 reactions 1 assignee View on GitHub

@BoxyUwU is already working on this.

Since Jan 2, 2026.

A-const-generics E-needs-design F-min_generic_const_args T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

After #149114 ValTree's Branches variant stores a list of ty::Const instead of a list of ValTrees. See the PR description and associated zulip thread (#project-const-generics > Valtrees that can contain generic params) for a motivation for this.

This has left us with two problems:

  1. The name Value is kinda confusing :) These are in some sense not full values. It may be desirable to rename ConstKind::Value, ty::Value, ty::ValTree and ty::ValTreeKind to something different now that they don't represent full values.
  2. There are now a bunch of extra Ty in a fully evaluate ValTree. This is likely bad for performance. Though more importantly it means that when CTFE evaluates something to a ValTree it has to pick types for all the nested nodes in a ValTree. This is effectively impossible for CTFE to do correctly as it doesn't have lifetime information so we wind up with a bunch of erased lifetimes entering the type system.

The second point can be observed by looking at debug logs for this code example:

#![feature(adt_const_params, unsized_const_params)]
#![expect(incomplete_features)]
#![crate_type = "lib"]

struct Foo<'a> {
    r: &'a u32,
}

fn bar<const N: Foo<'static>>() { }

fn qux() {
    bar::<{ Foo { r: &1 } }>();
}

0ms DEBUG rustc_trait_selection::traits ct=UnevaluatedConst { def: DefId(0:9 ~ foo[cae9]::qux::{constant#0}), args: [] }
0ms DEBUG rustc_trait_selection::traits return=Ok(ValTree(Branch([ValTree(Leaf(0x00000001): &'{erased} u32)]): Foo::<'static>))

Assigning myself as I'm partially through fixing this second point.

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.