Skip to content

Commit f7ba6db

Browse files
committed
rust: alloc: import 1.58.0
Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 83a4f81 commit f7ba6db

File tree

11 files changed

+138
-124
lines changed

11 files changed

+138
-124
lines changed

rust/alloc/alloc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub use std::alloc::Global;
8383
/// }
8484
/// ```
8585
#[stable(feature = "global_alloc", since = "1.28.0")]
86+
#[must_use = "losing the pointer will leak memory"]
8687
#[inline]
8788
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
8889
unsafe { __rust_alloc(layout.size(), layout.align()) }
@@ -119,6 +120,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
119120
///
120121
/// See [`GlobalAlloc::realloc`].
121122
#[stable(feature = "global_alloc", since = "1.28.0")]
123+
#[must_use = "losing the pointer will leak memory"]
122124
#[inline]
123125
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
124126
unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
@@ -152,6 +154,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
152154
/// }
153155
/// ```
154156
#[stable(feature = "global_alloc", since = "1.28.0")]
157+
#[must_use = "losing the pointer will leak memory"]
155158
#[inline]
156159
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
157160
unsafe { __rust_alloc_zeroed(layout.size(), layout.align()) }

rust/alloc/boxed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ use crate::vec::Vec;
171171
#[lang = "owned_box"]
172172
#[fundamental]
173173
#[stable(feature = "rust1", since = "1.0.0")]
174+
// The declaration of the `Box` struct must be kept in sync with the
175+
// `alloc::alloc::box_free` function or ICEs will happen. See the comment
176+
// on `box_free` for more details.
174177
pub struct Box<
175178
T: ?Sized,
176179
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

rust/alloc/collections/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub struct TryReserveError {
6767
impl TryReserveError {
6868
/// Details about the allocation that caused the error
6969
#[inline]
70+
#[must_use]
7071
#[unstable(
7172
feature = "try_reserve_kind",
7273
reason = "Uncertain how much info should be exposed",

rust/alloc/fmt.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
//! format!("The number is {}", 1); // => "The number is 1"
2020
//! format!("{:?}", (3, 4)); // => "(3, 4)"
2121
//! format!("{value}", value=4); // => "4"
22+
//! let people = "Rustaceans";
23+
//! format!("Hello {people}!"); // => "Hello Rustaceans!"
2224
//! format!("{} {}", 1, 2); // => "1 2"
2325
//! format!("{:04}", 42); // => "0042" with leading zeros
2426
//! format!("{:#?}", (100, 200)); // => "(
@@ -82,6 +84,19 @@
8284
//! format!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b"
8385
//! ```
8486
//!
87+
//! If a named parameter does not appear in the argument list, `format!` will
88+
//! reference a variable with that name in the current scope.
89+
//!
90+
//! ```
91+
//! let argument = 2 + 2;
92+
//! format!("{argument}"); // => "4"
93+
//!
94+
//! fn make_string(a: u32, b: &str) -> String {
95+
//! format!("{b} {a}")
96+
//! }
97+
//! make_string(927, "label"); // => "label 927"
98+
//! ```
99+
//!
85100
//! It is not valid to put positional parameters (those without names) after
86101
//! arguments that have names. Like with positional parameters, it is not
87102
//! valid to provide named parameters that are unused by the format string.
@@ -100,6 +115,8 @@
100115
//! println!("Hello {:1$}!", "x", 5);
101116
//! println!("Hello {1:0$}!", 5, "x");
102117
//! println!("Hello {:width$}!", "x", width = 5);
118+
//! let width = 5;
119+
//! println!("Hello {:width$}!", "x");
103120
//! ```
104121
//!
105122
//! This is a parameter for the "minimum width" that the format should take up.
@@ -574,6 +591,7 @@ use crate::string;
574591
/// [`format_args!`]: core::format_args
575592
/// [`format!`]: crate::format
576593
#[cfg(not(no_global_oom_handling))]
594+
#[must_use]
577595
#[stable(feature = "rust1", since = "1.0.0")]
578596
pub fn format(args: Arguments<'_>) -> string::String {
579597
let capacity = args.estimated_capacity();

rust/alloc/lib.rs

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -82,87 +82,91 @@
8282
)]
8383
#![no_std]
8484
#![needs_allocator]
85+
//
86+
// Lints:
87+
#![deny(unsafe_op_in_unsafe_fn)]
8588
#![warn(deprecated_in_future)]
86-
#![warn(missing_docs)]
8789
#![warn(missing_debug_implementations)]
90+
#![warn(missing_docs)]
8891
#![allow(explicit_outlives_requirements)]
89-
#![deny(unsafe_op_in_unsafe_fn)]
90-
#![feature(rustc_allow_const_fn_unstable)]
91-
#![cfg_attr(not(test), feature(generator_trait))]
92-
#![cfg_attr(test, feature(test))]
93-
#![cfg_attr(test, feature(new_uninit))]
92+
//
93+
// Library features:
94+
#![feature(alloc_layout_extra)]
9495
#![feature(allocator_api)]
9596
#![feature(array_chunks)]
9697
#![feature(array_methods)]
9798
#![feature(array_windows)]
98-
#![feature(allow_internal_unstable)]
99-
#![feature(arbitrary_self_types)]
10099
#![feature(async_stream)]
101-
#![feature(box_patterns)]
102-
#![feature(box_syntax)]
103-
#![feature(cfg_sanitize)]
104-
#![feature(cfg_target_has_atomic)]
105100
#![feature(coerce_unsized)]
106101
#![cfg_attr(not(no_global_oom_handling), feature(const_btree_new))]
107-
#![feature(const_fn_trait_bound)]
108-
#![feature(cow_is_borrowed)]
109102
#![feature(const_cow_is_borrowed)]
110-
#![feature(const_trait_impl)]
111-
#![feature(destructuring_assignment)]
112-
#![feature(dispatch_from_dyn)]
113103
#![feature(core_intrinsics)]
114-
#![feature(dropck_eyepatch)]
104+
#![feature(dispatch_from_dyn)]
115105
#![feature(exact_size_is_empty)]
116-
#![feature(exclusive_range_pattern)]
117106
#![feature(extend_one)]
118107
#![feature(fmt_internals)]
119108
#![feature(fn_traits)]
120-
#![feature(fundamental)]
109+
#![feature(inherent_ascii_escape)]
110+
#![cfg_attr(bootstrap, feature(format_args_capture))]
121111
#![feature(inplace_iteration)]
122-
// Technically, this is a bug in rustdoc: rustdoc sees the documentation on `#[lang = slice_alloc]`
123-
// blocks is for `&[T]`, which also has documentation using this feature in `core`, and gets mad
124-
// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
125-
// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
126-
#![feature(intra_doc_pointers)]
127112
#![feature(iter_advance_by)]
128113
#![feature(iter_zip)]
129-
#![feature(lang_items)]
130114
#![feature(layout_for_ptr)]
131-
#![feature(negative_impls)]
132-
#![feature(never_type)]
133-
#![feature(nll)]
115+
#![feature(maybe_uninit_extra)]
116+
#![feature(maybe_uninit_slice)]
117+
#![cfg_attr(test, feature(new_uninit))]
134118
#![feature(nonnull_slice_from_raw_parts)]
135-
#![feature(auto_traits)]
136-
#![feature(option_result_unwrap_unchecked)]
137119
#![feature(pattern)]
138120
#![feature(ptr_internals)]
139-
#![feature(rustc_attrs)]
140121
#![feature(receiver_trait)]
141-
#![feature(min_specialization)]
142122
#![feature(set_ptr_value)]
123+
#![feature(slice_group_by)]
143124
#![feature(slice_ptr_get)]
144125
#![feature(slice_ptr_len)]
145126
#![feature(slice_range)]
146-
#![feature(staged_api)]
147127
#![feature(str_internals)]
148128
#![feature(trusted_len)]
149-
#![feature(unboxed_closures)]
129+
#![feature(trusted_random_access)]
130+
#![feature(try_trait_v2)]
150131
#![feature(unicode_internals)]
151132
#![feature(unsize)]
152-
#![feature(unsized_fn_params)]
133+
//
134+
// Language features:
153135
#![feature(allocator_internals)]
154-
#![feature(slice_partition_dedup)]
155-
#![feature(maybe_uninit_extra, maybe_uninit_slice, maybe_uninit_uninit_array)]
156-
#![feature(alloc_layout_extra)]
157-
#![feature(trusted_random_access)]
158-
#![feature(try_trait_v2)]
136+
#![feature(allow_internal_unstable)]
159137
#![feature(associated_type_bounds)]
160-
#![feature(slice_group_by)]
161-
#![feature(decl_macro)]
138+
#![feature(box_syntax)]
139+
#![feature(cfg_sanitize)]
140+
#![feature(cfg_target_has_atomic)]
141+
#![feature(const_fn_trait_bound)]
142+
#![feature(const_trait_impl)]
143+
#![feature(destructuring_assignment)]
144+
#![feature(dropck_eyepatch)]
145+
#![feature(exclusive_range_pattern)]
146+
#![feature(fundamental)]
147+
#![cfg_attr(not(test), feature(generator_trait))]
148+
#![feature(lang_items)]
149+
#![feature(min_specialization)]
150+
#![feature(negative_impls)]
151+
#![feature(never_type)]
152+
#![feature(nll)] // Not necessary, but here to test the `nll` feature.
153+
#![feature(rustc_allow_const_fn_unstable)]
154+
#![feature(rustc_attrs)]
155+
#![feature(staged_api)]
156+
#![cfg_attr(test, feature(test))]
157+
#![feature(unboxed_closures)]
158+
#![feature(unsized_fn_params)]
159+
//
160+
// Rustdoc features:
162161
#![feature(doc_cfg)]
163-
#![cfg_attr(not(bootstrap), feature(doc_cfg_hide))]
164-
// Allow testing this library
162+
#![feature(doc_cfg_hide)]
163+
// Technically, this is a bug in rustdoc: rustdoc sees the documentation on `#[lang = slice_alloc]`
164+
// blocks is for `&[T]`, which also has documentation using this feature in `core`, and gets mad
165+
// that the feature-gate isn't enabled. Ideally, it wouldn't check for the feature gate for docs
166+
// from other crates, but since this can only appear for lang items, it doesn't seem worth fixing.
167+
#![feature(intra_doc_pointers)]
165168

169+
// Allow testing this library
166170
#[cfg(test)]
167171
#[macro_use]
168172
extern crate std;
@@ -173,6 +177,8 @@ extern crate test;
173177
#[macro_use]
174178
mod macros;
175179

180+
mod raw_vec;
181+
176182
// Heaps provided for low-level allocation strategies
177183

178184
pub mod alloc;
@@ -191,7 +197,6 @@ mod boxed {
191197
pub mod borrow;
192198
pub mod collections;
193199
pub mod fmt;
194-
pub mod raw_vec;
195200
#[cfg(not(no_rc))]
196201
pub mod rc;
197202
pub mod slice;

rust/alloc/raw_vec.rs

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3-
#![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "none")]
4-
#![doc(hidden)]
3+
#![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")]
54

65
use core::alloc::LayoutError;
76
use core::cmp;
@@ -52,7 +51,7 @@ enum AllocInit {
5251
/// `usize::MAX`. This means that you need to be careful when round-tripping this type with a
5352
/// `Box<[T]>`, since `capacity()` won't yield the length.
5453
#[allow(missing_debug_implementations)]
55-
pub struct RawVec<T, A: Allocator = Global> {
54+
pub(crate) struct RawVec<T, A: Allocator = Global> {
5655
ptr: Unique<T>,
5756
cap: usize,
5857
alloc: A,
@@ -89,43 +88,20 @@ impl<T> RawVec<T, Global> {
8988
/// # Aborts
9089
///
9190
/// Aborts on OOM.
92-
#[cfg(not(no_global_oom_handling))]
91+
#[cfg(not(any(no_global_oom_handling, test)))]
9392
#[must_use]
9493
#[inline]
9594
pub fn with_capacity(capacity: usize) -> Self {
9695
Self::with_capacity_in(capacity, Global)
9796
}
9897

99-
/// Tries to create a `RawVec` (on the system heap) with exactly the
100-
/// capacity and alignment requirements for a `[T; capacity]`. This is
101-
/// equivalent to calling `RawVec::new` when `capacity` is `0` or `T` is
102-
/// zero-sized. Note that if `T` is zero-sized this means you will
103-
/// *not* get a `RawVec` with the requested capacity.
104-
#[inline]
105-
pub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError> {
106-
Self::try_with_capacity_in(capacity, Global)
107-
}
108-
10998
/// Like `with_capacity`, but guarantees the buffer is zeroed.
110-
#[cfg(not(no_global_oom_handling))]
99+
#[cfg(not(any(no_global_oom_handling, test)))]
111100
#[must_use]
112101
#[inline]
113102
pub fn with_capacity_zeroed(capacity: usize) -> Self {
114103
Self::with_capacity_zeroed_in(capacity, Global)
115104
}
116-
117-
/// Reconstitutes a `RawVec` from a pointer and capacity.
118-
///
119-
/// # Safety
120-
///
121-
/// The `ptr` must be allocated (on the system heap), and with the given `capacity`.
122-
/// The `capacity` cannot exceed `isize::MAX` for sized types. (only a concern on 32-bit
123-
/// systems). ZST vectors may have a capacity up to `usize::MAX`.
124-
/// If the `ptr` and `capacity` come from a `RawVec`, then this is guaranteed.
125-
#[inline]
126-
pub unsafe fn from_raw_parts(ptr: *mut T, capacity: usize) -> Self {
127-
unsafe { Self::from_raw_parts_in(ptr, capacity, Global) }
128-
}
129105
}
130106

131107
impl<T, A: Allocator> RawVec<T, A> {
@@ -173,14 +149,6 @@ impl<T, A: Allocator> RawVec<T, A> {
173149
Self::allocate_in(capacity, AllocInit::Zeroed, alloc)
174150
}
175151

176-
/// Converts a `Box<[T]>` into a `RawVec<T>`.
177-
pub fn from_box(slice: Box<[T], A>) -> Self {
178-
unsafe {
179-
let (slice, alloc) = Box::into_raw_with_allocator(slice);
180-
RawVec::from_raw_parts_in(slice.as_mut_ptr(), slice.len(), alloc)
181-
}
182-
}
183-
184152
/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
185153
///
186154
/// Note that this will correctly reconstitute any `cap` changes
@@ -329,37 +297,6 @@ impl<T, A: Allocator> RawVec<T, A> {
329297
/// # Aborts
330298
///
331299
/// Aborts on OOM.
332-
///
333-
/// # Examples
334-
///
335-
/// ```
336-
/// # #![feature(raw_vec_internals)]
337-
/// # extern crate alloc;
338-
/// # use std::ptr;
339-
/// # use alloc::raw_vec::RawVec;
340-
/// struct MyVec<T> {
341-
/// buf: RawVec<T>,
342-
/// len: usize,
343-
/// }
344-
///
345-
/// impl<T: Clone> MyVec<T> {
346-
/// pub fn push_all(&mut self, elems: &[T]) {
347-
/// self.buf.reserve(self.len, elems.len());
348-
/// // reserve would have aborted or panicked if the len exceeded
349-
/// // `isize::MAX` so this is safe to do unchecked now.
350-
/// for x in elems {
351-
/// unsafe {
352-
/// ptr::write(self.buf.ptr().add(self.len), x.clone());
353-
/// }
354-
/// self.len += 1;
355-
/// }
356-
/// }
357-
/// }
358-
/// # fn main() {
359-
/// # let mut vector = MyVec { buf: RawVec::new(), len: 0 };
360-
/// # vector.push_all(&[1, 3, 5, 7, 9]);
361-
/// # }
362-
/// ```
363300
#[cfg(not(no_global_oom_handling))]
364301
#[inline]
365302
pub fn reserve(&mut self, len: usize, additional: usize) {

rust/alloc/slice.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ pub use core::slice::ArrayChunks;
110110
pub use core::slice::ArrayChunksMut;
111111
#[unstable(feature = "array_windows", issue = "75027")]
112112
pub use core::slice::ArrayWindows;
113+
#[unstable(feature = "inherent_ascii_escape", issue = "77174")]
114+
pub use core::slice::EscapeAscii;
113115
#[stable(feature = "slice_get_slice", since = "1.28.0")]
114116
pub use core::slice::SliceIndex;
115117
#[stable(feature = "from_ref", since = "1.28.0")]
@@ -132,6 +134,8 @@ pub use core::slice::{RChunks, RChunksExact, RChunksExactMut, RChunksMut};
132134
pub use core::slice::{RSplit, RSplitMut};
133135
#[stable(feature = "rust1", since = "1.0.0")]
134136
pub use core::slice::{RSplitN, RSplitNMut, SplitN, SplitNMut};
137+
#[stable(feature = "split_inclusive", since = "1.51.0")]
138+
pub use core::slice::{SplitInclusive, SplitInclusiveMut};
135139

136140
////////////////////////////////////////////////////////////////////////////////
137141
// Basic slice extension methods

0 commit comments

Comments
 (0)