Make slice->str conversion and related functions const
by WaffleLapkin · Pull Request #90607 · rust-lang/rust (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const_eval_select
inalign_offset
itself clearly changes it's return value depending on whatever it's called at runtime or compile time.Sadly, it seems that we don't want to allow this, right? :(
Actually, the docs specifically state
If it is not possible to align the pointer, the implementation returns usize::MAX. It is permissible for the implementation to always return usize::MAX. Only your algorithm’s performance can depend on getting a usable offset here, not its correctness.
There are no guarantees whatsoever that offsetting the pointer will not overflow or go beyond the allocation that the pointer points into. It is up to the caller to ensure that the returned offset is correct in all terms other than alignment.
The only reason align_offset
even exists is because I wanted to enable miri to do such trickery back when it wasn't able to do ptr2int conversions.
So, we can definitely make align_offset
behave this way in const fn, as long as we have a tracking issue for the const stabilization that specifically raises this concern before we bake it into a stabilized function.