about summary refs log tree commit diff
path: root/library/core/src/slice
AgeCommit message (Collapse)AuthorLines
2025-10-01Change ArrayWindows to use a sliceCameron Steffen-47/+22
2025-09-23Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercotebors-6/+6
Add panic=immediate-abort MCP: https://github.com/rust-lang/compiler-team/issues/909 This adds a new panic strategy, `-Cpanic=immediate-abort`. This panic strategy essentially just codifies use of `-Zbuild-std-features=panic_immediate_abort`. This PR is intended to just set up infrastructure, and while it will change how the compiler is invoked for users of the feature, there should be no other impacts. In many parts of the compiler, `PanicStrategy::ImmediateAbort` behaves just like `PanicStrategy::Abort`, because actually most parts of the compiler just mean to ask "can this unwind?" so I've added a helper function so we can say `sess.panic_strategy().unwinds()`. The panic and unwind strategies have some level of compatibility, which mostly means that we can pre-compile the sysroot with unwinding panics then the sysroot can be linked with aborting panics later. The immediate-abort strategy is all-or-nothing, enforced by `compiler/rustc_metadata/src/dependency_format.rs` and this is tested for in `tests/ui/panic-runtime/`. We could _technically_ be more compatible with the other panic strategies, but immediately-aborting panics primarily exist for users who want to eliminate all the code size responsible for the panic runtime. I'm open to other use cases if people want to present them, but not right now. This PR is already large. `-Cpanic=immediate-abort` sets both `cfg(panic = "immediate-abort")` _and_ `cfg(panic = "abort")`. bjorn3 pointed out that people may be checking for the abort cfg to ask if panics will unwind, and also the sysroot feature this is replacing used to require `-Cpanic=abort` so this seems like a good back-compat step. At least for the moment. Unclear if this is a good idea indefinitely. I can imagine this being confusing. The changes to the standard library attributes are purely mechanical. Apart from that, I removed an `unsafe` we haven't needed for a while since the `abort` intrinsic became safe, and I've added a helpful diagnostic for people trying to use the old feature. To test that `-Cpanic=immediate-abort` conflicts with other panic strategies, I've beefed up the core-stubs infrastructure a bit. There is now a separate attribute to set flags on it. I've added a test that this produces the desired codegen, called `tests/run-make-cargo/panic-immediate-abort-codegen/` and also a separate run-make-cargo test that checks that we can build a binary.
2025-09-22assert_unsafe_precondition: fix some incorrect check_language_ubRalf Jung-1/+1
2025-09-21Change the cfg to a dashBen Kimock-6/+6
2025-09-21Add panic=immediate-abortBen Kimock-6/+6
2025-09-12Constify Eq, Ord, PartialOrdEvgenii Zheltonozhskii-12/+31
2025-09-10Rollup merge of #144765 - Qelxiros:range-inclusive-last, r=jhprattMatthias Krüger-0/+41
inclusive `Range`s: change `end` to `last` Tracking issue: rust-lang/rust#125687 ACP: rust-lang/libs-team#511
2025-09-08change end to lastJeremy Smart-0/+41
2025-09-06clean up some old const trait impl syntaxNathaniel McCallum-3/+2
2025-08-21Consolidate panicking functions in `slice/index.rs`Karl Meakin-97/+103
Consolidate all the panicking functions in `slice/index.rs` to use a single `slice_index_fail` function, similar to how it is done in `str/traits.rs`.
2025-08-14Rollup merge of #144515 - scottmcm:ptr_cast_array, r=Mark-SimulacrumGuillaume Gomez-10/+10
Implement `ptr_cast_array` ACP: https://github.com/rust-lang/libs-team/issues/602 Tracking Issue: https://github.com/rust-lang/rust/issues/144514
2025-08-06tidyBoxy-9/+9
2025-08-06replace version placeholderBoxy-1/+1
2025-08-04Rollup merge of #142205 - paolobarbolini:const_swap_with_slice-impl, ↵Stuart Cook-1/+2
r=Mark-Simulacrum Mark `slice::swap_with_slice` unstably const Tracking issue rust-lang/rust#142204
2025-07-29Rollup merge of #144575 - xonx4l:patch-6, r=scottmcmStuart Cook-1/+1
fixed typo chunks->as_chunks Fixes rust-lang/rust#144555 info-: fix typo chunks -> as_chunks This now take us to as_chunks page when clicking on as_chunks link and not to chunks . Thanks .
2025-07-28fixed typo chunks->as_chunksxonx-1/+1
2025-07-27Remove `[T]::array_chunks(_mut)`Scott McMurray-325/+0
2025-07-26Use `cast_array` in coreScott McMurray-10/+10
2025-07-23Hint that choose_pivot returns index in boundsKornel-10/+10
2025-07-18Rollup merge of #143382 - fee1-dead-contrib:push-trrymlzqmmoz, r=jhprattMatthias Krüger-1/+2
stabilize `const_slice_reverse` cc rust-lang/rust#135120, needs FCP.
2025-07-17Make slices `[const] PartialEq`Oli Scherer-7/+15
2025-07-15constify `Index` trait and its slice implsOli Scherer-4/+6
2025-07-15constify some methods using `SliceIndex`Oli Scherer-8/+12
2025-07-15constify `SliceIndex` traitOli Scherer-11/+24
2025-07-14Rollup merge of #143875 - fee1-dead-contrib:push-zvqrmzrprpzt, r=compiler-errorsJakub Beránek-2/+2
update issue number for `const_trait_impl` r? project-const-traits cc rust-lang/rust#67792 rust-lang/rust#143874
2025-07-13update issue number for `const_trait_impl`Deadbeef-2/+2
2025-07-13Rollup merge of #143554 - okaneco:const_slice_rotate, r=Amanieu,tgross35Matthias Krüger-9/+21
slice: Mark `rotate_left`, `rotate_right` unstably const Tracking issue rust-lang/rust#143812 - Add the const unstable `const_slice_rotate` feature - Mark `<[T]>::rotate_left` and `<[T]>::rotate_right` as const unstable The internal rotate functions use [`<*mut T>::replace`](https://doc.rust-lang.org/stable/core/primitive.pointer.html#method.replace) and [`ptr::swap_nonoverlapping`](https://doc.rust-lang.org/stable/core/ptr/fn.swap_nonoverlapping.html) which were const-stabilized in 1.88. Two changes were needed in the `rotate.rs` module to make these functions const: 1. A usage of `cmp::min` was replaced with a local function implementation of [`Ord::min`](https://doc.rust-lang.org/1.88.0/src/core/cmp.rs.html#1048-1053). 2. A `for start in 1..gcd` loop was changed to a while loop with an increment variable. This needs libs-api approval and cc-ing const-eval.
2025-07-11slice: Mark `rotate_left`, `rotate_right` unstably constokaneco-9/+21
2025-07-10Rollup merge of #143265 - scottmcm:mention-as-chunks, r=ibraheemdevTrevor Gross-0/+32
Mention as_chunks in the docs for chunks and `as_rchunks_mut` from `rchunks_exact_mut`, and such. As suggested in https://github.com/rust-lang/rust/issues/76354#issuecomment-3015376438 (but does not close that issue).
2025-07-07Make `Default` const and add some `const Default` implsEsteban Küber-2/+4
Full list of `impl const Default` types: - () - bool - char - Cell - std::ascii::Char - usize - u8 - u16 - u32 - u64 - u128 - i8 - i16 - i32 - i64 - i128 - f16 - f32 - f64 - f128 - std::marker::PhantomData<T> - Option<T> - std::iter::Empty<T> - std::ptr::Alignment - &[T] - &mut [T] - &str - &mut str - String - Vec<T>
2025-07-05use `div_ceil` instead of manual logicFolkert de Vries-2/+2
2025-07-05use `is_multiple_of` instead of manual moduloFolkert de Vries-5/+5
2025-07-03stabilize `const_slice_reverse`Deadbeef-1/+2
2025-07-01Update version placeholdersJosh Stone-2/+2
2025-06-30Mention as_chunks in the docs for chunksScott McMurray-0/+32
2025-06-21Rollup merge of #142787 - samueltardieu:diag-items-for-clippy, ↵Matthias Krüger-0/+1
r=Manishearth,Urgau Add diagnostic items for Clippy Clippy still uses some paths to access items from the standard library. Adding the missing diagnostic items allows removing the last remaining paths. Closes rust-lang/rust-clippy#5393
2025-06-20Rollup merge of #142331 - deven:trim_prefix_suffix, r=AmanieuTrevor Gross-0/+83
Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types. Implements `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types, which remove at most one occurrence of a prefix/suffix while always returning a string/slice (rather than Option), enabling easy method chaining. ## Tracking issue rust-lang/rust#142312 ## API ```rust impl str { pub fn trim_prefix<P: Pattern>(&self, prefix: P) -> &str; pub fn trim_suffix<P: Pattern>(&self, suffix: P) -> &str where for<'a> P::Searcher<'a>: ReverseSearcher<'a>; } impl<T> [T] { pub fn trim_prefix<P: SlicePattern<Item = T> + ?Sized>(&self, prefix: &P) -> &[T] where T: PartialEq; pub fn trim_suffix<P: SlicePattern<Item = T> + ?Sized>(&self, suffix: &P) -> &[T] where T: PartialEq; } ``` ## Examples ```rust // Method chaining assert_eq!(" <https://example.com/> ".trim().trim_prefix('<').trim_suffix('>').trim(), "https://example.com/"); // Slices let v = &[10, 40, 30]; assert_eq!(v.trim_prefix(&[10]), &[40, 30][..]); ``` ## ACP Originally proposed in rust-lang/libs-team#597
2025-06-20Add diagnostic items for ClippySamuel Tardieu-0/+1
2025-06-15Get rid of `EscapeDebugInner`.Markus Reiter-1/+1
2025-06-13Auto merge of #142432 - matthiaskrgr:rollup-ziuls9y, r=matthiaskrgrbors-0/+7
Rollup of 6 pull requests Successful merges: - rust-lang/rust#138016 (Added `Clone` implementation for `ChunkBy`) - rust-lang/rust#141162 (refactor `AttributeGate` and `rustc_attr!` to emit notes during feature checking) - rust-lang/rust#141474 (Add `ParseMode::Diagnostic` and fix multiline spans in diagnostic attribute lints) - rust-lang/rust#141947 (Specify that "option-like" enums must be `#[repr(Rust)]` to be ABI-compatible with their non-1ZST field.) - rust-lang/rust#142252 (Improve clarity of `core::sync::atomic` docs about "Considerations" in regards to CAS operations) - rust-lang/rust#142337 (miri: add flag to suppress float non-determinism) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-12Rollup merge of #138016 - nwoods-cimpress:slice_chunkby_clone, r=dtolnayMatthias Krüger-0/+7
Added `Clone` implementation for `ChunkBy` Added `Clone` implementation for `ChunkBy` Closes rust-lang/rust#137969.
2025-06-12chore(doctest): Remove redundant blank linesShun Sakai-1/+0
2025-06-11Add trim_prefix and trim_suffix for slice and str.Deven T. Corzine-0/+83
Implements `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types which remove at most one occurrence of a prefix/suffix while always returning a string/slice (rather than Option), enabling easy method chaining.
2025-06-09Mark `core::slice::memchr` as `#[doc(hidden)]`Alona Enraght-Moony-0/+1
It's purely internal, and not intended to be a public API, even on nightly. This stops it showing up and being misleading in rustdoc search. It also mirrors the (also internal) `core::slice::sort` module.
2025-06-08Mark `slice::swap_with_slice` unstably constPaolo Barbolini-1/+2
2025-06-05Stabilize `const_eq_ignore_ascii_case`Paolo Barbolini-1/+1
2025-06-02Remove bootstrap cfgs from library/Josh Stone-53/+4
2025-06-01Rollup merge of #141224 - RalfJung:no-objects, r=traviscrossGuillaume Gomez-10/+10
terminology: allocated object → allocation Rust does not have "objects" in memory so "allocated object" is a somewhat odd name. I am not sure where the term comes from. "object" has been used to refer to allocations already [in 1.0 docs](https://doc.rust-lang.org/1.0.0/std/primitive.pointer.html#method.offset); this was apparently later changed to "allocated object". "Allocation" is already the terminology used in Miri and in the [UCG](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#allocation). We should properly move to that terminology, and avoid any confusion about whether Rust has an object memory model. (It does not. Memory contains untyped bytes.) Cc ``@rust-lang/opsem`` ``@rust-lang/lang``
2025-05-31terminology: allocated object → allocationRalf Jung-10/+10
2025-05-30`slice.get(i)` should use a slice projection in MIR, like `slice[i]` doesScott McMurray-7/+49