Const functions calling trait function of its generic arguments

Is it possible to call a trait function of a generic argument in a const function?

trait T{
    const X:Self;
    fn f()->Self;
}
const fn g<S:T>()->S{
    T::X  // OK
}
const fn h<S:T>()->S{
    T::f()  //  error[E0015] cannot call non-const fn `<S as T>::f` in constant functions
}

After trying out myself, the current nightly rustc (1.71.0) accepts the following program:

#![feature(const_trait_impl)]

#[const_trait]
trait T {
    const X: Self;
    fn f() -> Self;
}

const fn g<S: T>() -> S {
    T::X  // OK
}

const fn h<S: T>() -> S where S: ~const T {
    T::f()
}

fn main() {}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.