Skip to content

Commit 3488cdd

Browse files
borsgitbot
authored and
gitbot
committed
Auto merge of rust-lang#137571 - tgross35:rollup-i1tcnv1, r=tgross35
Rollup of 8 pull requests Successful merges: - rust-lang#134655 (Stabilize `hash_extract_if`) - rust-lang#135933 (Explain how Vec::with_capacity is faithful) - rust-lang#136668 (Stabilize `core::str::from_utf8_mut` as `const`) - rust-lang#136775 (Update `String::from_raw_parts` safety requirements) - rust-lang#137109 (stabilize extract_if) - rust-lang#137349 (Implement `read_buf` for zkVM stdin) - rust-lang#137493 (configure.py: don't instruct user to run nonexistent program) - rust-lang#137516 (remove some unnecessary rustc_const_unstable) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e075ffa + f479cf0 commit 3488cdd

File tree

12 files changed

+50
-49
lines changed

12 files changed

+50
-49
lines changed

alloc/src/collections/linked_list.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ impl<T, A: Allocator> LinkedList<T, A> {
11401140
/// Splitting a list into evens and odds, reusing the original list:
11411141
///
11421142
/// ```
1143-
/// #![feature(extract_if)]
11441143
/// use std::collections::LinkedList;
11451144
///
11461145
/// let mut numbers: LinkedList<u32> = LinkedList::new();
@@ -1152,7 +1151,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
11521151
/// assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![2, 4, 6, 8, 14]);
11531152
/// assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 9, 11, 13, 15]);
11541153
/// ```
1155-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
1154+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
11561155
pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F, A>
11571156
where
11581157
F: FnMut(&mut T) -> bool,
@@ -1932,7 +1931,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
19321931
}
19331932

19341933
/// An iterator produced by calling `extract_if` on LinkedList.
1935-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
1934+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
19361935
#[must_use = "iterators are lazy and do nothing unless consumed"]
19371936
pub struct ExtractIf<
19381937
'a,
@@ -1947,7 +1946,7 @@ pub struct ExtractIf<
19471946
old_len: usize,
19481947
}
19491948

1950-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
1949+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
19511950
impl<T, F, A: Allocator> Iterator for ExtractIf<'_, T, F, A>
19521951
where
19531952
F: FnMut(&mut T) -> bool,
@@ -1976,7 +1975,7 @@ where
19761975
}
19771976
}
19781977

1979-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
1978+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
19801979
impl<T: fmt::Debug, F> fmt::Debug for ExtractIf<'_, T, F> {
19811980
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19821981
f.debug_tuple("ExtractIf").field(&self.list).finish()

alloc/src/string.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,8 @@ impl String {
966966
/// This is highly unsafe, due to the number of invariants that aren't
967967
/// checked:
968968
///
969-
/// * The memory at `buf` needs to have been previously allocated by the
970-
/// same allocator the standard library uses, with a required alignment of exactly 1.
971-
/// * `length` needs to be less than or equal to `capacity`.
972-
/// * `capacity` needs to be the correct value.
973-
/// * The first `length` bytes at `buf` need to be valid UTF-8.
969+
/// * all safety requirements for [`Vec::<u8>::from_raw_parts`].
970+
/// * all safety requirements for [`String::from_utf8_unchecked`].
974971
///
975972
/// Violating these may cause problems like corrupting the allocator's
976973
/// internal data structures. For example, it is normally **not** safe to

alloc/src/vec/extract_if.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ use crate::alloc::{Allocator, Global};
1212
/// # Example
1313
///
1414
/// ```
15-
/// #![feature(extract_if)]
16-
///
1715
/// let mut v = vec![0, 1, 2];
1816
/// let iter: std::vec::ExtractIf<'_, _, _> = v.extract_if(.., |x| *x % 2 == 0);
1917
/// ```
20-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
18+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
2119
#[derive(Debug)]
2220
#[must_use = "iterators are lazy and do nothing unless consumed"]
2321
pub struct ExtractIf<
@@ -59,7 +57,7 @@ impl<'a, T, F, A: Allocator> ExtractIf<'a, T, F, A> {
5957
}
6058
}
6159

62-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
60+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
6361
impl<T, F, A: Allocator> Iterator for ExtractIf<'_, T, F, A>
6462
where
6563
F: FnMut(&mut T) -> bool,
@@ -95,7 +93,7 @@ where
9593
}
9694
}
9795

98-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
96+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
9997
impl<T, F, A: Allocator> Drop for ExtractIf<'_, T, F, A> {
10098
fn drop(&mut self) {
10199
unsafe {

alloc/src/vec/mod.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use core::ptr::{self, NonNull};
6666
use core::slice::{self, SliceIndex};
6767
use core::{fmt, intrinsics};
6868

69-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
69+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
7070
pub use self::extract_if::ExtractIf;
7171
use crate::alloc::{Allocator, Global};
7272
use crate::borrow::{Cow, ToOwned};
@@ -355,11 +355,20 @@ mod spec_extend;
355355
/// and it may prove desirable to use a non-constant growth factor. Whatever
356356
/// strategy is used will of course guarantee *O*(1) amortized [`push`].
357357
///
358-
/// `vec![x; n]`, `vec![a, b, c, d]`, and
359-
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
360-
/// with at least the requested capacity. If <code>[len] == [capacity]</code>,
361-
/// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to
362-
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
358+
/// It is guaranteed, in order to respect the intentions of the programmer, that
359+
/// all of `vec![e_1, e_2, ..., e_n]`, `vec![x; n]`, and [`Vec::with_capacity(n)`] produce a `Vec`
360+
/// that requests an allocation of the exact size needed for precisely `n` elements from the allocator,
361+
/// and no other size (such as, for example: a size rounded up to the nearest power of 2).
362+
/// The allocator will return an allocation that is at least as large as requested, but it may be larger.
363+
///
364+
/// It is guaranteed that the [`Vec::capacity`] method returns a value that is at least the requested capacity
365+
/// and not more than the allocated capacity.
366+
///
367+
/// The method [`Vec::shrink_to_fit`] will attempt to discard excess capacity an allocator has given to a `Vec`.
368+
/// If <code>[len] == [capacity]</code>, then a `Vec<T>` can be converted
369+
/// to and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
370+
/// `Vec` exploits this fact as much as reasonable when implementing common conversions
371+
/// such as [`into_boxed_slice`].
363372
///
364373
/// `Vec` will not specifically overwrite any data that is removed from it,
365374
/// but also won't specifically preserve it. Its uninitialized memory is
@@ -383,14 +392,17 @@ mod spec_extend;
383392
/// [`shrink_to`]: Vec::shrink_to
384393
/// [capacity]: Vec::capacity
385394
/// [`capacity`]: Vec::capacity
395+
/// [`Vec::capacity`]: Vec::capacity
386396
/// [mem::size_of::\<T>]: core::mem::size_of
387397
/// [len]: Vec::len
388398
/// [`len`]: Vec::len
389399
/// [`push`]: Vec::push
390400
/// [`insert`]: Vec::insert
391401
/// [`reserve`]: Vec::reserve
402+
/// [`Vec::with_capacity(n)`]: Vec::with_capacity
392403
/// [`MaybeUninit`]: core::mem::MaybeUninit
393404
/// [owned slice]: Box
405+
/// [`into_boxed_slice`]: Vec::into_boxed_slice
394406
#[stable(feature = "rust1", since = "1.0.0")]
395407
#[cfg_attr(not(test), rustc_diagnostic_item = "Vec")]
396408
#[rustc_insignificant_dtor]
@@ -3684,7 +3696,6 @@ impl<T, A: Allocator> Vec<T, A> {
36843696
/// Splitting an array into evens and odds, reusing the original allocation:
36853697
///
36863698
/// ```
3687-
/// #![feature(extract_if)]
36883699
/// let mut numbers = vec![1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15];
36893700
///
36903701
/// let evens = numbers.extract_if(.., |x| *x % 2 == 0).collect::<Vec<_>>();
@@ -3697,13 +3708,12 @@ impl<T, A: Allocator> Vec<T, A> {
36973708
/// Using the range argument to only process a part of the vector:
36983709
///
36993710
/// ```
3700-
/// #![feature(extract_if)]
37013711
/// let mut items = vec![0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 1, 2];
37023712
/// let ones = items.extract_if(7.., |x| *x == 1).collect::<Vec<_>>();
37033713
/// assert_eq!(items, vec![0, 0, 0, 0, 0, 0, 0, 2, 2, 2]);
37043714
/// assert_eq!(ones.len(), 3);
37053715
/// ```
3706-
#[unstable(feature = "extract_if", reason = "recently added", issue = "43244")]
3716+
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
37073717
pub fn extract_if<F, R>(&mut self, range: R, filter: F) -> ExtractIf<'_, T, F, A>
37083718
where
37093719
F: FnMut(&mut T) -> bool,

alloc/tests/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![feature(cow_is_borrowed)]
88
#![feature(core_intrinsics)]
99
#![feature(downcast_unchecked)]
10-
#![feature(extract_if)]
1110
#![feature(exact_size_is_empty)]
1211
#![feature(hashmap_internals)]
1312
#![feature(linked_list_cursors)]
@@ -29,7 +28,6 @@
2928
#![feature(string_remove_matches)]
3029
#![feature(const_btree_len)]
3130
#![feature(const_trait_impl)]
32-
#![feature(const_str_from_utf8)]
3331
#![feature(panic_update_hook)]
3432
#![feature(pointer_is_aligned_to)]
3533
#![feature(test)]

core/src/mem/maybe_uninit.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ impl<T> MaybeUninit<T> {
10411041

10421042
/// Deprecated version of [`slice::assume_init_ref`].
10431043
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1044-
#[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")]
10451044
#[deprecated(
10461045
note = "replaced by inherent assume_init_ref method; will eventually be removed",
10471046
since = "1.83.0"
@@ -1053,7 +1052,6 @@ impl<T> MaybeUninit<T> {
10531052

10541053
/// Deprecated version of [`slice::assume_init_mut`].
10551054
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
1056-
#[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")]
10571055
#[deprecated(
10581056
note = "replaced by inherent assume_init_mut method; will eventually be removed",
10591057
since = "1.83.0"
@@ -1326,7 +1324,6 @@ impl<T> [MaybeUninit<T>] {
13261324
///
13271325
/// [`write_clone_of_slice`]: slice::write_clone_of_slice
13281326
#[unstable(feature = "maybe_uninit_write_slice", issue = "79995")]
1329-
#[rustc_const_unstable(feature = "maybe_uninit_write_slice", issue = "79995")]
13301327
pub const fn write_copy_of_slice(&mut self, src: &[T]) -> &mut [T]
13311328
where
13321329
T: Copy,

core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,6 @@ impl<T> [T] {
956956
/// [`swap`]: slice::swap
957957
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
958958
#[unstable(feature = "slice_swap_unchecked", issue = "88539")]
959-
#[rustc_const_unstable(feature = "slice_swap_unchecked", issue = "88539")]
960959
pub const unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
961960
assert_unsafe_precondition!(
962961
check_library_ub,
@@ -3734,6 +3733,7 @@ impl<T> [T] {
37343733
#[inline]
37353734
#[stable(feature = "copy_from_slice", since = "1.9.0")]
37363735
#[rustc_const_unstable(feature = "const_copy_from_slice", issue = "131415")]
3736+
#[rustc_const_stable_indirect]
37373737
#[track_caller]
37383738
pub const fn copy_from_slice(&mut self, src: &[T])
37393739
where

core/src/str/converts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
126126
/// See the docs for [`Utf8Error`] for more details on the kinds of
127127
/// errors that can be returned.
128128
#[stable(feature = "str_mut_extras", since = "1.20.0")]
129-
#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")]
129+
#[rustc_const_stable(feature = "const_str_from_utf8", since = "CURRENT_RUSTC_VERSION")]
130130
#[rustc_diagnostic_item = "str_from_utf8_mut"]
131131
pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
132132
// FIXME(const-hack): This should use `?` again, once it's `const`

core/src/str/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl str {
265265
/// See the docs for [`Utf8Error`] for more details on the kinds of
266266
/// errors that can be returned.
267267
#[stable(feature = "inherent_str_constructors", since = "CURRENT_RUSTC_VERSION")]
268-
#[rustc_const_unstable(feature = "const_str_from_utf8", issue = "91006")]
268+
#[rustc_const_stable(feature = "const_str_from_utf8", since = "CURRENT_RUSTC_VERSION")]
269269
#[rustc_diagnostic_item = "str_inherent_from_utf8_mut"]
270270
pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error> {
271271
converts::from_utf8_mut(v)

std/src/collections/hash/map.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ impl<K, V, S> HashMap<K, V, S> {
656656
/// Splitting a map into even and odd keys, reusing the original map:
657657
///
658658
/// ```
659-
/// #![feature(hash_extract_if)]
660659
/// use std::collections::HashMap;
661660
///
662661
/// let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();
@@ -672,7 +671,7 @@ impl<K, V, S> HashMap<K, V, S> {
672671
/// ```
673672
#[inline]
674673
#[rustc_lint_query_instability]
675-
#[unstable(feature = "hash_extract_if", issue = "59618")]
674+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
676675
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
677676
where
678677
F: FnMut(&K, &mut V) -> bool,
@@ -1722,16 +1721,14 @@ impl<'a, K, V> Drain<'a, K, V> {
17221721
/// # Example
17231722
///
17241723
/// ```
1725-
/// #![feature(hash_extract_if)]
1726-
///
17271724
/// use std::collections::HashMap;
17281725
///
17291726
/// let mut map = HashMap::from([
17301727
/// ("a", 1),
17311728
/// ]);
17321729
/// let iter = map.extract_if(|_k, v| *v % 2 == 0);
17331730
/// ```
1734-
#[unstable(feature = "hash_extract_if", issue = "59618")]
1731+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
17351732
#[must_use = "iterators are lazy and do nothing unless consumed"]
17361733
pub struct ExtractIf<'a, K, V, F>
17371734
where
@@ -2746,7 +2743,7 @@ where
27462743
}
27472744
}
27482745

2749-
#[unstable(feature = "hash_extract_if", issue = "59618")]
2746+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
27502747
impl<K, V, F> Iterator for ExtractIf<'_, K, V, F>
27512748
where
27522749
F: FnMut(&K, &mut V) -> bool,
@@ -2763,10 +2760,10 @@ where
27632760
}
27642761
}
27652762

2766-
#[unstable(feature = "hash_extract_if", issue = "59618")]
2763+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
27672764
impl<K, V, F> FusedIterator for ExtractIf<'_, K, V, F> where F: FnMut(&K, &mut V) -> bool {}
27682765

2769-
#[unstable(feature = "hash_extract_if", issue = "59618")]
2766+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
27702767
impl<'a, K, V, F> fmt::Debug for ExtractIf<'a, K, V, F>
27712768
where
27722769
F: FnMut(&K, &mut V) -> bool,

std/src/collections/hash/set.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ impl<T, S> HashSet<T, S> {
293293
/// Splitting a set into even and odd values, reusing the original set:
294294
///
295295
/// ```
296-
/// #![feature(hash_extract_if)]
297296
/// use std::collections::HashSet;
298297
///
299298
/// let mut set: HashSet<i32> = (0..8).collect();
@@ -309,7 +308,7 @@ impl<T, S> HashSet<T, S> {
309308
/// ```
310309
#[inline]
311310
#[rustc_lint_query_instability]
312-
#[unstable(feature = "hash_extract_if", issue = "59618")]
311+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
313312
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, T, F>
314313
where
315314
F: FnMut(&T) -> bool,
@@ -1385,15 +1384,13 @@ pub struct Drain<'a, K: 'a> {
13851384
/// # Examples
13861385
///
13871386
/// ```
1388-
/// #![feature(hash_extract_if)]
1389-
///
13901387
/// use std::collections::HashSet;
13911388
///
13921389
/// let mut a = HashSet::from([1, 2, 3]);
13931390
///
13941391
/// let mut extract_ifed = a.extract_if(|v| v % 2 == 0);
13951392
/// ```
1396-
#[unstable(feature = "hash_extract_if", issue = "59618")]
1393+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
13971394
pub struct ExtractIf<'a, K, F>
13981395
where
13991396
F: FnMut(&K) -> bool,
@@ -1676,7 +1673,7 @@ impl<K: fmt::Debug> fmt::Debug for Drain<'_, K> {
16761673
}
16771674
}
16781675

1679-
#[unstable(feature = "hash_extract_if", issue = "59618")]
1676+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
16801677
impl<K, F> Iterator for ExtractIf<'_, K, F>
16811678
where
16821679
F: FnMut(&K) -> bool,
@@ -1693,10 +1690,10 @@ where
16931690
}
16941691
}
16951692

1696-
#[unstable(feature = "hash_extract_if", issue = "59618")]
1693+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
16971694
impl<K, F> FusedIterator for ExtractIf<'_, K, F> where F: FnMut(&K) -> bool {}
16981695

1699-
#[unstable(feature = "hash_extract_if", issue = "59618")]
1696+
#[stable(feature = "hash_extract_if", since = "CURRENT_RUSTC_VERSION")]
17001697
impl<'a, K, F> fmt::Debug for ExtractIf<'a, K, F>
17011698
where
17021699
F: FnMut(&K) -> bool,

std/src/sys/pal/zkvm/stdio.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::abi;
22
use super::abi::fileno;
3-
use crate::io;
3+
use crate::io::{self, BorrowedCursor};
44

55
pub struct Stdin;
66
pub struct Stdout;
@@ -16,6 +16,14 @@ impl io::Read for Stdin {
1616
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
1717
Ok(unsafe { abi::sys_read(fileno::STDIN, buf.as_mut_ptr(), buf.len()) })
1818
}
19+
20+
fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
21+
unsafe {
22+
let n = abi::sys_read(fileno::STDIN, buf.as_mut().as_mut_ptr().cast(), buf.capacity());
23+
buf.advance_unchecked(n);
24+
}
25+
Ok(())
26+
}
1927
}
2028

2129
impl Stdout {

0 commit comments

Comments
 (0)