Closed as not planned
Description
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