Skip to content

Commit 7d91beb

Browse files
author
The Miri Cronjob Bot
committed
Merge from rustc
2 parents 5db6df4 + 1f27619 commit 7d91beb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+1820
-764
lines changed

alloc/src/alloc.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@ use core::ptr::{self, NonNull};
1010

1111
unsafe extern "Rust" {
1212
// These are the magic symbols to call the global allocator. rustc generates
13-
// them to call `__rg_alloc` etc. if there is a `#[global_allocator]` attribute
13+
// them to call the global allocator if there is a `#[global_allocator]` attribute
1414
// (the code expanding that attribute macro generates those functions), or to call
1515
// the default implementations in std (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
1616
// otherwise.
17-
// The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them
18-
// like `malloc`, `realloc`, and `free`, respectively.
1917
#[rustc_allocator]
2018
#[rustc_nounwind]
19+
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
2120
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
2221
#[rustc_deallocator]
2322
#[rustc_nounwind]
23+
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
2424
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
2525
#[rustc_reallocator]
2626
#[rustc_nounwind]
27+
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
2728
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
2829
#[rustc_allocator_zeroed]
2930
#[rustc_nounwind]
31+
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
3032
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
3133

34+
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
3235
static __rust_no_alloc_shim_is_unstable: u8;
3336
}
3437

@@ -357,6 +360,7 @@ unsafe extern "Rust" {
357360
// This is the magic symbol to call the global alloc error handler. rustc generates
358361
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
359362
// default implementations below (`__rdl_oom`) otherwise.
363+
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
360364
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
361365
}
362366

@@ -423,6 +427,7 @@ pub mod __alloc_error_handler {
423427
unsafe extern "Rust" {
424428
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
425429
// Its value depends on the -Zoom={panic,abort} compiler option.
430+
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
426431
static __rust_alloc_error_handler_should_panic: u8;
427432
}
428433

alloc/src/rc.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -1327,11 +1327,14 @@ impl<T: ?Sized> Rc<T> {
13271327
///
13281328
/// # Safety
13291329
///
1330-
/// The pointer must have been obtained through `Rc::into_raw`, the
1331-
/// associated `Rc` instance must be valid (i.e. the strong count must be at
1330+
/// The pointer must have been obtained through `Rc::into_raw` and must satisfy the
1331+
/// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
1332+
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
13321333
/// least 1) for the duration of this method, and `ptr` must point to a block of memory
13331334
/// allocated by the global allocator.
13341335
///
1336+
/// [from_raw_in]: Rc::from_raw_in
1337+
///
13351338
/// # Examples
13361339
///
13371340
/// ```
@@ -1360,12 +1363,15 @@ impl<T: ?Sized> Rc<T> {
13601363
///
13611364
/// # Safety
13621365
///
1363-
/// The pointer must have been obtained through `Rc::into_raw`, the
1364-
/// associated `Rc` instance must be valid (i.e. the strong count must be at
1366+
/// The pointer must have been obtained through `Rc::into_raw`and must satisfy the
1367+
/// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
1368+
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
13651369
/// least 1) when invoking this method, and `ptr` must point to a block of memory
13661370
/// allocated by the global allocator. This method can be used to release the final `Rc` and
13671371
/// backing storage, but **should not** be called after the final `Rc` has been released.
13681372
///
1373+
/// [from_raw_in]: Rc::from_raw_in
1374+
///
13691375
/// # Examples
13701376
///
13711377
/// ```
@@ -1623,10 +1629,13 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
16231629
///
16241630
/// # Safety
16251631
///
1626-
/// The pointer must have been obtained through `Rc::into_raw`, the
1627-
/// associated `Rc` instance must be valid (i.e. the strong count must be at
1632+
/// The pointer must have been obtained through `Rc::into_raw` and must satisfy the
1633+
/// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
1634+
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
16281635
/// least 1) for the duration of this method, and `ptr` must point to a block of memory
1629-
/// allocated by `alloc`
1636+
/// allocated by `alloc`.
1637+
///
1638+
/// [from_raw_in]: Rc::from_raw_in
16301639
///
16311640
/// # Examples
16321641
///
@@ -1665,11 +1674,14 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
16651674
///
16661675
/// # Safety
16671676
///
1668-
/// The pointer must have been obtained through `Rc::into_raw`, the
1669-
/// associated `Rc` instance must be valid (i.e. the strong count must be at
1677+
/// The pointer must have been obtained through `Rc::into_raw`and must satisfy the
1678+
/// same layout requirements specified in [`Rc::from_raw_in`][from_raw_in].
1679+
/// The associated `Rc` instance must be valid (i.e. the strong count must be at
16701680
/// least 1) when invoking this method, and `ptr` must point to a block of memory
1671-
/// allocated by `alloc`. This method can be used to release the final `Rc` and backing storage,
1672-
/// but **should not** be called after the final `Rc` has been released.
1681+
/// allocated by `alloc`. This method can be used to release the final `Rc` and
1682+
/// backing storage, but **should not** be called after the final `Rc` has been released.
1683+
///
1684+
/// [from_raw_in]: Rc::from_raw_in
16731685
///
16741686
/// # Examples
16751687
///

alloc/src/sync.rs

+44-12
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,29 @@ macro_rules! acquire {
8484
///
8585
/// Shared references in Rust disallow mutation by default, and `Arc` is no
8686
/// exception: you cannot generally obtain a mutable reference to something
87-
/// inside an `Arc`. If you need to mutate through an `Arc`, use
88-
/// [`Mutex`][mutex], [`RwLock`][rwlock], or one of the [`Atomic`][atomic]
89-
/// types.
87+
/// inside an `Arc`. If you do need to mutate through an `Arc`, you have several options:
88+
///
89+
/// 1. Use interior mutability with synchronization primitives like [`Mutex`][mutex],
90+
/// [`RwLock`][rwlock], or one of the [`Atomic`][atomic] types.
91+
///
92+
/// 2. Use clone-on-write semantics with [`Arc::make_mut`] which provides efficient mutation
93+
/// without requiring interior mutability. This approach clones the data only when
94+
/// needed (when there are multiple references) and can be more efficient when mutations
95+
/// are infrequent.
96+
///
97+
/// 3. Use [`Arc::get_mut`] when you know your `Arc` is not shared (has a reference count of 1),
98+
/// which provides direct mutable access to the inner value without any cloning.
99+
///
100+
/// ```
101+
/// use std::sync::Arc;
102+
///
103+
/// let mut data = Arc::new(vec![1, 2, 3]);
104+
///
105+
/// // This will clone the vector only if there are other references to it
106+
/// Arc::make_mut(&mut data).push(4);
107+
///
108+
/// assert_eq!(*data, vec![1, 2, 3, 4]);
109+
/// ```
90110
///
91111
/// **Note**: This type is only available on platforms that support atomic
92112
/// loads and stores of pointers, which includes all platforms that support
@@ -1453,11 +1473,14 @@ impl<T: ?Sized> Arc<T> {
14531473
///
14541474
/// # Safety
14551475
///
1456-
/// The pointer must have been obtained through `Arc::into_raw`, and the
1457-
/// associated `Arc` instance must be valid (i.e. the strong count must be at
1476+
/// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1477+
/// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1478+
/// The associated `Arc` instance must be valid (i.e. the strong count must be at
14581479
/// least 1) for the duration of this method, and `ptr` must point to a block of memory
14591480
/// allocated by the global allocator.
14601481
///
1482+
/// [from_raw_in]: Arc::from_raw_in
1483+
///
14611484
/// # Examples
14621485
///
14631486
/// ```
@@ -1488,13 +1511,16 @@ impl<T: ?Sized> Arc<T> {
14881511
///
14891512
/// # Safety
14901513
///
1491-
/// The pointer must have been obtained through `Arc::into_raw`, and the
1492-
/// associated `Arc` instance must be valid (i.e. the strong count must be at
1514+
/// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1515+
/// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1516+
/// The associated `Arc` instance must be valid (i.e. the strong count must be at
14931517
/// least 1) when invoking this method, and `ptr` must point to a block of memory
14941518
/// allocated by the global allocator. This method can be used to release the final
14951519
/// `Arc` and backing storage, but **should not** be called after the final `Arc` has been
14961520
/// released.
14971521
///
1522+
/// [from_raw_in]: Arc::from_raw_in
1523+
///
14981524
/// # Examples
14991525
///
15001526
/// ```
@@ -1806,11 +1832,14 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
18061832
///
18071833
/// # Safety
18081834
///
1809-
/// The pointer must have been obtained through `Arc::into_raw`, and the
1810-
/// associated `Arc` instance must be valid (i.e. the strong count must be at
1811-
/// least 1) for the duration of this method,, and `ptr` must point to a block of memory
1835+
/// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1836+
/// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1837+
/// The associated `Arc` instance must be valid (i.e. the strong count must be at
1838+
/// least 1) for the duration of this method, and `ptr` must point to a block of memory
18121839
/// allocated by `alloc`.
18131840
///
1841+
/// [from_raw_in]: Arc::from_raw_in
1842+
///
18141843
/// # Examples
18151844
///
18161845
/// ```
@@ -1850,13 +1879,16 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
18501879
///
18511880
/// # Safety
18521881
///
1853-
/// The pointer must have been obtained through `Arc::into_raw`, the
1854-
/// associated `Arc` instance must be valid (i.e. the strong count must be at
1882+
/// The pointer must have been obtained through `Arc::into_raw` and must satisfy the
1883+
/// same layout requirements specified in [`Arc::from_raw_in`][from_raw_in].
1884+
/// The associated `Arc` instance must be valid (i.e. the strong count must be at
18551885
/// least 1) when invoking this method, and `ptr` must point to a block of memory
18561886
/// allocated by `alloc`. This method can be used to release the final
18571887
/// `Arc` and backing storage, but **should not** be called after the final `Arc` has been
18581888
/// released.
18591889
///
1890+
/// [from_raw_in]: Arc::from_raw_in
1891+
///
18601892
/// # Examples
18611893
///
18621894
/// ```

alloc/src/vec/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,19 @@ impl<T, A: Allocator> Vec<T, A> {
12521252
/// vec.push(42);
12531253
/// assert!(vec.capacity() >= 10);
12541254
/// ```
1255+
///
1256+
/// A vector with zero-sized elements will always have a capacity of usize::MAX:
1257+
///
1258+
/// ```
1259+
/// #[derive(Clone)]
1260+
/// struct ZeroSized;
1261+
///
1262+
/// fn main() {
1263+
/// assert_eq!(std::mem::size_of::<ZeroSized>(), 0);
1264+
/// let v = vec![ZeroSized; 0];
1265+
/// assert_eq!(v.capacity(), usize::MAX);
1266+
/// }
1267+
/// ```
12551268
#[inline]
12561269
#[stable(feature = "rust1", since = "1.0.0")]
12571270
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]

core/src/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use crate::{fmt, hash, intrinsics};
109109
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
110110
// but we would likely want to indicate as such in documentation).
111111
#[stable(feature = "rust1", since = "1.0.0")]
112-
#[cfg_attr(not(test), rustc_diagnostic_item = "Any")]
112+
#[rustc_diagnostic_item = "Any"]
113113
pub trait Any: 'static {
114114
/// Gets the `TypeId` of `self`.
115115
///

core/src/array/ascii.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::ascii;
22

3-
#[cfg(not(test))]
43
impl<const N: usize> [u8; N] {
54
/// Converts this array of bytes into an array of ASCII characters,
65
/// or returns `None` if any of the characters is non-ASCII.

core/src/bool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl bool {
5656
/// ```
5757
#[doc(alias = "then_with")]
5858
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
59-
#[cfg_attr(not(test), rustc_diagnostic_item = "bool_then")]
59+
#[rustc_diagnostic_item = "bool_then"]
6060
#[inline]
6161
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
6262
if self { Some(f()) } else { None }

core/src/cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub use once::OnceCell;
304304
/// ```
305305
///
306306
/// See the [module-level documentation](self) for more.
307-
#[cfg_attr(not(test), rustc_diagnostic_item = "Cell")]
307+
#[rustc_diagnostic_item = "Cell"]
308308
#[stable(feature = "rust1", since = "1.0.0")]
309309
#[repr(transparent)]
310310
#[rustc_pub_transparent]
@@ -725,7 +725,7 @@ impl<T, const N: usize> Cell<[T; N]> {
725725
/// A mutable memory location with dynamically checked borrow rules
726726
///
727727
/// See the [module-level documentation](self) for more.
728-
#[cfg_attr(not(test), rustc_diagnostic_item = "RefCell")]
728+
#[rustc_diagnostic_item = "RefCell"]
729729
#[stable(feature = "rust1", since = "1.0.0")]
730730
pub struct RefCell<T: ?Sized> {
731731
borrow: Cell<BorrowFlag>,

core/src/char/methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ impl char {
11781178
#[must_use]
11791179
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
11801180
#[rustc_const_stable(feature = "const_char_is_ascii", since = "1.32.0")]
1181-
#[cfg_attr(not(test), rustc_diagnostic_item = "char_is_ascii")]
1181+
#[rustc_diagnostic_item = "char_is_ascii"]
11821182
#[inline]
11831183
pub const fn is_ascii(&self) -> bool {
11841184
*self as u32 <= 0x7F

0 commit comments

Comments
 (0)