Skip to content

Commit 0997c96

Browse files
committed
Auto merge of #101017 - JohnTitor:rollup-73f2fhb, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #99064 (distinguish the method and associated function diagnostic information) - #99920 (Custom allocator support in `rustc_serialize`) - #100034 ( Elaborate all box dereferences in `ElaborateBoxDerefs`) - #100076 (make slice::{split_at,split_at_unchecked} const functions) - #100604 (Remove unstable Result::into_ok_or_err) - #100933 (Reduce code size of `assert_matches_failed`) - #100978 (Handle `Err` in `ast::LitKind::to_token_lit`.) - #101010 (rustdoc: remove unused CSS for `.multi-column`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fd2ef63 + 8f66ef9 commit 0997c96

File tree

6 files changed

+16
-50
lines changed

6 files changed

+16
-50
lines changed

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
#![feature(maybe_uninit_uninit_array)]
150150
#![feature(ptr_metadata)]
151151
#![feature(slice_ptr_get)]
152+
#![feature(slice_split_at_unchecked)]
152153
#![feature(str_internals)]
153154
#![feature(utf16_extra)]
154155
#![feature(utf16_extra_const)]

core/src/panicking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
190190
right: &str,
191191
args: Option<fmt::Arguments<'_>>,
192192
) -> ! {
193-
// Use the Display implementation to display the pattern.
193+
// The pattern is a string so it can be displayed directly.
194194
struct Pattern<'a>(&'a str);
195195
impl fmt::Debug for Pattern<'_> {
196196
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
197-
fmt::Display::fmt(self.0, f)
197+
f.write_str(self.0)
198198
}
199199
}
200200
assert_failed_inner(AssertKind::Match, &left, &Pattern(right), args);

core/src/result.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,40 +1776,6 @@ impl<T, E> Result<Result<T, E>, E> {
17761776
}
17771777
}
17781778

1779-
impl<T> Result<T, T> {
1780-
/// Returns the [`Ok`] value if `self` is `Ok`, and the [`Err`] value if
1781-
/// `self` is `Err`.
1782-
///
1783-
/// In other words, this function returns the value (the `T`) of a
1784-
/// `Result<T, T>`, regardless of whether or not that result is `Ok` or
1785-
/// `Err`.
1786-
///
1787-
/// This can be useful in conjunction with APIs such as
1788-
/// [`Atomic*::compare_exchange`], or [`slice::binary_search`], but only in
1789-
/// cases where you don't care if the result was `Ok` or not.
1790-
///
1791-
/// [`Atomic*::compare_exchange`]: crate::sync::atomic::AtomicBool::compare_exchange
1792-
///
1793-
/// # Examples
1794-
///
1795-
/// ```
1796-
/// #![feature(result_into_ok_or_err)]
1797-
/// let ok: Result<u32, u32> = Ok(3);
1798-
/// let err: Result<u32, u32> = Err(4);
1799-
///
1800-
/// assert_eq!(ok.into_ok_or_err(), 3);
1801-
/// assert_eq!(err.into_ok_or_err(), 4);
1802-
/// ```
1803-
#[inline]
1804-
#[unstable(feature = "result_into_ok_or_err", reason = "newly added", issue = "82223")]
1805-
pub const fn into_ok_or_err(self) -> T {
1806-
match self {
1807-
Ok(v) => v,
1808-
Err(v) => v,
1809-
}
1810-
}
1811-
}
1812-
18131779
// This is a separate function to reduce the code size of the methods
18141780
#[cfg(not(feature = "panic_immediate_abort"))]
18151781
#[inline(never)]

core/src/slice/mod.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,13 +1541,14 @@ impl<T> [T] {
15411541
/// }
15421542
/// ```
15431543
#[stable(feature = "rust1", since = "1.0.0")]
1544+
#[rustc_const_unstable(feature = "const_slice_split_at_not_mut", issue = "none")]
15441545
#[inline]
15451546
#[track_caller]
15461547
#[must_use]
1547-
pub fn split_at(&self, mid: usize) -> (&[T], &[T]) {
1548+
pub const fn split_at(&self, mid: usize) -> (&[T], &[T]) {
15481549
assert!(mid <= self.len());
15491550
// SAFETY: `[ptr; mid]` and `[mid; len]` are inside `self`, which
1550-
// fulfills the requirements of `from_raw_parts_mut`.
1551+
// fulfills the requirements of `split_at_unchecked`.
15511552
unsafe { self.split_at_unchecked(mid) }
15521553
}
15531554

@@ -1626,11 +1627,19 @@ impl<T> [T] {
16261627
/// }
16271628
/// ```
16281629
#[unstable(feature = "slice_split_at_unchecked", reason = "new API", issue = "76014")]
1630+
#[rustc_const_unstable(feature = "slice_split_at_unchecked", issue = "76014")]
16291631
#[inline]
16301632
#[must_use]
1631-
pub unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) {
1633+
pub const unsafe fn split_at_unchecked(&self, mid: usize) -> (&[T], &[T]) {
1634+
// HACK: the const function `from_raw_parts` is used to make this
1635+
// function const; previously the implementation used
1636+
// `(self.get_unchecked(..mid), self.get_unchecked(mid..))`
1637+
1638+
let len = self.len();
1639+
let ptr = self.as_ptr();
1640+
16321641
// SAFETY: Caller has to check that `0 <= mid <= self.len()`
1633-
unsafe { (self.get_unchecked(..mid), self.get_unchecked(mid..)) }
1642+
unsafe { (from_raw_parts(ptr, mid), from_raw_parts(ptr.add(mid), len - mid)) }
16341643
}
16351644

16361645
/// Divides one mutable slice into two at an index, without doing bounds checking.

core/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
#![feature(const_pin)]
7676
#![feature(never_type)]
7777
#![feature(unwrap_infallible)]
78-
#![feature(result_into_ok_or_err)]
7978
#![feature(pointer_byte_offsets)]
8079
#![feature(portable_simd)]
8180
#![feature(ptr_metadata)]

core/tests/result.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,6 @@ fn test_unwrap_or() {
9595
assert_eq!(ok_err.unwrap_or(50), 50);
9696
}
9797

98-
#[test]
99-
fn test_ok_or_err() {
100-
let ok: Result<isize, isize> = Ok(100);
101-
let err: Result<isize, isize> = Err(200);
102-
103-
assert_eq!(ok.into_ok_or_err(), 100);
104-
assert_eq!(err.into_ok_or_err(), 200);
105-
}
106-
10798
#[test]
10899
fn test_unwrap_or_else() {
109100
fn handler(msg: &'static str) -> isize {

0 commit comments

Comments
 (0)