about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2022-08-22Rollup merge of #93162 - camsteffen:std-prim-docs, r=Mark-SimulacrumDylan DPC-97/+7
Std module docs improvements My primary goal is to create a cleaner separation between primitive types and primitive type helper modules (fixes #92777). I also changed a few header lines in other top-level std modules (seen at https://doc.rust-lang.org/std/) for consistency. Some conventions used/established: * "The \`Box\<T>` type for heap allocation." - if a module mainly provides a single type, name it and summarize its purpose in the module header * "Utilities for the _ primitive type." - this wording is used for the header of helper modules * Documentation for primitive types themselves are removed from helper modules * provided-by-core functionality of primitive types is documented in the primitive type instead of the helper module (such as the "Iteration" section in the slice docs) I wonder if some content in `std::ptr` should be in `pointer` but I did not address this.
2022-08-21Extra documentation for new formatting featureIsaac Cloos-0/+2
High traffic macros should detail this helpful addition.
2022-08-21Rollup merge of #100822 - WaffleLapkin:no_offset_question_mark, r=scottmcmMatthias Krüger-14/+14
Replace most uses of `pointer::offset` with `add` and `sub` As PR title says, it replaces `pointer::offset` in compiler and standard library with `pointer::add` and `pointer::sub`. This generally makes code cleaner, easier to grasp and removes (or, well, hides) integer casts. This is generally trivially correct, `.offset(-constant)` is just `.sub(constant)`, `.offset(usized as isize)` is just `.add(usized)`, etc. However in some cases we need to be careful with signs of things. r? ````@scottmcm```` _split off from #100746_
2022-08-21Rollup merge of #100821 - WaffleLapkin:ptr_add_docs, r=scottmcmMatthias Krüger-7/+7
Make some docs nicer wrt pointer offsets This PR replaces `pointer::offset` with `pointer::add` and similarly `.cast().wrapping_add().cast()` with `.wrapping_byte_add()` **in docs**. r? ``````@scottmcm`````` _split off from #100746_
2022-08-21Make some docs nicer wrt pointer offsetsMaybe Waffle-7/+7
2022-08-21Replace most uses of `pointer::offset` with `add` and `sub`Maybe Waffle-14/+14
2022-08-20Improve primitive/std docs separation and headersCameron Steffen-97/+7
2022-08-21Remove useless pointer castMaybe Waffle-1/+1
2022-08-20Auto merge of #100810 - matthiaskrgr:rollup-xep778s, r=matthiaskrgrbors-4/+23
Rollup of 9 pull requests Successful merges: - #97963 (net listen backlog set to negative on Linux.) - #99935 (Reenable disabled early syntax gates as future-incompatibility lints) - #100129 (add miri-test-libstd support to libstd) - #100500 (Ban references to `Self` in trait object substs for projection predicates too.) - #100636 (Revert "Revert "Allow dynamic linking for iOS/tvOS targets."") - #100718 ([rustdoc] Fix item info display) - #100769 (Suggest adding a reference to a trait assoc item) - #100777 (elaborate how revisions work with FileCheck stuff in src/test/codegen) - #100796 (Refactor: remove unnecessary string searchings) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-08-20Rollup merge of #99544 - dylni:expose-utf8lossy, r=Mark-SimulacrumMatthias Krüger-8/+11
Expose `Utf8Lossy` as `Utf8Chunks` This PR changes the feature for `Utf8Lossy` from `str_internals` to `utf8_lossy` and improves the API. This is done to eventually expose the API as stable. Proposal: rust-lang/libs-team#54 Tracking Issue: #99543
2022-08-20Expose `Utf8Lossy` as `Utf8Chunks`dylni-8/+11
2022-08-18clarify lib.rs attribute structureRalf Jung-5/+4
2022-08-18add some Miri-only testsRalf Jung-0/+19
2022-08-18add miri-test-libstd support to libstdRalf Jung-0/+1
2022-08-13address review comments, add tracking issueThe 8472-7/+8
2022-08-13add Vec::push_within_capacity - fallible, does not allocateThe8472-0/+44
2022-08-12Adjust cfgsMark Rousskov-3/+3
2022-08-10Guarantee `try_reserve` preserves the contents on errorYOSHIOKA Takuma-4/+8
Update doc comments to make the guarantee explicit. However, some implementations does not have the statement though. * `HashMap`, `HashSet`: require guarantees on hashbrown side. * `PathBuf`: simply redirecting to `OsString`. Fixes #99606.
2022-07-27Auto merge of #98553 - the8472:next_chunk_opt, r=Mark-Simulacrumbors-2/+43
Optimized vec::IntoIter::next_chunk impl ``` x86_64v1, default test vec::bench_next_chunk ... bench: 696 ns/iter (+/- 22) x86_64v1, pr test vec::bench_next_chunk ... bench: 309 ns/iter (+/- 4) znver2, default test vec::bench_next_chunk ... bench: 17,272 ns/iter (+/- 117) znver2, pr test vec::bench_next_chunk ... bench: 211 ns/iter (+/- 3) ``` On znver2 the default impl seems to be slow due to different inlining decisions. It goes through `core::array::iter_next_chunk` which has a deep call tree.
2022-07-26Auto merge of #99574 - durin42:allocator-patch-redux, r=nikicbors-1/+4
codegen: use new {re,de,}allocator annotations in llvm This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. r? `@nikic`
2022-07-26Optimized vec::IntoIter::next_chunk implThe 8472-2/+43
``` test vec::bench_next_chunk ... bench: 696 ns/iter (+/- 22) x86_64v1, pr test vec::bench_next_chunk ... bench: 309 ns/iter (+/- 4) znver2, default test vec::bench_next_chunk ... bench: 17,272 ns/iter (+/- 117) znver2, pr test vec::bench_next_chunk ... bench: 211 ns/iter (+/- 3) ``` The znver2 default impl seems to be slow due to inlining decisions. It goes through `core::array::iter_next_chunk` which has a deeper call tree.
2022-07-26codegen: use new {re,de,}allocator annotations in llvmAugie Fackler-1/+4
This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. While we're here, we also emit allocator attributes on __rust_alloc_zeroed. This should allow LLVM to perform more optimizations for zeroed blocks, and probably fixes #90032. [This comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157) mentions "weird UB-like behaviour with bitvec iterators in rustc_data_structures" so we may need to back this change out if things go wrong. The new test cases require LLVM 15, so we copy them into LLVM 14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-26Rollup merge of #98710 - mojave2:string, r=JohnTitorYuki Okushi-5/+5
correct the output of a `capacity` method example The output of this example in std::alloc is different from which shown in the comment. I have tested it on both Linux and Windows.
2022-07-24Support vec zero-alloc optimization for tuples and byte arraysAngelicosPhosphoros-17/+46
* Implement IsZero trait for tuples up to 8 IsZero elements; * Implement IsZero for u8/i8, leading to implementation of it for arrays of them too; * Add more codegen tests for this optimization. * Lower size of array for IsZero trait because it fails to inline checks
2022-07-22Remove redundant lifetime bound from `impl Borrow for Cow`Frank Steffahn-1/+0
The lifetime bound `B::Owned: 'a` is redundant and doesn't make a difference, because `Cow<'a, B>` comes with an implicit `B: 'a`, and associated types will outlive lifetimes outlived by the `Self` type (and all the trait's generic parameters, of which there are none in this case), so the implicit `B: 'a` implies `B::Owned: 'a` anyway. The explicit lifetime bound here does however end up in documentation, and that's confusing in my opinion, so let's remove it ^^
2022-07-21Box::from(slice): Clarify that contents are copiedAlan Wu-1/+1
A colleague mentioned that they interpreted the old text as saying that only the pointer and the length are copied. Add a clause so it is more clear that the pointed to contents are also copied.
2022-07-21Rollup merge of #99413 - steffahn:btree_dropck, r=m-ou-seMatthias Krüger-4/+26
Add `PhantomData` marker for dropck to `BTreeMap` closes #99408
2022-07-18Rollup merge of #99198 - RalfJung:alloc-null-ptr, r=JohnTitorDylan DPC-1/+4
add missing null ptr check in alloc example `alloc` can return null on OOM, if I understood correctly. So we should never just deref a pointer we get from `alloc`.
2022-07-18Add `PhantomData` marker for dropck to `BTreeMap`Frank Steffahn-4/+26
closes #99408
2022-07-16Rollup merge of #99317 - yanchith:borrow-vec-ta-as-slice-t, r=Mark-SimulacrumMatthias Krüger-2/+2
Borrow Vec<T, A> as [T] Hello all, When `Vec` was parametrized with `A`, the `Borrow` impls were omitted and currently `Vec<T, A>` can't be borrowed as `[T]`. This PR fixes that. This was probably missed, because the `Borrow` impls are in a different file - `src/alloc/slice.rs`. We briefly discussed this here: https://github.com/rust-lang/wg-allocators/issues/96 and I was told to go ahead and make a PR :) I tested this by building the toolchain and building my code that needed the `Borrow` impl against it, but let me know if I should add any tests to this PR.
2022-07-16Parametrize a few more thingsyanchith-16/+19
2022-07-16Mark lifetimes explicitlyyanchith-10/+10
2022-07-16Parametrize BinaryHeap with Allocatoryanchith-45/+111
2022-07-16Borrow Vec<T, A> as [T]yanchith-2/+2
2022-07-16Rollup merge of #99277 - joshtriplett:stabilize-core-cstr-alloc-cstring, ↵Yuki Okushi-9/+7
r=Mark-Simulacrum Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friends Stabilize the `core_c_str` and `alloc_c_string` feature gates. Change `std::ffi` to re-export these types rather than creating type aliases, since they now have matching stability.
2022-07-16Rollup merge of #99270 - rhysd:issue-99269, r=Mark-SimulacrumYuki Okushi-0/+1
Add `#[must_use]` to `Box::from_raw` Fixes #99269
2022-07-15Stabilize `core::ffi::CStr`, `alloc::ffi::CString`, and friendsJosh Triplett-9/+7
Stabilize the `core_c_str` and `alloc_c_string` feature gates. Change `std::ffi` to re-export these types rather than creating type aliases, since they now have matching stability.
2022-07-15add `#[must_use]` to `Box::from_raw`rhysd-0/+1
2022-07-15Rollup merge of #99113 - WaffleLapkin:arc_simplify, r=Mark-SimulacrumDylan DPC-12/+11
Simplify [a]rc code a little Nothing interesting, just make [a]rc code a little nicer by using `byte_sub` and `let`-`else`.
2022-07-14add missing null ptr check in alloc exampleRalf Jung-1/+4
2022-07-14add code examplesDuarte Nunes-1/+50
2022-07-14Rollup merge of #98315 - joshtriplett:stabilize-core-ffi-c, r=Mark-SimulacrumDylan DPC-1/+0
Stabilize `core::ffi:c_*` and rexport in `std::ffi` This only stabilizes the base types, not the non-zero variants, since those have their own separate tracking issue and have not gone through FCP to stabilize.
2022-07-13Stabilize `core::ffi:c_*` and rexport in `std::ffi`Josh Triplett-1/+0
This only stabilizes the base types, not the non-zero variants, since those have their own separate tracking issue and have not gone through FCP to stabilize.
2022-07-13rustdocDuarte Nunes-1/+1
2022-07-13typoDuarte Nunes-2/+2
2022-07-13changes to wordingDuarte Nunes-9/+15
2022-07-13docs: be less harsh in wording for Vec::from_raw_partsDuarte Nunes-5/+15
In particular, be clear that it is sound to specify memory not originating from a previous `Vec` allocation. That is already suggested in other parts of the documentation about zero-alloc conversions to Box<[T]>. Incorporate a constraint from `slice::from_raw_parts` that was missing but needs to be fulfilled, since a `Vec` can be converted into a slice.
2022-07-10Use `byte_sub` in [a]rc implMaybe Waffle-12/+11
2022-07-08Intra-doc-link-ify reference to Clone::clone_fromest31-1/+1
2022-07-03Auto merge of #98755 - nnethercote:faster-vec-insert, r=cuviperbors-6/+9
Optimize `Vec::insert` for the case where `index == len`. By skipping the call to `copy` with a zero length. This makes it closer to `push`. I did this recently for `SmallVec` (https://github.com/servo/rust-smallvec/pull/282) and it was a big perf win in one case. Although I don't have a specific use case in mind, it seems worth doing it for `Vec` as well. Things to note: - In the `index < len` case, the number of conditions checked is unchanged. - In the `index == len` case, the number of conditions checked increases by one, but the more expensive zero-length copy is avoided. - In the `index > len` case the code now reserves space for the extra element before panicking. This seems like an unimportant change. r? `@cuviper`