Skip to content

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

@theemathas

Description

@theemathas
#![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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-specializationArea: Trait impl specializationC-bugCategory: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]`F-min_specialization`#![feature(min_specialization)]`T-typesRelevant to the types team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions