about summary refs log tree commit diff
path: root/library/alloc/src/slice.rs
AgeCommit message (Collapse)AuthorLines
2022-04-14Remove use of `#[rustc_deprecated]`Jacob Pratt-1/+1
2022-04-05trivial cfg(bootstrap) changesPietro Albini-15/+13
2022-03-30Auto merge of #94963 - lcnr:inherent-impls-std, r=oli-obk,m-ou-sebors-2/+15
allow arbitrary inherent impls for builtin types in core Part of https://github.com/rust-lang/compiler-team/issues/487. Slightly adjusted after some talks with `@m-ou-se` about the requirements of `t-libs-api`. This adds a crate attribute `#![rustc_coherence_is_core]` which allows arbitrary impls for builtin types in core. For other library crates impls for builtin types should be avoided if possible. We do have to allow the existing stable impls however. To prevent us from accidentally adding more of these in the future, there is a second attribute `#[rustc_allow_incoherent_impl]` which has to be added to **all impl items**. This only supports impls for builtin types but can easily be extended to additional types in a future PR. This implementation does not check for overlaps in these impls. Perfectly checking that requires us to check the coherence of these incoherent impls in every crate, as two distinct dependencies may add overlapping methods. It should be easy enough to detect if it goes wrong and the attribute is only intended for use inside of std. The first two commits are mostly unrelated cleanups.
2022-03-30remove now unnecessary lang itemslcnr-2/+2
2022-03-30rework implementation for inherent impls for builtin typeslcnr-0/+13
2022-03-29cleanup some of the less terrifying library codeAria Beingessner-2/+2
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-1/+1
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.
2022-03-10Use implicit capture syntax in format_argsT-O-R-U-S-1/+1
This updates the standard library's documentation to use the new syntax. The documentation is worthwhile to update as it should be more idiomatic (particularly for features like this, which are nice for users to get acquainted with). The general codebase is likely more hassle than benefit to update: it'll hurt git blame, and generally updates can be done by folks updating the code if (and when) that makes things more readable with the new format. A few places in the compiler and library code are updated (mostly just due to already having been done when this commit was first authored).
2022-02-12Stabilise inherent_ascii_escape (FCP in #77174)ltdk-1/+1
2022-01-19Rollup merge of #89621 - digama0:patch-2, r=yaahcMatthias Krüger-1/+4
doc: guarantee call order for sort_by_cached_key `slice::sort_by_cached_key` takes a caching function `f: impl FnMut(&T) -> K`, which means that the order that calls to the caching function are made is user-visible. This adds a clause to the documentation to promise the current behavior, which is that `f` is called on all elements of the slice from left to right, unless the slice has len < 2 in which case `f` is not called. For example, this can be used to ensure that the following code is a correct way to involve the index of the element in the sort key: ```rust let mut index = 0; slice.sort_by_cached_key(|x| (my_key(index, x), index += 1).0); ```
2022-01-04Clarify that ordering is unspecifiedMario Carneiro-0/+2
2022-01-04Update wordingMario Carneiro-3/+3
2021-12-18Derive src pointers in sort drop guards from &TBen Kimock-3/+3
The src pointers in CopyOnDrop and InsertionHole used to be *mut T, and were derived via automatic conversion from &mut T. According to Stacked Borrows 2.1, this means that those pointers become invalidated by interior mutation in the comparison function. But there's no need for mutability in this code path. Thus, we can change the drop guards to use *const and derive those from &T.
2021-11-05Re-export `core::slice::EscapeAscii`mbartlett21-0/+2
2021-11-05Re-export `core::slice::SplitInclusive[Mut]`mbartlett21-0/+2
2021-10-09Add #[must_use] to string/char transformation methodsJohn Kugelman-0/+4
These methods could be misconstrued as modifying their arguments instead of returning new values. Where possible I made the note recommend a method that does mutate in place.
2021-10-07doc: guarantee call order for sort_by_cached_keyMario Carneiro-1/+2
`slice::sort_by_cached_key` takes a caching function `f: impl FnMut(&T) -> K`, which means that the order that calls to the caching function are made is user-visible. This adds a clause to the documentation to promise the current behavior, which is that `f` is called on all elements of the slice from left to right, unless the slice has len < 2 in which case `f` is not called.
2021-06-23Use HTTPS links where possibleSmitty-1/+1
2021-05-05alloc: Add unstable Cfg feature `no-global_oom_handling`John Ericson-2/+30
For certain sorts of systems, programming, it's deemed essential that all allocation failures be explicitly handled where they occur. For example, see Linus Torvald's opinion in [1]. Merely not calling global panic handlers, or always `try_reserving` first (for vectors), is not deemed good enough, because the mere presence of the global OOM handlers is burdens static analysis. One option for these projects to use rust would just be to skip `alloc`, rolling their own allocation abstractions. But this would, in my opinion be a real shame. `alloc` has a few `try_*` methods already, and we could easily have more. Features like custom allocator support also demonstrate and existing to support diverse use-cases with the same abstractions. A natural way to add such a feature flag would a Cargo feature, but there are currently uncertainties around how std library crate's Cargo features may or not be stable, so to avoid any risk of stabilizing by mistake we are going with a more low-level "raw cfg" token, which cannot be interacted with via Cargo alone. Note also that since there is no notion of "default cfg tokens" outside of Cargo features, we have to invert the condition from `global_oom_handling` to to `not(no_global_oom_handling)`. This breaks the monotonicity that would be important for a Cargo feature (i.e. turning on more features should never break compatibility), but it doesn't matter for raw cfg tokens which are not intended to be "constraint solved" by Cargo or anything else. To support this use-case we create a new feature, "global-oom-handling", on by default, and put the global OOM handler infra and everything else it that depends on it behind it. By default, nothing is changed, but users concerned about global handling can make sure it is disabled, and be confident that all OOM handling is local and explicit. For this first iteration, non-flat collections are outright disabled. `Vec` and `String` don't yet have `try_*` allocation methods, but are kept anyways since they can be oom-safely created "from parts", and we hope to add those `try_` methods in the future. [1]: https://lore.kernel.org/lkml/CAHk-=wh_sNLoz84AUUzuqXEsYH35u=8HV3vK-jbRbJ_B-JjGrg@mail.gmail.com/
2021-04-13Remove slice diagnostic itemCameron Steffen-1/+0
2021-03-27adjust documentation links for slice ascii case functions to use newer ↵Violet-2/+2
rustdoc link format
2021-03-27update links to make_ascii_lowercase for slice to point to methods on the ↵Violet-2/+2
same type, rather than on u8
2021-03-09convert slice doc link to intra-doc linksFrançois Mockers-5/+5
2021-02-25Convert primitives to use intra-doc linksJoshua Nelson-11/+11
2021-02-23Rollup merge of #82128 - anall:feature/add_diagnostic_items, r=davidtwcoDylan DPC-0/+1
add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice This is adding diagnostic items to be used by rust-lang/rust-clippy#6730, but my understanding is the clippy-side change does need to be done over there since I am adding a new clippy feature. Add diagnostic items to the following types: OsString (os_string_type) PathBuf (path_buf_type) Owned (to_owned_trait) As well as the to_vec method on slice/[T]
2021-02-15requested/proposed changesAndrea Nall-1/+1
2021-02-15add diagnostic itemsAndrea Nall-0/+1
Add diagnostic items to the following types: OsString (os_string_type) PathBuf (path_buf_type) Owned (to_owned_trait) As well as the to_vec method on slice/[T]
2021-02-12Rename `Range::ensure_subset_of` to `slice::range`dylni-0/+2
2020-12-31Replace the tracking issue for the slice_group_by featureClément Renault-1/+1
2020-12-10Fix the fmt issuesClément Renault-2/+2
2020-12-10Use none as the issue instead of 0Clément Renault-1/+1
2020-12-10Introduce the GroupBy and GroupByMut IteratorsClément Renault-0/+2
2020-12-04 Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate`Tim Diekmann-12/+12
2020-11-22Change slice::to_vec to not use extend_from_slicekadmin-7/+59
This also required adding a loop guard in case clone panics Add specialization for copy There is a better version for copy, so I've added specialization for that function and hopefully that should speed it up even more. Switch FromIter<slice::Iter> to use `to_vec` Test different unrolling version for to_vec Revert to impl From benchmarking, it appears this version is faster
2020-11-18Add support for custom allocators in `Vec`Tim Diekmann-8/+33
2020-10-23Rollup merge of #77969 - ryan-scott-dev:bigo-notation-consistency, r=m-ou-seYuki Okushi-7/+7
Doc formating consistency between slice sort and sort_unstable, and big O notation consistency Updated documentation for slice sorting methods to be consistent between stable and unstable versions, which just ended up being minor formatting differences. I also went through and updated any doc comments with big O notation to be consistent with #74010 by italicizing them rather than having them in a code block.
2020-10-15Made slice sort documentation consistent between stable and unstable versionsRyan Scott-7/+7
2020-09-18Move `slice::check_range` to `RangeBounds`dylni-2/+0
2020-09-16Rollup merge of #75026 - JulianKnodt:array_windows, r=AmanieuTyler Mandry-0/+2
Add array_windows fn This mimicks the functionality added by array_chunks, and implements a const-generic form of `windows`. It makes egregious use of `unsafe`, but by necessity because the array must be re-interpreted as a slice of arrays, and unlike array_chunks this cannot be done by casting the original array once, since each time the index is advanced it needs to move one element, not `N`. I'm planning on adding more tests, but this should be good enough as a premise for the functionality. Notably: should there be more functions overwritten for the iterator implementation/in general? ~~I've marked the issue as #74985 as there is no corresponding exact issue for `array_windows`, but it's based of off `array_chunks`.~~ Edit: See Issue #75027 created by @lcnr for tracking issue ~~Do not merge until I add more tests, please.~~ r? @lcnr
2020-09-16Add array window fnkadmin-0/+2
Updated issue to #75027 Update to rm oob access And hopefully fix docs as well Fixed naming conflict in test Fix test which used 1-indexing Nth starts from 0, woops Fix a bunch of off by 1 errors See https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=757b311987e3fae1ca47122969acda5a Add even more off by 1 errors And also write `next` and `next_back` in terms of `nth` and `nth_back`. Run fmt Fix forgetting to change fn name in test add nth_back test & document unsafe Remove as_ref().unwrap() Documented occurrences of unsafe, noting what invariants are maintained
2020-09-15fix slice::check_range aliasing problemsRalf Jung-0/+2
2020-09-04Re-export ArrayChunksMut in allocJosh Stone-0/+2
2020-08-21Use intra-doc-links in `alloc`LeSeulArtichaut-7/+3
2020-08-01add tracking issueBastian Kauschke-1/+1
2020-07-30liballoc export ArrayChunksBastian Kauschke-0/+2
2020-07-27mv std libs to library/mark-0/+1069