Skip to content

Commit 76cbf00

Browse files
committed
Auto merge of #71151 - Dylan-DPC:rollup-6rt4h7b, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #70657 (Allow `try`-blocks in places where an open delim is expected) - #70947 (tighten CTFE safety net for accesses to globals) - #70949 (simplify `vec!` macro) - #71002 (fix target & runtool args order) - #71082 (ptr: introduce len() method on raw slices) - #71128 (Remove unused single_step flag) - #71133 (Tighten time complexity on the doc of sort_by_key) - #71135 (Update books) Failed merges: r? @ghost
2 parents d12f030 + db3addb commit 76cbf00

File tree

25 files changed

+222
-50
lines changed

25 files changed

+222
-50
lines changed

src/doc/embedded-book

src/liballoc/macros.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ macro_rules! vec {
4242
($elem:expr; $n:expr) => (
4343
$crate::vec::from_elem($elem, $n)
4444
);
45-
($($x:expr),*) => (
46-
<[_]>::into_vec(box [$($x),*])
45+
($($x:expr),+ $(,)?) => (
46+
<[_]>::into_vec(box [$($x),+])
4747
);
48-
($($x:expr,)*) => ($crate::vec![$($x),*])
4948
}
5049

5150
// HACK(japaric): with cfg(test) the inherent `[T]::into_vec` method, which is

src/liballoc/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<T> [T] {
254254

255255
/// Sorts the slice with a key extraction function.
256256
///
257-
/// This sort is stable (i.e., does not reorder equal elements) and `O(m n log(m n))`
257+
/// This sort is stable (i.e., does not reorder equal elements) and `O(m n log n)`
258258
/// worst-case, where the key function is `O(m)`.
259259
///
260260
/// For expensive key functions (e.g. functions that are not simple property accesses or

src/libcore/ptr/const_ptr.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,34 @@ impl<T: ?Sized> *const T {
706706
}
707707
}
708708

709+
#[cfg(not(bootstrap))]
710+
#[lang = "const_slice_ptr"]
711+
impl<T> *const [T] {
712+
/// Returns the length of a raw slice.
713+
///
714+
/// The returned value is the number of **elements**, not the number of bytes.
715+
///
716+
/// This function is safe, even when the raw slice cannot be cast to a slice
717+
/// reference because the pointer is null or unaligned.
718+
///
719+
/// # Examples
720+
///
721+
/// ```rust
722+
/// #![feature(slice_ptr_len)]
723+
///
724+
/// use std::ptr;
725+
///
726+
/// let slice: *const [i8] = ptr::slice_from_raw_parts(ptr::null(), 3);
727+
/// assert_eq!(slice.len(), 3);
728+
/// ```
729+
#[inline]
730+
#[unstable(feature = "slice_ptr_len", issue = "71146")]
731+
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
732+
pub const fn len(self) -> usize {
733+
unsafe { Repr { rust: self }.raw }.len
734+
}
735+
}
736+
709737
// Equality for pointers
710738
#[stable(feature = "rust1", since = "1.0.0")]
711739
impl<T: ?Sized> PartialEq for *const T {

src/libcore/ptr/mut_ptr.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,34 @@ impl<T: ?Sized> *mut T {
894894
}
895895
}
896896

897+
#[cfg(not(bootstrap))]
898+
#[lang = "mut_slice_ptr"]
899+
impl<T> *mut [T] {
900+
/// Returns the length of a raw slice.
901+
///
902+
/// The returned value is the number of **elements**, not the number of bytes.
903+
///
904+
/// This function is safe, even when the raw slice cannot be cast to a slice
905+
/// reference because the pointer is null or unaligned.
906+
///
907+
/// # Examples
908+
///
909+
/// ```rust
910+
/// #![feature(slice_ptr_len)]
911+
///
912+
/// use std::ptr;
913+
///
914+
/// let slice: *mut [i8] = ptr::slice_from_raw_parts_mut(ptr::null_mut(), 3);
915+
/// assert_eq!(slice.len(), 3);
916+
/// ```
917+
#[inline]
918+
#[unstable(feature = "slice_ptr_len", issue = "71146")]
919+
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
920+
pub const fn len(self) -> usize {
921+
unsafe { Repr { rust_mut: self }.raw }.len
922+
}
923+
}
924+
897925
// Equality for pointers
898926
#[stable(feature = "rust1", since = "1.0.0")]
899927
impl<T: ?Sized> PartialEq for *mut T {

src/libcore/slice/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ impl<T> [T] {
16971697
/// elements.
16981698
///
16991699
/// This sort is unstable (i.e., may reorder equal elements), in-place
1700-
/// (i.e., does not allocate), and `O(m n log(m n))` worst-case, where the key function is
1700+
/// (i.e., does not allocate), and `O(m n log n)` worst-case, where the key function is
17011701
/// `O(m)`.
17021702
///
17031703
/// # Current implementation

0 commit comments

Comments
 (0)