rust-lang / rust-lang/rust

min_specialization with const traits can call non-const function in consteval

Open
#148,200 8 comments 0 reactions 1 assignee View on GitHub

@fee1-dead is already working on this.

Since Jul 22, 2026.

A-const-eval A-specialization C-bug F-const_trait_impl F-min_specialization PG-const-traits T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Edit: See the comment below for a simpler version.

#![feature(min_specialization, const_trait_impl)]

struct Dummy;

const trait One {
    fn one();
}
impl One for Dummy {
    fn one() {
        println!("wut");
    }
}

const trait Two {
    fn two();
}
impl<T: One, U> const Two for (T, U) {
    default fn two() {
        unreachable!();
    }
}
impl<T: [const] One> const Two for (T, i32) {
    fn two() {
        T::one();
    }
}

const trait Three {
    fn three();
}
impl<T: One, U> const Three for (T, U) {
    fn three() {
        <(T, U)>::two();
    }
}

const A: () = {
    <(Dummy, i32)>::three();
};

fn main() {}
error[E0080]: calling non-const function `<Dummy as One>::one`
  --> src/main.rs:38:5
   |
38 |     <(Dummy, i32)>::three();
   |     ^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `A` failed inside this call
   |
note: inside `<(Dummy, i32) as Three>::three`
  --> src/main.rs:33:9
   |
33 |         <(T, U)>::two();
   |         ^^^^^^^^^^^^^^^
note: inside `<(Dummy, i32) as Two>::two`
  --> src/main.rs:24:9
   |
24 |         T::one();
   |         ^^^^^^^^ the failure occurred here

For more information about this error, try `rustc --explain E0080`.

This code manages to get through const checking without any errors, and only produces an error while "executing" consteval and running into the non-const function. This seems incorrect. The compiler is supposed to disallow calling non-const functions in consteval before actually running consteval.

Meta

Reproducible on the playground with version 1.93.0-nightly (2025-10-27 adaa838976ff99a4f066)

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.