Skip to content

compile fail when HRTB + const trait #139134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
loynoir opened this issue Mar 30, 2025 · 1 comment
Closed

compile fail when HRTB + const trait #139134

loynoir opened this issue Mar 30, 2025 · 1 comment
Labels
F-const_trait_impl `#![feature(const_trait_impl)]`

Comments

@loynoir
Copy link

loynoir commented Mar 30, 2025

I tried this code:

pub mod reproduce {
    #[const_trait]
    pub trait ConstFrom<T>: Sized {
        #[must_use]
        fn const_from(value: T) -> Self;
    }

    #[const_trait]
    pub trait ConstAddAssign<Rhs = Self> {
        fn const_add_assign(&mut self, rhs: Rhs);
    }

    pub fn incr42<T>(mut x: T)
    where
        T: const ConstFrom<u8> + for<'a> ConstAddAssign<&'a T>,
    {
        let delta = T::const_from(42u8);

        x.const_add_assign(&delta)
    }

    // fail to compile
    pub const fn const_incr42<T>(mut x: T)
    where
        T: ~const ConstFrom<u8> + for<'a> ~const ConstAddAssign<&'a T>,
    {
        let delta = T::const_from(42u8);

        x.const_add_assign(&delta)
    }
}

I expected to see this happen: compile OK when HRTB + const trait

Instead, this happened: compile fail when HRTB + const trait

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (3ea711f17 2025-03-09)
binary: rustc
commit-hash: 3ea711f17e3946ac3f4df11691584e2c56b4b0cf
commit-date: 2025-03-09
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
Backtrace

<backtrace>

Related

Prev

#67792 (comment)

@loynoir loynoir added the C-bug Category: This is a bug. label Mar 30, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 30, 2025
@fmease
Copy link
Member

fmease commented Mar 30, 2025

Thanks for opening an issue. However, as I also wrote in #67792 (comment), for now you just need to add T: ~const Destruct: Playground.

So this works as intended atm. In the future, whether, when & where you need to write ~cons Destruct may change. See rust-lang/rfcs#3762.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2025
@fmease fmease added F-const_trait_impl `#![feature(const_trait_impl)]` and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-const_trait_impl `#![feature(const_trait_impl)]`
Projects
None yet
Development

No branches or pull requests

3 participants