Skip to content

Commit 216fe3d

Browse files
committed
Merge from rustc
2 parents e7c06e8 + 5c88806 commit 216fe3d

File tree

17 files changed

+139
-71
lines changed

17 files changed

+139
-71
lines changed

alloc/src/alloc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ pub mod __alloc_error_handler {
429429
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
430430
// Its value depends on the -Zoom={panic,abort} compiler option.
431431
#[rustc_std_internal_symbol]
432-
static __rust_alloc_error_handler_should_panic: u8;
432+
fn __rust_alloc_error_handler_should_panic_v2() -> u8;
433433
}
434434

435-
if unsafe { __rust_alloc_error_handler_should_panic != 0 } {
435+
if unsafe { __rust_alloc_error_handler_should_panic_v2() != 0 } {
436436
panic!("memory allocation of {size} bytes failed")
437437
} else {
438438
core::panicking::panic_nounwind_fmt(

alloc/src/boxed.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ use core::error::{self, Error};
191191
use core::fmt;
192192
use core::future::Future;
193193
use core::hash::{Hash, Hasher};
194-
use core::marker::{PointerLike, Tuple, Unsize};
194+
use core::marker::{Tuple, Unsize};
195195
use core::mem::{self, SizedTypeProperties};
196196
use core::ops::{
197197
AsyncFn, AsyncFnMut, AsyncFnOnce, CoerceUnsized, Coroutine, CoroutineState, Deref, DerefMut,
@@ -2132,6 +2132,3 @@ impl<E: Error> Error for Box<E> {
21322132
Error::provide(&**self, request);
21332133
}
21342134
}
2135-
2136-
#[unstable(feature = "pointer_like_trait", issue = "none")]
2137-
impl<T> PointerLike for Box<T> {}

alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
#![feature(panic_internals)]
135135
#![feature(pattern)]
136136
#![feature(pin_coerce_unsized_trait)]
137-
#![feature(pointer_like_trait)]
138137
#![feature(ptr_alignment_type)]
139138
#![feature(ptr_internals)]
140139
#![feature(ptr_metadata)]

core/src/bool.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,71 @@ impl bool {
6161
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
6262
if self { Some(f()) } else { None }
6363
}
64+
65+
/// Returns `Ok(())` if the `bool` is [`true`](../std/keyword.true.html),
66+
/// or `Err(err)` otherwise.
67+
///
68+
/// Arguments passed to `ok_or` are eagerly evaluated; if you are
69+
/// passing the result of a function call, it is recommended to use
70+
/// [`ok_or_else`], which is lazily evaluated.
71+
///
72+
/// [`ok_or_else`]: bool::ok_or_else
73+
///
74+
/// # Examples
75+
///
76+
/// ```
77+
/// #![feature(bool_to_result)]
78+
///
79+
/// assert_eq!(false.ok_or(0), Err(0));
80+
/// assert_eq!(true.ok_or(0), Ok(()));
81+
/// ```
82+
///
83+
/// ```
84+
/// #![feature(bool_to_result)]
85+
///
86+
/// let mut a = 0;
87+
/// let mut function_with_side_effects = || { a += 1; };
88+
///
89+
/// assert!(true.ok_or(function_with_side_effects()).is_ok());
90+
/// assert!(false.ok_or(function_with_side_effects()).is_err());
91+
///
92+
/// // `a` is incremented twice because the value passed to `ok_or` is
93+
/// // evaluated eagerly.
94+
/// assert_eq!(a, 2);
95+
/// ```
96+
#[unstable(feature = "bool_to_result", issue = "142748")]
97+
#[inline]
98+
pub fn ok_or<E>(self, err: E) -> Result<(), E> {
99+
if self { Ok(()) } else { Err(err) }
100+
}
101+
102+
/// Returns `Ok(())` if the `bool` is [`true`](../std/keyword.true.html),
103+
/// or `Err(f())` otherwise.
104+
///
105+
/// # Examples
106+
///
107+
/// ```
108+
/// #![feature(bool_to_result)]
109+
///
110+
/// assert_eq!(false.ok_or_else(|| 0), Err(0));
111+
/// assert_eq!(true.ok_or_else(|| 0), Ok(()));
112+
/// ```
113+
///
114+
/// ```
115+
/// #![feature(bool_to_result)]
116+
///
117+
/// let mut a = 0;
118+
///
119+
/// assert!(true.ok_or_else(|| { a += 1; }).is_ok());
120+
/// assert!(false.ok_or_else(|| { a += 1; }).is_err());
121+
///
122+
/// // `a` is incremented once because the closure is evaluated lazily by
123+
/// // `ok_or_else`.
124+
/// assert_eq!(a, 1);
125+
/// ```
126+
#[unstable(feature = "bool_to_result", issue = "142748")]
127+
#[inline]
128+
pub fn ok_or_else<E, F: FnOnce() -> E>(self, f: F) -> Result<(), E> {
129+
if self { Ok(()) } else { Err(f()) }
130+
}
64131
}

core/src/cell.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252

253253
use crate::cmp::Ordering;
254254
use crate::fmt::{self, Debug, Display};
255-
use crate::marker::{PhantomData, PointerLike, Unsize};
255+
use crate::marker::{PhantomData, Unsize};
256256
use crate::mem;
257257
use crate::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn};
258258
use crate::panic::const_panic;
@@ -669,9 +669,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
669669
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
670670
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Cell<U>> for Cell<T> {}
671671

672-
#[unstable(feature = "pointer_like_trait", issue = "none")]
673-
impl<T: PointerLike> PointerLike for Cell<T> {}
674-
675672
impl<T> Cell<[T]> {
676673
/// Returns a `&[Cell<T>]` from a `&Cell<[T]>`
677674
///
@@ -2361,9 +2358,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
23612358
#[unstable(feature = "dispatch_from_dyn", issue = "none")]
23622359
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafeCell<U>> for UnsafeCell<T> {}
23632360

2364-
#[unstable(feature = "pointer_like_trait", issue = "none")]
2365-
impl<T: PointerLike> PointerLike for UnsafeCell<T> {}
2366-
23672361
/// [`UnsafeCell`], but [`Sync`].
23682362
///
23692363
/// This is just an `UnsafeCell`, except it implements `Sync`
@@ -2470,9 +2464,6 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<SyncUnsafeCell<U>> for SyncUnsafeCell
24702464
//#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
24712465
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<SyncUnsafeCell<U>> for SyncUnsafeCell<T> {}
24722466

2473-
#[unstable(feature = "pointer_like_trait", issue = "none")]
2474-
impl<T: PointerLike> PointerLike for SyncUnsafeCell<T> {}
2475-
24762467
#[allow(unused)]
24772468
fn assert_coerce_unsized(
24782469
a: UnsafeCell<&i32>,

core/src/cmp.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,6 @@ pub trait PartialOrd<Rhs: PointeeSized = Self>: PartialEq<Rhs> + PointeeSized {
14491449
/// check `==` and `<` separately to do rather than needing to calculate
14501450
/// (then optimize out) the three-way `Ordering` result.
14511451
#[inline]
1452-
#[must_use]
14531452
// Added to improve the behaviour of tuples; not necessarily stabilization-track.
14541453
#[unstable(feature = "partial_ord_chaining_methods", issue = "none")]
14551454
#[doc(hidden)]
@@ -1459,7 +1458,6 @@ pub trait PartialOrd<Rhs: PointeeSized = Self>: PartialEq<Rhs> + PointeeSized {
14591458

14601459
/// Same as `__chaining_lt`, but for `<=` instead of `<`.
14611460
#[inline]
1462-
#[must_use]
14631461
#[unstable(feature = "partial_ord_chaining_methods", issue = "none")]
14641462
#[doc(hidden)]
14651463
fn __chaining_le(&self, other: &Rhs) -> ControlFlow<bool> {
@@ -1468,7 +1466,6 @@ pub trait PartialOrd<Rhs: PointeeSized = Self>: PartialEq<Rhs> + PointeeSized {
14681466

14691467
/// Same as `__chaining_lt`, but for `>` instead of `<`.
14701468
#[inline]
1471-
#[must_use]
14721469
#[unstable(feature = "partial_ord_chaining_methods", issue = "none")]
14731470
#[doc(hidden)]
14741471
fn __chaining_gt(&self, other: &Rhs) -> ControlFlow<bool> {
@@ -1477,7 +1474,6 @@ pub trait PartialOrd<Rhs: PointeeSized = Self>: PartialEq<Rhs> + PointeeSized {
14771474

14781475
/// Same as `__chaining_lt`, but for `>=` instead of `<`.
14791476
#[inline]
1480-
#[must_use]
14811477
#[unstable(feature = "partial_ord_chaining_methods", issue = "none")]
14821478
#[doc(hidden)]
14831479
fn __chaining_ge(&self, other: &Rhs) -> ControlFlow<bool> {

core/src/marker.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,37 +1066,6 @@ pub trait Destruct {}
10661066
#[rustc_do_not_implement_via_object]
10671067
pub trait Tuple {}
10681068

1069-
/// A marker for pointer-like types.
1070-
///
1071-
/// This trait can only be implemented for types that are certain to have
1072-
/// the same size and alignment as a [`usize`] or [`*const ()`](pointer).
1073-
/// To ensure this, there are special requirements on implementations
1074-
/// of `PointerLike` (other than the already-provided implementations
1075-
/// for built-in types):
1076-
///
1077-
/// * The type must have `#[repr(transparent)]`.
1078-
/// * The type’s sole non-zero-sized field must itself implement `PointerLike`.
1079-
#[unstable(feature = "pointer_like_trait", issue = "none")]
1080-
#[lang = "pointer_like"]
1081-
#[diagnostic::on_unimplemented(
1082-
message = "`{Self}` needs to have the same ABI as a pointer",
1083-
label = "`{Self}` needs to be a pointer-like type"
1084-
)]
1085-
#[rustc_do_not_implement_via_object]
1086-
pub trait PointerLike {}
1087-
1088-
marker_impls! {
1089-
#[unstable(feature = "pointer_like_trait", issue = "none")]
1090-
PointerLike for
1091-
isize,
1092-
usize,
1093-
{T} &T,
1094-
{T} &mut T,
1095-
{T} *const T,
1096-
{T} *mut T,
1097-
{T: PointerLike} crate::pin::Pin<T>,
1098-
}
1099-
11001069
/// A marker for types which can be used as types of `const` generic parameters.
11011070
///
11021071
/// These types must have a proper equivalence relation (`Eq`) and it must be automatically

core/src/num/f64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ impl f64 {
943943
/// This returns NaN when *either* argument is NaN, as opposed to
944944
/// [`f64::max`] which only returns NaN when *both* arguments are NaN.
945945
///
946-
/// ```ignore-arm-unknown-linux-gnueabihf,ignore-i586 (see https://github.com/rust-lang/rust/issues/141087)
946+
/// ```
947947
/// #![feature(float_minimum_maximum)]
948948
/// let x = 1.0_f64;
949949
/// let y = 2.0_f64;
@@ -970,7 +970,7 @@ impl f64 {
970970
/// This returns NaN when *either* argument is NaN, as opposed to
971971
/// [`f64::min`] which only returns NaN when *both* arguments are NaN.
972972
///
973-
/// ```ignore-arm-unknown-linux-gnueabihf,ignore-i586 (see https://github.com/rust-lang/rust/issues/141087)
973+
/// ```
974974
/// #![feature(float_minimum_maximum)]
975975
/// let x = 1.0_f64;
976976
/// let y = 2.0_f64;

core/src/num/uint_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,7 @@ macro_rules! uint_impl {
25722572
if size_of::<Self>() == 1 {
25732573
// Trick LLVM into generating the psadbw instruction when SSE2
25742574
// is available and this function is autovectorized for u8's.
2575-
(self as i32).wrapping_sub(other as i32).abs() as Self
2575+
(self as i32).wrapping_sub(other as i32).unsigned_abs() as Self
25762576
} else {
25772577
if self < other {
25782578
other - self

core/src/pin/unsafe_pinned.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::cell::UnsafeCell;
2-
use crate::marker::{PointerLike, Unpin};
2+
use crate::marker::Unpin;
33
use crate::ops::{CoerceUnsized, DispatchFromDyn};
44
use crate::pin::Pin;
55
use crate::{fmt, ptr};
@@ -178,8 +178,4 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafePinned<U>> for UnsafePinned<T>
178178
// #[unstable(feature = "unsafe_pinned", issue = "125735")]
179179
impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<UnsafePinned<U>> for UnsafePinned<T> {}
180180

181-
#[unstable(feature = "pointer_like_trait", issue = "none")]
182-
// #[unstable(feature = "unsafe_pinned", issue = "125735")]
183-
impl<T: PointerLike> PointerLike for UnsafePinned<T> {}
184-
185181
// FIXME(unsafe_pinned): impl PinCoerceUnsized for UnsafePinned<T>?

0 commit comments

Comments
 (0)