Skip to content

Commit afaa54a

Browse files
committed
Apply changes proposed in the review
1 parent 878ac10 commit afaa54a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

library/core/src/slice/raw.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,18 @@ const fn debug_check_data_len<T>(data: *const T, len: usize) {
141141
assert!(is_aligned_and_not_null(data), "attempt to create unaligned or null slice");
142142
}
143143

144-
const fn ctfe_check<T>(_data: *const T) {
145-
// It's impossible to check alignment in const fn.
146-
//
147-
// CTFE engine checks that the pointer is aligned and not null.
148-
}
144+
const fn noop<T>(_: *const T) {}
149145

150146
// SAFETY:
151-
// - `calling from_raw_parts[_mut]` with arguments that fail to fulfil checks made here is UB, so unless UB is already triggered this is noop
152-
// - CTFE makes the same checks as `rt_check`, so behavior change is not observable due to compilation error
147+
//
148+
// `rt_check` is just a debug assert to hint users that they are causing UB,
149+
// it is not required for safety (the safety must be guatanteed by
150+
// the `from_raw_parts[_mut]` caller).
151+
//
152+
// Since the checks are not required, we ignore them in CTFE as they can't
153+
// be done there (alignment does not make much sense there).
153154
unsafe {
154-
crate::intrinsics::const_eval_select((data,), ctfe_check, rt_check);
155+
crate::intrinsics::const_eval_select((data,), noop, rt_check);
155156
}
156157

157158
assert!(

0 commit comments

Comments
 (0)