Skip to content

Commit 05812a0

Browse files
committed
Merge from rustc
2 parents c6e53ce + e6c378f commit 05812a0

File tree

19 files changed

+115
-27
lines changed

19 files changed

+115
-27
lines changed

alloc/src/collections/binary_heap/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
12161216
/// Basic usage:
12171217
///
12181218
/// ```
1219-
/// #![feature(binary_heap_as_slice)]
12201219
/// use std::collections::BinaryHeap;
12211220
/// use std::io::{self, Write};
12221221
///
@@ -1225,7 +1224,7 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
12251224
/// io::sink().write(heap.as_slice()).unwrap();
12261225
/// ```
12271226
#[must_use]
1228-
#[unstable(feature = "binary_heap_as_slice", issue = "83659")]
1227+
#[stable(feature = "binary_heap_as_slice", since = "CURRENT_RUSTC_VERSION")]
12291228
pub fn as_slice(&self) -> &[T] {
12301229
self.data.as_slice()
12311230
}

alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
#![feature(deref_pure_trait)]
122122
#![feature(dispatch_from_dyn)]
123123
#![feature(error_generic_member_access)]
124-
#![feature(error_in_core)]
125124
#![feature(exact_size_is_empty)]
126125
#![feature(extend_one)]
127126
#![feature(fmt_internals)]

alloc/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#![feature(binary_heap_into_iter_sorted)]
2525
#![feature(binary_heap_drain_sorted)]
2626
#![feature(slice_ptr_get)]
27-
#![feature(binary_heap_as_slice)]
2827
#![feature(inplace_iteration)]
2928
#![feature(iter_advance_by)]
3029
#![feature(iter_next_chunk)]

backtrace

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 5e05efa87905fb5b351a2bc5644d60c57d6d9327
1+
Subproject commit 72265bea210891ae47bbe6d4f17b493ef0606619

core/src/error.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![doc = include_str!("error.md")]
2-
#![unstable(feature = "error_in_core", issue = "103765")]
2+
#![stable(feature = "error_in_core", since = "CURRENT_RUSTC_VERSION")]
33

44
#[cfg(test)]
55
mod tests;
@@ -130,7 +130,6 @@ pub trait Error: Debug + Display {
130130
///
131131
/// ```rust
132132
/// #![feature(error_generic_member_access)]
133-
/// #![feature(error_in_core)]
134133
/// use core::fmt;
135134
/// use core::error::{request_ref, Request};
136135
///
@@ -361,8 +360,7 @@ impl dyn Error {
361360
/// Get a string value from an error.
362361
///
363362
/// ```rust
364-
/// # #![feature(error_generic_member_access)]
365-
/// # #![feature(error_in_core)]
363+
/// #![feature(error_generic_member_access)]
366364
/// use std::error::Error;
367365
/// use core::error::request_value;
368366
///
@@ -385,8 +383,7 @@ where
385383
/// Get a string reference from an error.
386384
///
387385
/// ```rust
388-
/// # #![feature(error_generic_member_access)]
389-
/// # #![feature(error_in_core)]
386+
/// #![feature(error_generic_member_access)]
390387
/// use core::error::Error;
391388
/// use core::error::request_ref;
392389
///
@@ -458,7 +455,6 @@ where
458455
///
459456
/// ```
460457
/// #![feature(error_generic_member_access)]
461-
/// #![feature(error_in_core)]
462458
/// use core::fmt;
463459
/// use core::error::Request;
464460
/// use core::error::request_ref;
@@ -529,7 +525,6 @@ impl<'a> Request<'a> {
529525
///
530526
/// ```rust
531527
/// #![feature(error_generic_member_access)]
532-
/// #![feature(error_in_core)]
533528
///
534529
/// use core::error::Request;
535530
///
@@ -564,7 +559,6 @@ impl<'a> Request<'a> {
564559
///
565560
/// ```rust
566561
/// #![feature(error_generic_member_access)]
567-
/// #![feature(error_in_core)]
568562
///
569563
/// use core::error::Request;
570564
///
@@ -600,7 +594,6 @@ impl<'a> Request<'a> {
600594
///
601595
/// ```rust
602596
/// #![feature(error_generic_member_access)]
603-
/// #![feature(error_in_core)]
604597
///
605598
/// use core::error::Request;
606599
///
@@ -633,7 +626,6 @@ impl<'a> Request<'a> {
633626
///
634627
/// ```rust
635628
/// #![feature(error_generic_member_access)]
636-
/// #![feature(error_in_core)]
637629
///
638630
/// use core::error::Request;
639631
///
@@ -700,7 +692,6 @@ impl<'a> Request<'a> {
700692
///
701693
/// ```rust
702694
/// #![feature(error_generic_member_access)]
703-
/// #![feature(error_in_core)]
704695
///
705696
/// use core::error::Request;
706697
/// use core::error::request_value;
@@ -788,7 +779,6 @@ impl<'a> Request<'a> {
788779
///
789780
/// ```rust
790781
/// #![feature(error_generic_member_access)]
791-
/// #![feature(error_in_core)]
792782
///
793783
/// use core::error::Request;
794784
/// use core::error::request_ref;

core/src/fmt/num.rs

+33
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static DEC_DIGITS_LUT: &[u8; 200] = b"0001020304050607080910111213141516171819\
212212

213213
macro_rules! impl_Display {
214214
($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => {
215+
#[cfg(not(feature = "optimize_for_size"))]
215216
fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
216217
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
217218
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
@@ -277,6 +278,38 @@ macro_rules! impl_Display {
277278
f.pad_integral(is_nonnegative, "", buf_slice)
278279
}
279280

281+
#[cfg(feature = "optimize_for_size")]
282+
fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter<'_>) -> fmt::Result {
283+
// 2^128 is about 3*10^38, so 39 gives an extra byte of space
284+
let mut buf = [MaybeUninit::<u8>::uninit(); 39];
285+
let mut curr = buf.len();
286+
let buf_ptr = MaybeUninit::slice_as_mut_ptr(&mut buf);
287+
288+
// SAFETY: To show that it's OK to copy into `buf_ptr`, notice that at the beginning
289+
// `curr == buf.len() == 39 > log(n)` since `n < 2^128 < 10^39`, and at
290+
// each step this is kept the same as `n` is divided. Since `n` is always
291+
// non-negative, this means that `curr > 0` so `buf_ptr[curr..curr + 1]`
292+
// is safe to access.
293+
unsafe {
294+
loop {
295+
curr -= 1;
296+
buf_ptr.add(curr).write((n % 10) as u8 + b'0');
297+
n /= 10;
298+
299+
if n == 0 {
300+
break;
301+
}
302+
}
303+
}
304+
305+
// SAFETY: `curr` > 0 (since we made `buf` large enough), and all the chars are valid UTF-8
306+
let buf_slice = unsafe {
307+
str::from_utf8_unchecked(
308+
slice::from_raw_parts(buf_ptr.add(curr), buf.len() - curr))
309+
};
310+
f.pad_integral(is_nonnegative, "", buf_slice)
311+
}
312+
280313
$(#[stable(feature = "rust1", since = "1.0.0")]
281314
impl fmt::Display for $t {
282315
#[allow(unused_comparisons)]

core/src/option.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1708,8 +1708,6 @@ impl<T> Option<T> {
17081708
/// # Examples
17091709
///
17101710
/// ```
1711-
/// #![feature(option_take_if)]
1712-
///
17131711
/// let mut x = Some(42);
17141712
///
17151713
/// let prev = x.take_if(|v| if *v == 42 {
@@ -1726,7 +1724,7 @@ impl<T> Option<T> {
17261724
/// assert_eq!(prev, Some(43));
17271725
/// ```
17281726
#[inline]
1729-
#[unstable(feature = "option_take_if", issue = "98934")]
1727+
#[stable(feature = "option_take_if", since = "CURRENT_RUSTC_VERSION")]
17301728
pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
17311729
where
17321730
P: FnOnce(&mut T) -> bool,

core/src/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
//! requires at least a level of pointer indirection each time a new object is added to the mix
185185
//! (and, practically, a heap allocation).
186186
//!
187-
//! Although there were other reason as well, this issue of expensive composition is the key thing
187+
//! Although there were other reasons as well, this issue of expensive composition is the key thing
188188
//! that drove Rust towards adopting a different model. It is particularly a problem
189189
//! when one considers, for example, the implications of composing together the [`Future`]s which
190190
//! will eventually make up an asynchronous task (including address-sensitive `async fn` state

core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
#![feature(const_slice_from_ref)]
113113
#![feature(waker_getters)]
114114
#![feature(error_generic_member_access)]
115-
#![feature(error_in_core)]
116115
#![feature(trait_upcasting)]
117116
#![feature(is_ascii_octdigit)]
118117
#![feature(get_many_mut)]

std/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ addr2line = { version = "0.22.0", optional = true, default-features = false }
3434
libc = { version = "0.2.153", default-features = false, features = ['rustc-dep-of-std'], public = true }
3535

3636
[target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies]
37-
object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] }
37+
object = { version = "0.36.0", default-features = false, optional = true, features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive'] }
3838

3939
[target.'cfg(target_os = "aix")'.dependencies]
40-
object = { version = "0.32.0", default-features = false, optional = true, features = ['read_core', 'xcoff', 'unaligned', 'archive'] }
40+
object = { version = "0.36.0", default-features = false, optional = true, features = ['read_core', 'xcoff', 'unaligned', 'archive'] }
4141

4242
[dev-dependencies]
4343
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }

std/src/ffi/os_str.rs

+19
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,25 @@ impl OsString {
533533
unsafe { Box::from_raw(rw) }
534534
}
535535

536+
/// Consumes and leaks the `OsString`, returning a mutable reference to the contents,
537+
/// `&'a mut OsStr`.
538+
///
539+
/// The caller has free choice over the returned lifetime, including 'static.
540+
/// Indeed, this function is ideally used for data that lives for the remainder of
541+
/// the program’s life, as dropping the returned reference will cause a memory leak.
542+
///
543+
/// It does not reallocate or shrink the `OsString`, so the leaked allocation may include
544+
/// unused capacity that is not part of the returned slice. If you want to discard excess
545+
/// capacity, call [`into_boxed_os_str`], and then [`Box::leak`] instead.
546+
/// However, keep in mind that trimming the capacity may result in a reallocation and copy.
547+
///
548+
/// [`into_boxed_os_str`]: Self::into_boxed_os_str
549+
#[unstable(feature = "os_string_pathbuf_leak", issue = "125965")]
550+
#[inline]
551+
pub fn leak<'a>(self) -> &'a mut OsStr {
552+
OsStr::from_inner_mut(self.inner.leak())
553+
}
554+
536555
/// Part of a hack to make PathBuf::push/pop more efficient.
537556
#[inline]
538557
pub(crate) fn as_mut_vec_for_path_buf(&mut self) -> &mut Vec<u8> {

std/src/ffi/os_str/tests.rs

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ fn test_os_string_clear() {
2323
assert_eq!(0, os_string.inner.as_inner().len());
2424
}
2525

26+
#[test]
27+
fn test_os_string_leak() {
28+
let os_string = OsString::from("have a cake");
29+
let (len, cap) = (os_string.len(), os_string.capacity());
30+
let leaked = os_string.leak();
31+
assert_eq!(leaked.as_encoded_bytes(), b"have a cake");
32+
unsafe { drop(String::from_raw_parts(leaked as *mut OsStr as _, len, cap)) }
33+
}
34+
2635
#[test]
2736
fn test_os_string_capacity() {
2837
let os_string = OsString::with_capacity(0);

std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@
324324
#![feature(core_io_borrowed_buf)]
325325
#![feature(duration_constants)]
326326
#![feature(error_generic_member_access)]
327-
#![feature(error_in_core)]
328327
#![feature(error_iter)]
329328
#![feature(exact_size_is_empty)]
330329
#![feature(exclusive_wrapper)]

std/src/path.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,25 @@ impl PathBuf {
12261226
self
12271227
}
12281228

1229+
/// Consumes and leaks the `PathBuf`, returning a mutable reference to the contents,
1230+
/// `&'a mut Path`.
1231+
///
1232+
/// The caller has free choice over the returned lifetime, including 'static.
1233+
/// Indeed, this function is ideally used for data that lives for the remainder of
1234+
/// the program’s life, as dropping the returned reference will cause a memory leak.
1235+
///
1236+
/// It does not reallocate or shrink the `PathBuf`, so the leaked allocation may include
1237+
/// unused capacity that is not part of the returned slice. If you want to discard excess
1238+
/// capacity, call [`into_boxed_path`], and then [`Box::leak`] instead.
1239+
/// However, keep in mind that trimming the capacity may result in a reallocation and copy.
1240+
///
1241+
/// [`into_boxed_path`]: Self::into_boxed_path
1242+
#[unstable(feature = "os_string_pathbuf_leak", issue = "125965")]
1243+
#[inline]
1244+
pub fn leak<'a>(self) -> &'a mut Path {
1245+
Path::from_inner_mut(self.inner.leak())
1246+
}
1247+
12291248
/// Extends `self` with `path`.
12301249
///
12311250
/// If `path` is absolute, it replaces the current path.

std/src/path/tests.rs

+10
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ fn into() {
126126
assert_eq!(static_cow_path, owned_cow_path);
127127
}
128128

129+
#[test]
130+
fn test_pathbuf_leak() {
131+
let string = "/have/a/cake".to_owned();
132+
let (len, cap) = (string.len(), string.capacity());
133+
let buf = PathBuf::from(string);
134+
let leaked = buf.leak();
135+
assert_eq!(leaked.as_os_str().as_encoded_bytes(), b"/have/a/cake");
136+
unsafe { drop(String::from_raw_parts(leaked.as_mut_os_str() as *mut OsStr as _, len, cap)) }
137+
}
138+
129139
#[test]
130140
#[cfg(unix)]
131141
pub fn test_decompositions_unix() {

std/src/sys/os_str/bytes.rs

+5
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ impl Buf {
176176
self.inner.extend_from_slice(&s.inner)
177177
}
178178

179+
#[inline]
180+
pub fn leak<'a>(self) -> &'a mut Slice {
181+
unsafe { mem::transmute(self.inner.leak()) }
182+
}
183+
179184
#[inline]
180185
pub fn into_box(self) -> Box<Slice> {
181186
unsafe { mem::transmute(self.inner.into_boxed_slice()) }

std/src/sys/os_str/wtf8.rs

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ impl Buf {
138138
self.inner.shrink_to(min_capacity)
139139
}
140140

141+
#[inline]
142+
pub fn leak<'a>(self) -> &'a mut Slice {
143+
unsafe { mem::transmute(self.inner.leak()) }
144+
}
145+
141146
#[inline]
142147
pub fn into_box(self) -> Box<Slice> {
143148
unsafe { mem::transmute(self.inner.into_box()) }

std/src/sys/pal/windows/c/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ be edited manually.
33

44
To add bindings, edit `bindings.txt` then regenerate using the following command:
55

6-
./x run generate-windows-sys && ./x fmt library/std
6+
./x run generate-windows-sys && ./x fmt
77

88
If you need to override generated functions or types then add them to
99
`library/std/src/sys/pal/windows/c.rs`.

std/src/sys_common/wtf8.rs

+5
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ impl Wtf8Buf {
325325
self.bytes.shrink_to(min_capacity)
326326
}
327327

328+
#[inline]
329+
pub fn leak<'a>(self) -> &'a mut Wtf8 {
330+
unsafe { Wtf8::from_mut_bytes_unchecked(self.bytes.leak()) }
331+
}
332+
328333
/// Returns the number of bytes that this string buffer can hold without reallocating.
329334
#[inline]
330335
pub fn capacity(&self) -> usize {

0 commit comments

Comments
 (0)