Skip to content

Re-enable debug checks in copy[_nonoverlapping] #90012

Closed

Description

#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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation (MIR interpretation)A-const-fnArea: const fn foo(..) {..}. Pure functions which can be applied at compile time.T-langRelevant to the language team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions