X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Fcore%2Fsrc%2Fslice%2Fmod.rs;h=ec28cdd1ba0d9cf166ccf869ce70d77b94c6a1c0;hb=d32238532138485c80db4f2cd596372bce214e00;hp=56d3ba0ff254d0d2be9378f97f42264a621c349d;hpb=6327e46d8c21d54734eb5eb44604be487a8e6bdb;p=rust.git diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 56d3ba0ff25..ec28cdd1ba0 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -81,6 +81,9 @@ #[unstable(feature = "slice_range", issue = "76393")] pub use index::range; +#[unstable(feature = "inherent_ascii_escape", issue = "77174")] +pub use ascii::EscapeAscii; + #[lang = "slice"] #[cfg(not(test))] impl [T] { @@ -99,23 +102,14 @@ impl [T] { // SAFETY: const sound because we transmute out the length field as a usize (which it must be) #[rustc_allow_const_fn_unstable(const_fn_union)] pub const fn len(&self) -> usize { - #[cfg(bootstrap)] - { - // SAFETY: this is safe because `&[T]` and `FatPtr` have the same layout. - // Only `std` can make this guarantee. - unsafe { crate::ptr::Repr { rust: self }.raw.len } - } - #[cfg(not(bootstrap))] - { - // FIXME: Replace with `crate::ptr::metadata(self)` when that is const-stable. - // As of this writing this causes a "Const-stable functions can only call other - // const-stable functions" error. - - // SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T - // and PtrComponents have the same memory layouts. Only std can make this - // guarantee. - unsafe { crate::ptr::PtrRepr { const_ptr: self }.components.metadata } - } + // FIXME: Replace with `crate::ptr::metadata(self)` when that is const-stable. + // As of this writing this causes a "Const-stable functions can only call other + // const-stable functions" error. + + // SAFETY: Accessing the value from the `PtrRepr` union is safe since *const T + // and PtrComponents have the same memory layouts. Only std can make this + // guarantee. + unsafe { crate::ptr::PtrRepr { const_ptr: self }.components.metadata } } /// Returns `true` if the slice has a length of 0. @@ -2212,6 +2206,8 @@ pub fn binary_search_by<'a, F>(&'a self, mut f: F) -> Result } else if cmp == Greater { right = mid; } else { + // SAFETY: same as the `get_unchecked` above + unsafe { crate::intrinsics::assume(mid < self.len()) }; return Ok(mid); } @@ -2260,8 +2256,7 @@ pub fn binary_search_by<'a, F>(&'a self, mut f: F) -> Result // in crate `alloc`, and as such doesn't exists yet when building `core`. // links to downstream crate: #74481. Since primitives are only documented in // libstd (#73423), this never leads to broken links in practice. - #[cfg_attr(not(bootstrap), allow(rustdoc::broken_intra_doc_links))] - #[cfg_attr(bootstrap, allow(broken_intra_doc_links))] + #[allow(rustdoc::broken_intra_doc_links)] #[stable(feature = "slice_binary_search_by_key", since = "1.10.0")] #[inline] pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result