#79684 removed debug_assert! from intrinsic::copy[_nonoverlapping] to make it const:
|
// FIXME: Perform these checks only at run time |
|
/*if cfg!(debug_assertions) |
|
&& !(is_aligned_and_not_null(src) |
|
&& is_aligned_and_not_null(dst) |
|
&& is_nonoverlapping(src, dst, count)) |
|
// FIXME: Perform these checks only at run time |
|
/*if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) { |
We can't do these checks at compile-time, since
is_aligned_and_not_null, for example, involves ptr->int cast to check the alignment:
|
pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool { |
|
!ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0 |
|
} |
So, as the FIXME suggests, we should enable the checks only at runtime. Recently const_eval_select intrinsic was implemented, it allows for exactly this use case - running different code in CTFE and runtime.
cc @rust-lang/lang, @rust-lang/libs and @rust-lang/wg-const-eval (it seems like use of const_eval_select requires approval of all of the above teams)
@rustbot label +T-lang +T-libs +A-const-eval +A-const-fn
#79684 removed
debug_assert!fromintrinsic::copy[_nonoverlapping]to make itconst:rust/library/core/src/intrinsics.rs
Lines 2045 to 2049 in 5dab47d
rust/library/core/src/intrinsics.rs
Lines 2130 to 2131 in 5dab47d
We can't do these checks at compile-time, since
is_aligned_and_not_null, for example, involves ptr->int cast to check the alignment:rust/library/core/src/intrinsics.rs
Lines 1950 to 1952 in 5dab47d
So, as the FIXME suggests, we should enable the checks only at runtime. Recently
const_eval_selectintrinsic was implemented, it allows for exactly this use case - running different code in CTFE and runtime.cc @rust-lang/lang, @rust-lang/libs and @rust-lang/wg-const-eval (it seems like use of
const_eval_selectrequires approval of all of the above teams)@rustbot label +T-lang +T-libs +A-const-eval +A-const-fn