Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9dcffa5

Browse files
Rollup merge ofrust-lang#125082 - kpreid:const-uninit, r=dtolnay
Remove `MaybeUninit::uninit_array()` and replace it with inline const blocks.\[This PR originally contained the changes inrust-lang#125995 too. See edit history for the original PR description.]The documentation of `MaybeUninit::uninit_array()` says:> Note: in a future Rust version this method may become unnecessary when Rust allows [inline const expressions](rust-lang#76001). The example below could then use `let mut buf = [const { MaybeUninit::<u8>::uninit() }; 32];`.The PR adding it also said: <rust-lang#65580 (comment)>> if it’s stabilized soon enough maybe it’s not worth having a standard library method that will be replaceable with `let buffer = [MaybeUninit::<T>::uninit(); $N];`That time has come to pass — inline const expressions are stable — so `MaybeUninit::uninit_array()` is now unnecessary. The only remaining question is whether it is an important enough *convenience* to keep it around.I believe it is net good to remove this function, on the principle that it is better to compose two orthogonal features (`MaybeUninit` and array construction) than to have a specific function for the specific combination, now that that is possible.
2 parentse51d8a2 +cf34f71 commit9dcffa5

File tree

20 files changed

+31
-36
lines changed

20 files changed

+31
-36
lines changed

‎alloc/src/collections/vec_deque/into_iter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
132132
fnnext_chunk<constN:usize>(
133133
&mutself,
134134
) ->Result<[Self::Item;N], array::IntoIter<Self::Item,N>>{
135-
letmut raw_arr =MaybeUninit::uninit_array();
135+
letmut raw_arr =[const{MaybeUninit::uninit()};N];
136136
let raw_arr_ptr = raw_arr.as_mut_ptr().cast();
137137
let(head, tail) =self.inner.as_slices();
138138

‎alloc/src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@
135135
#![feature(layout_for_ptr)]
136136
#![feature(local_waker)]
137137
#![feature(maybe_uninit_slice)]
138-
#![feature(maybe_uninit_uninit_array)]
139138
#![feature(maybe_uninit_uninit_array_transpose)]
140139
#![feature(panic_internals)]
141140
#![feature(pattern)]

‎alloc/src/vec/into_iter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
254254

255255
#[inline]
256256
fnnext_chunk<constN:usize>(&mutself) ->Result<[T;N], core::array::IntoIter<T,N>>{
257-
letmut raw_ary =MaybeUninit::uninit_array();
257+
letmut raw_ary =[const{MaybeUninit::uninit()};N];
258258

259259
let len =self.len();
260260

‎core/src/array/iter.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ impl<T, const N: usize> IntoIter<T, N> {
101101
/// ```
102102
/// #![feature(array_into_iter_constructors)]
103103
/// #![feature(maybe_uninit_uninit_array_transpose)]
104-
/// #![feature(maybe_uninit_uninit_array)]
105104
/// use std::array::IntoIter;
106105
/// use std::mem::MaybeUninit;
107106
///
@@ -111,7 +110,7 @@ impl<T, const N: usize> IntoIter<T, N> {
111110
/// fn next_chunk<T: Copy, const N: usize>(
112111
/// it: &mut impl Iterator<Item = T>,
113112
/// ) -> Result<[T; N], IntoIter<T, N>> {
114-
/// let mut buffer = MaybeUninit::uninit_array();
113+
/// let mut buffer =[const {MaybeUninit::uninit() }; N];
115114
/// let mut i = 0;
116115
/// while i < N {
117116
/// match it.next() {
@@ -203,7 +202,7 @@ impl<T, const N: usize> IntoIter<T, N> {
203202
#[unstable(feature ="array_into_iter_constructors", issue ="91583")]
204203
#[rustc_const_unstable(feature ="const_array_into_iter_constructors", issue ="91583")]
205204
pubconstfnempty() ->Self{
206-
let buffer =MaybeUninit::uninit_array();
205+
let buffer =[const{MaybeUninit::uninit()};N];
207206
let initialized =0..0;
208207

209208
// SAFETY: We're telling it that none of the elements are initialized,
@@ -405,7 +404,8 @@ impl<T: Clone, const N: usize> Clone for IntoIter<T, N> {
405404
fnclone(&self) ->Self{
406405
// Note, we don't really need to match the exact same alive range, so
407406
// we can just clone into offset 0 regardless of where `self` is.
408-
letmut new =Self{data:MaybeUninit::uninit_array(),alive:IndexRange::zero_to(0)};
407+
letmut new =
408+
Self{data:[const{MaybeUninit::uninit()};N],alive:IndexRange::zero_to(0)};
409409

410410
// Clone all alive elements.
411411
for(src, dst)in iter::zip(self.as_slice(),&mut new.data){

‎core/src/array/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ where
127127
R:Try,
128128
R::Residual:Residual<[R::Output;N]>,
129129
{
130-
letmut array =MaybeUninit::uninit_array::<N>();
130+
letmut array =[const{MaybeUninit::uninit()};N];
131131
matchtry_from_fn_erased(&mut array, cb){
132132
ControlFlow::Break(r) =>FromResidual::from_residual(r),
133133
ControlFlow::Continue(()) =>{
@@ -918,7 +918,7 @@ impl<T> Drop for Guard<'_, T> {
918918
pub(crate)fniter_next_chunk<T,constN:usize>(
919919
iter:&mutimplIterator<Item =T>,
920920
) ->Result<[T;N],IntoIter<T,N>>{
921-
letmut array =MaybeUninit::uninit_array::<N>();
921+
letmut array =[const{MaybeUninit::uninit()};N];
922922
let r =iter_next_chunk_erased(&mut array, iter);
923923
match r{
924924
Ok(()) =>{

‎core/src/fmt/float.rs‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ fn float_to_decimal_common_exact<T>(
3535
where
3636
T: flt2dec::DecodableFloat,
3737
{
38-
letmut buf:[MaybeUninit<u8>;1024] =MaybeUninit::uninit_array();// enough for f32 and f64
39-
letmut parts:[MaybeUninit<numfmt::Part<'_>>;4] =MaybeUninit::uninit_array();
38+
letmut buf:[MaybeUninit<u8>;1024] =[MaybeUninit::uninit();1024];// enough for f32 and f64
39+
letmut parts:[MaybeUninit<numfmt::Part<'_>>;4] =[MaybeUninit::uninit();4];
4040
let formatted = flt2dec::to_exact_fixed_str(
4141
flt2dec::strategy::grisu::format_exact,
4242
*num,
@@ -62,8 +62,9 @@ where
6262
T: flt2dec::DecodableFloat,
6363
{
6464
// enough for f32 and f64
65-
letmut buf:[MaybeUninit<u8>; flt2dec::MAX_SIG_DIGITS] =MaybeUninit::uninit_array();
66-
letmut parts:[MaybeUninit<numfmt::Part<'_>>;4] =MaybeUninit::uninit_array();
65+
letmut buf:[MaybeUninit<u8>; flt2dec::MAX_SIG_DIGITS] =
66+
[MaybeUninit::uninit(); flt2dec::MAX_SIG_DIGITS];
67+
letmut parts:[MaybeUninit<numfmt::Part<'_>>;4] =[MaybeUninit::uninit();4];
6768
let formatted = flt2dec::to_shortest_str(
6869
flt2dec::strategy::grisu::format_shortest,
6970
*num,
@@ -107,8 +108,8 @@ fn float_to_exponential_common_exact<T>(
107108
where
108109
T: flt2dec::DecodableFloat,
109110
{
110-
letmut buf:[MaybeUninit<u8>;1024] =MaybeUninit::uninit_array();// enough for f32 and f64
111-
letmut parts:[MaybeUninit<numfmt::Part<'_>>;6] =MaybeUninit::uninit_array();
111+
letmut buf:[MaybeUninit<u8>;1024] =[MaybeUninit::uninit();1024];// enough for f32 and f64
112+
letmut parts:[MaybeUninit<numfmt::Part<'_>>;6] =[MaybeUninit::uninit();6];
112113
let formatted = flt2dec::to_exact_exp_str(
113114
flt2dec::strategy::grisu::format_exact,
114115
*num,
@@ -135,8 +136,9 @@ where
135136
T: flt2dec::DecodableFloat,
136137
{
137138
// enough for f32 and f64
138-
letmut buf:[MaybeUninit<u8>; flt2dec::MAX_SIG_DIGITS] =MaybeUninit::uninit_array();
139-
letmut parts:[MaybeUninit<numfmt::Part<'_>>;6] =MaybeUninit::uninit_array();
139+
letmut buf:[MaybeUninit<u8>; flt2dec::MAX_SIG_DIGITS] =
140+
[MaybeUninit::uninit(); flt2dec::MAX_SIG_DIGITS];
141+
letmut parts:[MaybeUninit<numfmt::Part<'_>>;6] =[MaybeUninit::uninit();6];
140142
let formatted = flt2dec::to_shortest_exp_str(
141143
flt2dec::strategy::grisu::format_shortest,
142144
*num,

‎core/src/iter/adapters/copied.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ where
202202
T:Copy,
203203
{
204204
fnspec_next_chunk(&mutself) ->Result<[T;N], array::IntoIter<T,N>>{
205-
letmut raw_array =MaybeUninit::uninit_array();
205+
letmut raw_array =[const{MaybeUninit::uninit()};N];
206206

207207
let len =self.len();
208208

‎core/src/iter/adapters/filter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ where
6464
fnnext_chunk<constN:usize>(
6565
&mutself,
6666
) ->Result<[Self::Item;N], array::IntoIter<Self::Item,N>>{
67-
letmut array:[MaybeUninit<Self::Item>;N] =MaybeUninit::uninit_array();
67+
letmut array:[MaybeUninit<Self::Item>;N] =[const{MaybeUninit::uninit()};N];
6868

6969
structGuard<'a,T>{
7070
array:&'amut[MaybeUninit<T>],

‎core/src/iter/adapters/filter_map.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
fnnext_chunk<constN:usize>(
6969
&mutself,
7070
) ->Result<[Self::Item;N], array::IntoIter<Self::Item,N>>{
71-
letmut array:[MaybeUninit<Self::Item>;N] =MaybeUninit::uninit_array();
71+
letmut array:[MaybeUninit<Self::Item>;N] =[const{MaybeUninit::uninit()};N];
7272

7373
structGuard<'a,T>{
7474
array:&'amut[MaybeUninit<T>],

‎core/src/iter/adapters/map_windows.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ impl<I: Iterator, const N: usize> MapWindowsInner<I, N> {
110110
impl<T,constN:usize>Buffer<T,N>{
111111
fntry_from_iter(iter:&mutimplIterator<Item =T>) ->Option<Self>{
112112
let first_half =crate::array::iter_next_chunk(iter).ok()?;
113-
let buffer =[MaybeUninit::new(first_half).transpose(),MaybeUninit::uninit_array()];
113+
let buffer =
114+
[MaybeUninit::new(first_half).transpose(),[const{MaybeUninit::uninit()};N]];
114115
Some(Self{ buffer,start:0})
115116
}
116117

@@ -204,7 +205,7 @@ impl<T, const N: usize> Buffer<T, N> {
204205
impl<T:Clone,constN:usize>CloneforBuffer<T,N>{
205206
fnclone(&self) ->Self{
206207
letmut buffer =Buffer{
207-
buffer:[MaybeUninit::uninit_array(),MaybeUninit::uninit_array()],
208+
buffer:[[const{MaybeUninit::uninit()};N],[const{MaybeUninit::uninit()};N]],
208209
start:self.start,
209210
};
210211
buffer.as_uninit_array_mut().write(self.as_array_ref().clone());

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp