]> git.lizzy.rs Git - rust.git/blobdiff - library/core/src/slice/raw.rs
Auto merge of #90306 - kornelski:slicecloneasset, r=joshtriplett
[rust.git] / library / core / src / slice / raw.rs
index 6653c998fa2ba5f913278493c071f8395d162f09..81bb16d54015e9551266e41068e1bb6ec63cd5a5 100644 (file)
@@ -83,7 +83,7 @@
 /// [`NonNull::dangling()`]: ptr::NonNull::dangling
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "none")]
+#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
 pub const unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
     debug_check_data_len(data, len);
 
 /// [`NonNull::dangling()`]: ptr::NonNull::dangling
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "none")]
+#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
 pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] {
     debug_check_data_len(data as _, len);
 
 
 // In debug builds checks that `data` pointer is aligned and non-null and that slice with given `len` would cover less than half the address space
 #[cfg(all(not(bootstrap), debug_assertions))]
-#[unstable(feature = "const_slice_from_raw_parts", issue = "none")]
-#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "none")]
+#[unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
+#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
 const fn debug_check_data_len<T>(data: *const T, len: usize) {
     fn rt_check<T>(data: *const T) {
         use crate::intrinsics::is_aligned_and_not_null;
@@ -141,17 +141,18 @@ fn rt_check<T>(data: *const T) {
         assert!(is_aligned_and_not_null(data), "attempt to create unaligned or null slice");
     }
 
-    const fn ctfe_check<T>(_data: *const T) {
-        // It's impossible to check alignment in const fn.
-        //
-        // CTFE engine checks that the pointer is aligned and not null.
-    }
+    const fn noop<T>(_: *const T) {}
 
     // SAFETY:
-    // - `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
-    // - CTFE makes the same checks as `rt_check`, so behavior change is not observable due to compilation error
+    //
+    // `rt_check` is just a debug assert to hint users that they are causing UB,
+    // it is not required for safety (the safety must be guatanteed by
+    // the `from_raw_parts[_mut]` caller).
+    //
+    // Since the checks are not required, we ignore them in CTFE as they can't
+    // be done there (alignment does not make much sense there).
     unsafe {
-        crate::intrinsics::const_eval_select((data,), ctfe_check, rt_check);
+        crate::intrinsics::const_eval_select((data,), noop, rt_check);
     }
 
     assert!(