Skip to content

Commit cc5846f

Browse files
author
The Miri Cronjob Bot
committed
Merge ref '425a9c0a0e36' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 425a9c0 Filtered ref: 7e955d5a6c676a099595bdfaec0705d3703e7a3c This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 65f9cb5 + 85cbfac commit cc5846f

File tree

24 files changed

+243
-143
lines changed

24 files changed

+243
-143
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

alloc/src/boxed.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
16721672
#[cfg(not(no_global_oom_handling))]
16731673
#[stable(feature = "rust1", since = "1.0.0")]
16741674
impl<T: Default> Default for Box<T> {
1675-
/// Creates a `Box<T>`, with the `Default` value for T.
1675+
/// Creates a `Box<T>`, with the `Default` value for `T`.
16761676
#[inline]
16771677
fn default() -> Self {
16781678
let mut x: Box<mem::MaybeUninit<T>> = Box::new_uninit();
@@ -1695,6 +1695,7 @@ impl<T: Default> Default for Box<T> {
16951695
#[cfg(not(no_global_oom_handling))]
16961696
#[stable(feature = "rust1", since = "1.0.0")]
16971697
impl<T> Default for Box<[T]> {
1698+
/// Creates an empty `[T]` inside a `Box`.
16981699
#[inline]
16991700
fn default() -> Self {
17001701
let ptr: Unique<[T]> = Unique::<[T; 0]>::dangling();
@@ -1716,6 +1717,19 @@ impl Default for Box<str> {
17161717
}
17171718
}
17181719

1720+
#[cfg(not(no_global_oom_handling))]
1721+
#[stable(feature = "pin_default_impls", since = "CURRENT_RUSTC_VERSION")]
1722+
impl<T> Default for Pin<Box<T>>
1723+
where
1724+
T: ?Sized,
1725+
Box<T>: Default,
1726+
{
1727+
#[inline]
1728+
fn default() -> Self {
1729+
Box::into_pin(Box::<T>::default())
1730+
}
1731+
}
1732+
17191733
#[cfg(not(no_global_oom_handling))]
17201734
#[stable(feature = "rust1", since = "1.0.0")]
17211735
impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {

alloc/src/rc.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ impl<T: Default> Default for Rc<T> {
23572357
/// assert_eq!(*x, 0);
23582358
/// ```
23592359
#[inline]
2360-
fn default() -> Rc<T> {
2360+
fn default() -> Self {
23612361
unsafe {
23622362
Self::from_inner(
23632363
Box::leak(Box::write(
@@ -2373,7 +2373,7 @@ impl<T: Default> Default for Rc<T> {
23732373
#[cfg(not(no_global_oom_handling))]
23742374
#[stable(feature = "more_rc_default_impls", since = "1.80.0")]
23752375
impl Default for Rc<str> {
2376-
/// Creates an empty str inside an Rc
2376+
/// Creates an empty `str` inside an `Rc`.
23772377
///
23782378
/// This may or may not share an allocation with other Rcs on the same thread.
23792379
#[inline]
@@ -2387,7 +2387,7 @@ impl Default for Rc<str> {
23872387
#[cfg(not(no_global_oom_handling))]
23882388
#[stable(feature = "more_rc_default_impls", since = "1.80.0")]
23892389
impl<T> Default for Rc<[T]> {
2390-
/// Creates an empty `[T]` inside an Rc
2390+
/// Creates an empty `[T]` inside an `Rc`.
23912391
///
23922392
/// This may or may not share an allocation with other Rcs on the same thread.
23932393
#[inline]
@@ -2397,6 +2397,19 @@ impl<T> Default for Rc<[T]> {
23972397
}
23982398
}
23992399

2400+
#[cfg(not(no_global_oom_handling))]
2401+
#[stable(feature = "pin_default_impls", since = "CURRENT_RUSTC_VERSION")]
2402+
impl<T> Default for Pin<Rc<T>>
2403+
where
2404+
T: ?Sized,
2405+
Rc<T>: Default,
2406+
{
2407+
#[inline]
2408+
fn default() -> Self {
2409+
unsafe { Pin::new_unchecked(Rc::<T>::default()) }
2410+
}
2411+
}
2412+
24002413
#[stable(feature = "rust1", since = "1.0.0")]
24012414
trait RcEqIdent<T: ?Sized + PartialEq, A: Allocator> {
24022415
fn eq(&self, other: &Rc<T, A>) -> bool;

alloc/src/sync.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,6 +3654,19 @@ impl<T> Default for Arc<[T]> {
36543654
}
36553655
}
36563656

3657+
#[cfg(not(no_global_oom_handling))]
3658+
#[stable(feature = "pin_default_impls", since = "CURRENT_RUSTC_VERSION")]
3659+
impl<T> Default for Pin<Arc<T>>
3660+
where
3661+
T: ?Sized,
3662+
Arc<T>: Default,
3663+
{
3664+
#[inline]
3665+
fn default() -> Self {
3666+
unsafe { Pin::new_unchecked(Arc::<T>::default()) }
3667+
}
3668+
}
3669+
36573670
#[stable(feature = "rust1", since = "1.0.0")]
36583671
impl<T: ?Sized + Hash, A: Allocator> Hash for Arc<T, A> {
36593672
fn hash<H: Hasher>(&self, state: &mut H) {

core/src/any.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,9 @@ impl fmt::Debug for TypeId {
835835
///
836836
/// The returned string must not be considered to be a unique identifier of a
837837
/// type as multiple types may map to the same type name. Similarly, there is no
838-
/// guarantee that all parts of a type will appear in the returned string: for
839-
/// example, lifetime specifiers are currently not included. In addition, the
840-
/// output may change between versions of the compiler.
838+
/// guarantee that all parts of a type will appear in the returned string. In
839+
/// addition, the output may change between versions of the compiler. For
840+
/// example, lifetime specifiers were omitted in some earlier versions.
841841
///
842842
/// The current implementation uses the same infrastructure as compiler
843843
/// diagnostics and debuginfo, but this is not guaranteed.

core/src/cell.rs

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,14 +698,14 @@ impl<T, const N: usize> Cell<[T; N]> {
698698
/// # Examples
699699
///
700700
/// ```
701-
/// #![feature(as_array_of_cells)]
702701
/// use std::cell::Cell;
703702
///
704703
/// let mut array: [i32; 3] = [1, 2, 3];
705704
/// let cell_array: &Cell<[i32; 3]> = Cell::from_mut(&mut array);
706705
/// let array_cell: &[Cell<i32>; 3] = cell_array.as_array_of_cells();
707706
/// ```
708-
#[unstable(feature = "as_array_of_cells", issue = "88248")]
707+
#[stable(feature = "as_array_of_cells", since = "CURRENT_RUSTC_VERSION")]
708+
#[rustc_const_stable(feature = "as_array_of_cells", since = "CURRENT_RUSTC_VERSION")]
709709
pub const fn as_array_of_cells(&self) -> &[Cell<T>; N] {
710710
// SAFETY: `Cell<T>` has the same memory layout as `T`.
711711
unsafe { &*(self as *const Cell<[T; N]> as *const [Cell<T>; N]) }
@@ -1573,6 +1573,47 @@ impl<'b, T: ?Sized> Ref<'b, T> {
15731573
}
15741574
}
15751575

1576+
/// Tries to makes a new `Ref` for a component of the borrowed data.
1577+
/// On failure, the original guard is returned alongside with the error
1578+
/// returned by the closure.
1579+
///
1580+
/// The `RefCell` is already immutably borrowed, so this cannot fail.
1581+
///
1582+
/// This is an associated function that needs to be used as
1583+
/// `Ref::try_map(...)`. A method would interfere with methods of the same
1584+
/// name on the contents of a `RefCell` used through `Deref`.
1585+
///
1586+
/// # Examples
1587+
///
1588+
/// ```
1589+
/// #![feature(refcell_try_map)]
1590+
/// use std::cell::{RefCell, Ref};
1591+
/// use std::str::{from_utf8, Utf8Error};
1592+
///
1593+
/// let c = RefCell::new(vec![0xF0, 0x9F, 0xA6 ,0x80]);
1594+
/// let b1: Ref<'_, Vec<u8>> = c.borrow();
1595+
/// let b2: Result<Ref<'_, str>, _> = Ref::try_map(b1, |v| from_utf8(v));
1596+
/// assert_eq!(&*b2.unwrap(), "🦀");
1597+
///
1598+
/// let c = RefCell::new(vec![0xF0, 0x9F, 0xA6]);
1599+
/// let b1: Ref<'_, Vec<u8>> = c.borrow();
1600+
/// let b2: Result<_, (Ref<'_, Vec<u8>>, Utf8Error)> = Ref::try_map(b1, |v| from_utf8(v));
1601+
/// let (b3, e) = b2.unwrap_err();
1602+
/// assert_eq!(*b3, vec![0xF0, 0x9F, 0xA6]);
1603+
/// assert_eq!(e.valid_up_to(), 0);
1604+
/// ```
1605+
#[unstable(feature = "refcell_try_map", issue = "143801")]
1606+
#[inline]
1607+
pub fn try_map<U: ?Sized, E>(
1608+
orig: Ref<'b, T>,
1609+
f: impl FnOnce(&T) -> Result<&U, E>,
1610+
) -> Result<Ref<'b, U>, (Self, E)> {
1611+
match f(&*orig) {
1612+
Ok(value) => Ok(Ref { value: NonNull::from(value), borrow: orig.borrow }),
1613+
Err(e) => Err((orig, e)),
1614+
}
1615+
}
1616+
15761617
/// Splits a `Ref` into multiple `Ref`s for different components of the
15771618
/// borrowed data.
15781619
///
@@ -1734,6 +1775,58 @@ impl<'b, T: ?Sized> RefMut<'b, T> {
17341775
}
17351776
}
17361777

1778+
/// Tries to makes a new `RefMut` for a component of the borrowed data.
1779+
/// On failure, the original guard is returned alongside with the error
1780+
/// returned by the closure.
1781+
///
1782+
/// The `RefCell` is already mutably borrowed, so this cannot fail.
1783+
///
1784+
/// This is an associated function that needs to be used as
1785+
/// `RefMut::try_map(...)`. A method would interfere with methods of the same
1786+
/// name on the contents of a `RefCell` used through `Deref`.
1787+
///
1788+
/// # Examples
1789+
///
1790+
/// ```
1791+
/// #![feature(refcell_try_map)]
1792+
/// use std::cell::{RefCell, RefMut};
1793+
/// use std::str::{from_utf8_mut, Utf8Error};
1794+
///
1795+
/// let c = RefCell::new(vec![0x68, 0x65, 0x6C, 0x6C, 0x6F]);
1796+
/// {
1797+
/// let b1: RefMut<'_, Vec<u8>> = c.borrow_mut();
1798+
/// let b2: Result<RefMut<'_, str>, _> = RefMut::try_map(b1, |v| from_utf8_mut(v));
1799+
/// let mut b2 = b2.unwrap();
1800+
/// assert_eq!(&*b2, "hello");
1801+
/// b2.make_ascii_uppercase();
1802+
/// }
1803+
/// assert_eq!(*c.borrow(), "HELLO".as_bytes());
1804+
///
1805+
/// let c = RefCell::new(vec![0xFF]);
1806+
/// let b1: RefMut<'_, Vec<u8>> = c.borrow_mut();
1807+
/// let b2: Result<_, (RefMut<'_, Vec<u8>>, Utf8Error)> = RefMut::try_map(b1, |v| from_utf8_mut(v));
1808+
/// let (b3, e) = b2.unwrap_err();
1809+
/// assert_eq!(*b3, vec![0xFF]);
1810+
/// assert_eq!(e.valid_up_to(), 0);
1811+
/// ```
1812+
#[unstable(feature = "refcell_try_map", issue = "143801")]
1813+
#[inline]
1814+
pub fn try_map<U: ?Sized, E>(
1815+
mut orig: RefMut<'b, T>,
1816+
f: impl FnOnce(&mut T) -> Result<&mut U, E>,
1817+
) -> Result<RefMut<'b, U>, (Self, E)> {
1818+
// SAFETY: function holds onto an exclusive reference for the duration
1819+
// of its call through `orig`, and the pointer is only de-referenced
1820+
// inside of the function call never allowing the exclusive reference to
1821+
// escape.
1822+
match f(&mut *orig) {
1823+
Ok(value) => {
1824+
Ok(RefMut { value: NonNull::from(value), borrow: orig.borrow, marker: PhantomData })
1825+
}
1826+
Err(e) => Err((orig, e)),
1827+
}
1828+
}
1829+
17371830
/// Splits a `RefMut` into multiple `RefMut`s for different components of the
17381831
/// borrowed data.
17391832
///

core/src/intrinsics/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,44 @@ pub const unsafe fn copysignf64(x: f64, y: f64) -> f64;
31573157
#[rustc_intrinsic]
31583158
pub const unsafe fn copysignf128(x: f128, y: f128) -> f128;
31593159

3160+
/// Generates the LLVM body for the automatic differentiation of `f` using Enzyme,
3161+
/// with `df` as the derivative function and `args` as its arguments.
3162+
///
3163+
/// Used internally as the body of `df` when expanding the `#[autodiff_forward]`
3164+
/// and `#[autodiff_reverse]` attribute macros.
3165+
///
3166+
/// Type Parameters:
3167+
/// - `F`: The original function to differentiate. Must be a function item.
3168+
/// - `G`: The derivative function. Must be a function item.
3169+
/// - `T`: A tuple of arguments passed to `df`.
3170+
/// - `R`: The return type of the derivative function.
3171+
///
3172+
/// This shows where the `autodiff` intrinsic is used during macro expansion:
3173+
///
3174+
/// ```rust,ignore (macro example)
3175+
/// #[autodiff_forward(df1, Dual, Const, Dual)]
3176+
/// pub fn f1(x: &[f64], y: f64) -> f64 {
3177+
/// unimplemented!()
3178+
/// }
3179+
/// ```
3180+
///
3181+
/// expands to:
3182+
///
3183+
/// ```rust,ignore (macro example)
3184+
/// #[rustc_autodiff]
3185+
/// #[inline(never)]
3186+
/// pub fn f1(x: &[f64], y: f64) -> f64 {
3187+
/// ::core::panicking::panic("not implemented")
3188+
/// }
3189+
/// #[rustc_autodiff(Forward, 1, Dual, Const, Dual)]
3190+
/// pub fn df1(x: &[f64], bx_0: &[f64], y: f64) -> (f64, f64) {
3191+
/// ::core::intrinsics::autodiff(f1::<>, df1::<>, (x, bx_0, y))
3192+
/// }
3193+
/// ```
3194+
#[rustc_nounwind]
3195+
#[rustc_intrinsic]
3196+
pub const fn autodiff<F, G, T: crate::marker::Tuple, R>(f: F, df: G, args: T) -> R;
3197+
31603198
/// Inform Miri that a given pointer definitely has a certain alignment.
31613199
#[cfg(miri)]
31623200
#[rustc_allow_const_fn_unstable(const_eval_select)]

core/src/iter/adapters/chain.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ impl<A, B> Chain<A, B> {
4545
/// # Examples
4646
///
4747
/// ```
48-
/// #![feature(iter_chain)]
49-
///
5048
/// use std::iter::chain;
5149
///
5250
/// let a = [1, 2, 3];
@@ -62,7 +60,7 @@ impl<A, B> Chain<A, B> {
6260
/// assert_eq!(iter.next(), Some(6));
6361
/// assert_eq!(iter.next(), None);
6462
/// ```
65-
#[unstable(feature = "iter_chain", reason = "recently added", issue = "125964")]
63+
#[stable(feature = "iter_chain", since = "CURRENT_RUSTC_VERSION")]
6664
pub fn chain<A, B>(a: A, b: B) -> Chain<A::IntoIter, B::IntoIter>
6765
where
6866
A: IntoIterator,

core/src/iter/adapters/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod zip;
3232
pub use self::array_chunks::ArrayChunks;
3333
#[unstable(feature = "std_internals", issue = "none")]
3434
pub use self::by_ref_sized::ByRefSized;
35-
#[unstable(feature = "iter_chain", reason = "recently added", issue = "125964")]
35+
#[stable(feature = "iter_chain", since = "CURRENT_RUSTC_VERSION")]
3636
pub use self::chain::chain;
3737
#[stable(feature = "iter_cloned", since = "1.1.0")]
3838
pub use self::cloned::Cloned;

core/src/iter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ pub use self::adapters::StepBy;
404404
pub use self::adapters::TrustedRandomAccess;
405405
#[unstable(feature = "trusted_random_access", issue = "none")]
406406
pub use self::adapters::TrustedRandomAccessNoCoerce;
407-
#[unstable(feature = "iter_chain", reason = "recently added", issue = "125964")]
407+
#[stable(feature = "iter_chain", since = "CURRENT_RUSTC_VERSION")]
408408
pub use self::adapters::chain;
409409
pub(crate) use self::adapters::try_process;
410410
#[stable(feature = "iter_zip", since = "1.59.0")]

0 commit comments

Comments
 (0)