about summary refs log tree commit diff
path: root/library/core/src/array
AgeCommit message (Collapse)AuthorLines
2025-09-26Update CURRENT_RUSTC_VERSION post-bumpMark Rousskov-3/+3
2025-09-14Note some previous attempts to change the Default impl for `[T; 0]`Zalathar-0/+5
2025-09-12Constify Eq, Ord, PartialOrdEvgenii Zheltonozhskii-17/+29
2025-09-04Rollup merge of #146054 - joboet:array-repeat-must_use, r=ibraheemdevStuart Cook-0/+1
add `#[must_use]` to `array::repeat`
2025-09-03Rollup merge of #145279 - clarfonthey:const-convert-initial, r=tgross35Stuart Cook-9/+17
Constify conversion traits (part 1) This is the first part of rust-lang/rust#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` There are a few methods that are intrinsically tied to these traits which I've included in the feature. Particularly, those which are wrappers over `AsRef`: * `ByteStr::new` (unstable under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as rust-lang/rust#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? ``@tgross35`` (who mostly already reviewed this)
2025-09-01Constify conversion traitsltdk-9/+17
2025-08-31add `#[must_use]` to `array::repeat`joboet-0/+1
2025-08-30Rollup merge of #145465 - Kivooeo:stabilize-array_repeat, r=joboetStuart Cook-3/+1
Stabilize `array_repeat` feature This closes [tracking issue](https://github.com/rust-lang/rust/issues/126695) and stabilises `array::repeat`
2025-08-26remove deprecated Error::description in implsMarijn Schouten-8/+2
2025-08-21Rollup merge of #143383 - fee1-dead-contrib:push-mstmlwuskxyy, r=dtolnayJacob Pratt-4/+4
stabilize `const_array_each_ref` cc rust-lang/rust#133289, needs FCP.
2025-08-15stabilize array repeatKivooeo-3/+1
2025-08-06tidyBoxy-2/+2
2025-08-03Use `as_array` in PartialEq for arraysScott McMurray-16/+12
2025-07-21Constify Try, From, TryFromEvgenii Zheltonozhskii-1/+2
2025-07-15constify `Index` trait and its slice implsOli Scherer-4/+6
2025-07-03stabilize `const_array_each_ref`Deadbeef-4/+4
2025-07-03simplify receivers for some array method callsMarijn Schouten-4/+4
2025-07-01Update version placeholdersJosh Stone-2/+2
2025-05-26impl `Default` for `array::IntoIter`Deadbeef-0/+7
2025-05-24Rollup merge of #140066 - thaliaarchi:const-array-as-mut-slice, r=jhprattGuillaume Gomez-1/+1
Stabilize `<[T; N]>::as_mut_slice` as `const` This is trivial and has no design questions. Tracked in https://github.com/rust-lang/rust/issues/133333. r? libs-api
2025-05-13Add `#[must_use]` to Array::mapJulian Knodt-0/+1
The output of Array::map is intended to be an array of the same size, and does not modify the original in place nor is it intended for side-effects. Thus, under normal circumstances it should be consumed. See [discussion](https://internals.rust-lang.org/t/array-map-annotate-with-must-use/22813/26). Attaching to tracking issue #75243
2025-04-20Stabilize <[T; N]>::as_mut_slice as constThalia Archibald-1/+1
2025-04-11Auto merge of #139430 - scottmcm:polymorphic-array-into-iter, r=cuviperbors-141/+365
Polymorphize `array::IntoIter`'s iterator impl Today we emit all the iterator methods for every different array width. That's wasteful since the actual array length never even comes into it -- the indices used are from the separate `alive: IndexRange` field, not even the `N` const param. This PR switches things so that an `array::IntoIter<T, N>` stores a `PolymorphicIter<[MaybeUninit<T>; N]>`, which we *unsize* to `PolymorphicIter<[MaybeUninit<T>]>` and call methods on that non-`Sized` type for all the iterator methods. That also necessarily makes the layout consistent between the different lengths of arrays, because of the unsizing. Compare that to today <https://rust.godbolt.org/z/Prb4xMPrb>, where different widths can't even be deduped because the offset to the indices is different for different array widths.
2025-04-09PR feedbackScott McMurray-8/+8
2025-04-05Polymorphize `array::IntoIter`'s iterator implScott McMurray-141/+365
2025-03-29Promise `array::from_fn` in generated in order of increasing indicesScott McMurray-6/+27
2025-03-06Remove #[cfg(not(test))] gates in coreThalia Archibald-1/+0
These gates are unnecessary now that unit tests for `core` are in a separate package, `coretests`, instead of in the same files as the source code. They previously prevented the two `core` versions from conflicting with each other.
2025-01-24Rollup merge of #135489 - RalfJung:TryFromSliceError, r=tgross35Matthias Krüger-1/+0
remove pointless allowed_through_unstable_modules on TryFromSliceError This got added in https://github.com/rust-lang/rust/pull/132482 but the PR does not explain why. `@lukas-code` do you still remember? Also Cc `@Noratrieb` as reviewer of that PR. If I understand the issue description correctly, all paths under which this type is exported are stable now: `core::array::TryFromSliceError` and `std::array::TryFromSliceError`. If that is the case, we shouldn't have the attribute; it's a terrible hack that should only be used when needed to maintain backward compatibility. Getting some historic information right is IMO *not* sufficient justification to risk accidentally exposing this type via more unstable paths today or in the future.
2025-01-20core: add `#![warn(unreachable_pub)]`Urgau-1/+1
2025-01-14remove pointless allowed_through_unstable_modules on TryFromSliceErrorRalf Jung-1/+0
2025-01-11Add inherent versions of MaybeUninit methods for slicesltdk-7/+5
2024-11-26Add '<[T]>::as_array', '<[T]>::as_mut_array', '<*const [T]>::as_array', and ↵Gabriel Bjørnager Jensen-16/+4
'<*mut [T]>::as_mut_array' conversion methods;
2024-11-23Rollup merge of #133332 - bjoernager:const-array-as-mut-slice, r=jhpratt许杰友 Jieyou Xu (Joe)-1/+2
Mark `<[T; N]>::as_mut_slice` with the `const` specifier. Tracking issue: #133333 `<[T; N]>::as_mut_slice` can have the `const` specifier without any changes to the function body.
2024-11-22Mark '<[T; N]>::as_mut_slice' as 'const';Gabriel Bjørnager Jensen-1/+2
2024-11-21Mark and implement 'each_ref' and 'each_mut' in '[T; N]' as const;Gabriel Bjørnager Jensen-4/+30
2024-11-03Auto merge of #132458 - RalfJung:rustc-const-unstable, r=Amanieubors-2/+0
get rid of a whole bunch of unnecessary rustc_const_unstable attributes In general, when a `const fn` is still unstable, it doesn't need a `#[rustc_const_unstable]` attribute. The only exception is functions that internally use things that can't be used in stable const fn yet. So this gets rid of a whole bunch of `#[rustc_const_unstable]` in libcore.
2024-11-02get rid of a whole bunch of unnecessary rustc_const_unstable attributesRalf Jung-2/+0
2024-11-02fix some stability annotationsLukas Markeffsky-2/+3
2024-10-15update bootstrap configsJosh Stone-1/+0
2024-10-15replace placeholder versionJosh Stone-1/+1
(cherry picked from commit 567fd9610cbfd220844443487059335d7e1ff021)
2024-10-12Stabilize `const_option`Trevor Gross-1/+0
This makes the following API stable in const contexts: impl<T> Option<T> { pub const fn as_mut(&mut self) -> Option<&mut T>; pub const fn expect(self, msg: &str) -> T; pub const fn unwrap(self) -> T; pub const unsafe fn unwrap_unchecked(self) -> T; pub const fn take(&mut self) -> Option<T>; pub const fn replace(&mut self, value: T) -> Option<T>; } impl<T> Option<&T> { pub const fn copied(self) -> Option<T> where T: Copy; } impl<T> Option<&mut T> { pub const fn copied(self) -> Option<T> where T: Copy; } impl<T, E> Option<Result<T, E>> { pub const fn transpose(self) -> Result<Option<T>, E> } impl<T> Option<Option<T>> { pub const fn flatten(self) -> Option<T>; } The following functions make use of the unstable `const_precise_live_drops` feature: - `expect` - `unwrap` - `unwrap_unchecked` - `transpose` - `flatten` Fixes: <https://github.com/rust-lang/rust/issues/67441>
2024-10-09stabilize `{slice,array}::from_mut`ultrabear-1/+2
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-08-31Fixed more typos in library/coreranger-ross-1/+1
2024-08-09fix: Ensure `Guard`'s `drop` method is removed at `opt-level=s` for `Copy` typesburlinchen-0/+1
Added `#[inline]` to the `drop` method in the `Guard` implementation to ensure that the method is removed by the compiler at optimization level `opt-level=s` for `Copy` types. This change aims to align the method's behavior with optimization expectations and ensure it does not affect performance.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-9/+5
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-4/+6
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-06-24Replace `MaybeUninit::uninit_array()` with array repeat expression.Kevin Reid-6/+6
This is possible now that inline const blocks are stable; the idea was even mentioned as an alternative when `uninit_array()` was added: <https://github.com/rust-lang/rust/pull/65580#issuecomment-544200681> > 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];` Const array repetition and inline const blocks are now stable (in the next release), so that circumstance has come to pass, and we no longer have reason to want `uninit_array()` other than convenience. Therefore, let’s evaluate the inconvenience by not using `uninit_array()` in the standard library, before potentially deleting it entirely.
2024-06-19core: add tracking issue for `array::repeat`joboet-1/+1
2024-06-19core: simplify implementation of `array::repeat`, address other nitsjoboet-18/+9