about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
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-27Auto merge of #78618 - workingjubilee:ieee754-fmt, r=m-ou-sebors-5/+3
Add IEEE 754 compliant fmt/parse of -0, infinity, NaN This pull request improves the Rust float formatting/parsing libraries to comply with IEEE 754's formatting expectations around certain special values, namely signed zero, the infinities, and NaN. It also adds IEEE 754 compliance tests that, while less stringent in certain places than many of the existing flt2dec/dec2flt capability tests, are intended to serve as the beginning of a roadmap to future compliance with the standard. Some relevant documentation is also adjusted with clarifying remarks. This PR follows from discussion in https://github.com/rust-lang/rfcs/issues/1074, and closes #24623. The most controversial change here is likely to be that -0 is now printed as -0. Allow me to explain: While there appears to be community support for an opt-in toggle of printing floats as if they exist in the naively expected domain of numbers, i.e. not the extended reals (where floats live), IEEE 754-2019 is clear that a float converted to a string should be capable of being transformed into the original floating point bit-pattern when it satisfies certain conditions (namely, when it is an actual numeric value i.e. not a NaN and the original and destination float width are the same). -0 is given special attention here as a value that should have its sign preserved. In addition, the vast majority of other programming languages not only output `-0` but output `-0.0` here. While IEEE 754 offers a broad leeway in how to handle producing what it calls a "decimal character sequence", it is clear that the operations a language provides should be capable of round tripping, and it is confusing to advertise the f32 and f64 types as binary32 and binary64 yet have the most basic way of producing a string and then reading it back into a floating point number be non-conformant with the standard. Further, existing documentation suggested that e.g. -0 would be printed with -0 regardless of the presence of the `+` fmt character, but it prints "+0" instead if given such (which was what led to the opening of #24623). There are other parsing and formatting issues for floating point numbers which prevent Rust from complying with the standard, as well as other well-documented challenges on the arithmetic level, but I hope that this can be the beginning of motion towards solving those challenges.
2021-03-27Rollup merge of #83388 - alamb:alamb/fmt-dcs, r=Mark-SimulacrumYuki Okushi-1/+5
Make # pretty print format easier to discover # Rationale: I use (cargo cult?) three formats in rust: `{}`, debug `{:?}`, and pretty-print debug `{:#?}`. I discovered `{:#?}` in some blog post or guide when I started working in Rust. While `#` is documented I think it is hard to discover. So taking the good advice of ```@carols10cents``` I am trying to improve the docs with a PR As a reminder "pretty print" means that where `{:?}` will print something like ``` foo: { b1: 1, b2: 2} ``` `{:#?}` will prints something like ``` foo { b1: 1 b2: 3 } ``` # Changes Add an example to `fmt` to try and make it easier to discover `#`
2021-03-26Use iter::zip in library/Josh Stone-6/+4
2021-03-26Update char::escape_debug_ext to handle different escapes in strings vs. charsÖmer Sinan Ağacan-4/+1
Fixes #83046 The program fn main() { println!("{:?}", '"'); println!("{:?}", "'"); } would previously print '\"' "\'" With this patch it now prints: '"' "'"
2021-03-26Rollup merge of #83456 - notriddle:vec-from-docs, r=JohnTitorDylan DPC-0/+61
Add docs for Vec::from functions Part of #51430
2021-03-25Add strong_count mutation methods to RcNika Layzell-0/+67
2021-03-25Change wordingMichael Howell-2/+2
2021-03-25Try to make Vec benchmarks only run code they are benchmarkingBen Kimock-68/+25
Many of the Vec benchmarks assert what values should be produced by the benchmarked code. In some cases, these asserts dominate the runtime of the benchmarks they are in, causing the benchmarks to understate the impact of an optimization or regression.
2021-03-24Add docs for Vec::from functionsMichael Howell-0/+61
Part of #51430
2021-03-24Revert "Revert stabilizing integer::BITS."Mara Bos-2/+0
2021-03-23Bump alloc::str::SplitInclusive to 1.53.0 releaseDavid Tolnay-1/+1
2021-03-23Expose str::SplitInclusive in alloc and therefore in stdIan Jackson-0/+2
This seems to have been omitted from the beginning when this feature was first introduced in 86bf96291d82. Most users won't need to name this type which is probably why this wasn't noticed in the meantime. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-03-22Update signed fmt/-0f32 docsJubilee Young-3/+2
"semantic equivalence" is too strong a phrasing here, which is why actually explaining what kind of circumstances might produce a -0 was chosen instead.
2021-03-22Preserve signed zero on roundtripJubilee Young-2/+1
This commit removes the previous mechanism of differentiating between "Debug" and "Display" formattings for the sign of -0 so as to comply with the IEEE 754 standard's requirements on external character sequences preserving various attributes of a floating point representation. In addition, numerous tests are fixed.
2021-03-22Update library/alloc/src/fmt.rsAndrew Lamb-1/+1
2021-03-22Auto merge of #79278 - mark-i-m:stabilize-or-pattern, r=nikomatsakisbors-1/+1
Stabilize or_patterns (RFC 2535, 2530, 2175) closes #54883 This PR stabilizes the or_patterns feature in Rust 1.53. This is blocked on the following (in order): - [x] The crater run in https://github.com/rust-lang/rust/pull/78935#issuecomment-731564021 - [x] The resolution of the unresolved questions and a second crater run (https://github.com/rust-lang/rust/pull/78935#issuecomment-735412705) - It looks like we will need to pursue some sort of edition-based transition for `:pat`. - [x] Nomination and discussion by T-lang - [x] Implement new behavior for `:pat` based on consensus (https://github.com/rust-lang/rust/pull/80100). - [ ] An FCP on stabilization EDIT: Stabilization report is in https://github.com/rust-lang/rust/pull/79278#issuecomment-772815177
2021-03-22Make # format easier to discoverAndrew Lamb-1/+5
2021-03-22Rollup merge of #82374 - clehner:licenses, r=joshtriplettDylan DPC-0/+3
Add license metadata for std dependencies These five crates are in the dependency tree of `std` but lack license metadata: - `alloc` - `core` - `panic_abort` - `panic_unwind` - `unwind` Querying the dependency tree of `std` is a useful thing to be able to do, since these crates will typically be linked into Rust binaries. Tools show the license fields missing, as seen in https://github.com/rust-lang/rust/issues/67014#issuecomment-782704534. This PR adds the license field for the five crates, based on the license of the `std` package and this repo as a whole. I also added the `repository` and `descriptions` fields, since those seem useful. For `description`, I copied text from top-level comments for the respective modules - except for `unwind` which has none. I also note that https://github.com/rust-lang/rust/pull/73530 attempted to add license metadata for all crates in this repo, but was rejected because there was question about some of them. I hope that this smaller change, focusing only on the runtime dependencies, will be easier to review. cc `@Mark-Simulacrum` `@Lokathor`
2021-03-22Auto merge of #83360 - Dylan-DPC:rollup-17xulpv, r=Dylan-DPCbors-19/+100
Rollup of 9 pull requests Successful merges: - #80193 (stabilize `feature(osstring_ascii)`) - #80771 (Make NonNull::as_ref (and friends) return refs with unbound lifetimes) - #81607 (Implement TrustedLen and TrustedRandomAccess for Range<integer>, array::IntoIter, VecDequeue's iterators) - #82554 (Fix invalid slice access in String::retain) - #82686 (Move `std::sys::unix::platform` to `std::sys::unix::ext`) - #82771 (slice: Stabilize IterMut::as_slice.) - #83329 (Cleanup LLVM debuginfo module docs) - #83336 (Fix ICE with `use clippy::a::b;`) - #83350 (Download a more recent LLVM version if `src/version` is modified) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-03-22Rollup merge of #82554 - SkiFire13:fix-string-retain-unsoundness, r=m-ou-seDylan DPC-15/+22
Fix invalid slice access in String::retain As noted in #78499, the previous fix was technically still unsound because it accessed elements of a slice outside its bounds (even though they were still inside the same allocation). This PR addresses that concern by switching to a dropguard approach.
2021-03-21fmt, change to coldBen Kimock-2/+6
2021-03-21Mark RawVec::reserve as inline and outline the resizing logicBen Kimock-1/+13
2021-03-21specialize in-place collection further via TrustedRandomAccessThe8472-16/+53
This allows the optimizer to turn certain iterator pipelines such as ```rust let vec = vec![0usize; 100]; vec.into_iter().map(|e| e as isize).collect::<Vec<_>>() ``` into a noop. The optimization only applies when iterator sources are `T: Copy` since `impl TrustedRandomAccess for IntoIter<T>`. No such requirement applies to the output type (`Iterator::Item`).
2021-03-21add transmute-via-iterators benchThe8472-0/+16
2021-03-21use BITS constantThe8472-1/+1
2021-03-21implement TrustedLen and TrustedRandomAccess for VecDeque iteratorsThe8472-3/+77
2021-03-21Auto merge of #83053 - oli-obk:const_stab_version, r=m-ou-sebors-1/+1
Fix const stability `since` versions. fixes #82085 r? `@m-ou-se`
2021-03-20Update the commentYechan Bae-4/+4
2021-03-19core/std/alloc: stabilize or_patternsmark-1/+1
2021-03-19Rollup merge of #83244 - cuviper:vec_deque-zst, r=m-ou-seDylan DPC-19/+33
Fix overflowing length in Vec<ZST> to VecDeque `Vec` can hold up to `usize::MAX` ZST items, but `VecDeque` has a lower limit to keep its raw capacity as a power of two, so we should check that in `From<Vec<T>> for VecDeque<T>`. We can also simplify the capacity check for the remaining non-ZST case. Before this fix, the new test would fail on the length: ``` thread 'collections::vec_deque::tests::test_from_vec_zst_overflow' panicked at 'assertion failed: `(left == right)` left: `0`, right: `9223372036854775808`', library/alloc/src/collections/vec_deque/tests.rs:474:5 note: panic did not contain expected string panic message: `"assertion failed: `(left == right)`\n left: `0`,\n right: `9223372036854775808`"`, expected substring: `"capacity overflow"` ``` That was a result of `len()` using a mask `& (size - 1)` with the improper length. Now we do get a "capacity overflow" panic as soon as that `VecDeque::from(vec)` is attempted. Fixes #80167.
2021-03-19Auto merge of #71780 - jcotton42:string_remove_matches, r=joshtriplettbors-0/+84
Implement String::remove_matches Closes #50206. I lifted the function help from `@frewsxcv's` original PR (#50015), hope they don't mind. I'm also wondering whether it would be useful for `remove_matches` to collect up the removed substrings into a `Vec` and return them, right now they're just overwritten by the copy and lost.
2021-03-18BTree: no longer search arrays twice to check OrdStein Somers-33/+27
2021-03-18Auto merge of #81312 - dylni:clarify-btree-range-search-comments, r=m-ou-sebors-3/+2
Clarify BTree `range_search` comments These comments were added by #81169. However, the soundness issue [might not be exploitable here](https://github.com/rust-lang/rust/pull/81169#issuecomment-765271717), so the comments should be updated. cc `@ssomers`
2021-03-18Rollup merge of #82434 - jyn514:hash, r=JohnTitorDylan DPC-3/+4
Add more links between hash and btree collections - Link from `core::hash` to `HashMap` and `HashSet` - Link from HashMap and HashSet to the module-level documentation on when to use the collection - Link from several collections to Wikipedia articles on the general concept See also https://github.com/rust-lang/rust/pull/81989#issuecomment-783920840.
2021-03-18Rollup merge of #82191 - Soveu:dedup, r=nagisaDylan DPC-6/+306
Vec::dedup_by optimization Now `Vec::dedup_by` drops items in-place as it goes through them. From my benchmarks, it is around 10% faster when T is small, with no major regression when otherwise. I used `ptr::copy` instead of conditional `ptr::copy_nonoverlapping`, because the latter had some weird performance issues on my ryzen laptop (it was 50% slower on it than on intel/sandybridge laptop) It would be good if someone was able to reproduce these results.
2021-03-17Fix overflowing length in Vec<ZST> to VecDequeJosh Stone-19/+33
`Vec` can hold up to `usize::MAX` ZST items, but `VecDeque` has a lower limit to keep its raw capacity as a power of two, so we should check that in `From<Vec<T>> for VecDeque<T>`. We can also simplify the capacity check for the remaining non-ZST case. Before this fix, the new test would fail on the length: ``` thread 'collections::vec_deque::tests::test_from_vec_zst_overflow' panicked at 'assertion failed: `(left == right)` left: `0`, right: `9223372036854775808`', library/alloc/src/collections/vec_deque/tests.rs:474:5 note: panic did not contain expected string panic message: `"assertion failed: `(left == right)`\n left: `0`,\n right: `9223372036854775808`"`, expected substring: `"capacity overflow"` ``` That was a result of `len()` using a mask `& (size - 1)` with the improper length. Now we do get a "capacity overflow" panic as soon as that `VecDeque::from(vec)` is attempted.
2021-03-17BTree: clarify order sanity enforced by range searchesStein Somers-7/+29
2021-03-16Fix comments based on reviewdylni-5/+2
2021-03-16Rollup merge of #83072 - henryboisdequin:patch-1, r=Dylan-DPCYuki Okushi-3/+3
Update `Vec` docs Fix typos/nits in `Vec` docs
2021-03-16Vec::dedup optimization - add benchesSoveu-1/+91
2021-03-15Merge branch 'master' into dedupSoveu-806/+1201
2021-03-15Vec::dedup optimization - add test for panicSoveu-0/+54
2021-03-15Vec::dedup optimization - finishing polishesSoveu-11/+7
2021-03-15Vec::dedup optimization - add testsSoveu-0/+74
2021-03-15Replace `type_alias_impl_trait` by `min_type_alias_impl_trait` with no ↵Oli Scherer-1/+2
actual changes in behaviour This makes `type_alias_impl_trait` not actually do anything anymore
2021-03-15Fix const stability `since` versions.Oli Scherer-1/+1
2021-03-15Clarify BTree range searching commentsdylni-1/+3
2021-03-13provide a more realistic example for BinaryHeap::as_sliceVlad Frolov-5/+3
2021-03-13Auto merge of #82760 - WaffleLapkin:unleak_extend_from_within, r=kennytmbors-15/+70
Fix leak in Vec::extend_from_within Fixes #82533