about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2019-07-08Auto merge of #62473 - timvermeulen:is_sorted_by_key, r=scottmcmbors-5/+5
Only call the closure parameter of Iterator::is_sorted_by_key once per item See https://github.com/rust-lang/rust/issues/53485#issuecomment-472314004. This changes `Iterator::is_sorted_by_key` to only call the given closure once for each item, which allows us to pass the items to the closure by value instead of by reference. **Important**: `is_sorted_by_key` for slices and slice iterators is now no longer implemented in terms of the custom `slice::Iter::is_sorted_by` implementation. It's a trade-off: we could forward `slice::Iter::is_sorted_by_key` to it directly for potential SIMD benefits, but that would mean that the closure is potentially called twice for (almost) every element of the slice.
2019-07-08Fix Pin urls in Option documentationGuillaume Gomez-0/+4
2019-07-08Add documentation to float conversion methodsLzu Tao-20/+144
2019-07-08Add float conversions to and from bytesTobias Bucher-0/+106
Use the same API as for integers. Fixes #57492.
2019-07-08Rollup merge of #62356 - soc:topic/contains, r=CentrilMazdak Farrokhzad-0/+78
Implement Option::contains and Result::contains This increases consistency with other common data structures.
2019-07-08add key and value methods to DebugMapAshley Mannix-25/+227
2019-07-07Only call the closure parameter of Iterator::is_sorted_by_key once per itemTim Vermeulen-5/+5
2019-07-07Auto merge of #62435 - scottmcm:constrained-array-impls, r=centrilbors-0/+321
Use const generics for array impls [part 1] Part 1 of #61415, following the plan in https://github.com/rust-lang/rust/issues/61415#issuecomment-497922482 Found a way that works 🙃
2019-07-07Use const generics for array impls, restricted to 0..=32Scott McMurray-0/+321
- uses a never-stable core::array::LengthAtMost32 to bound the impls - includes a custom error message to avoid mentioning LengthAtMost32 too often - doesn't use macros for the slice implementations to avoid #62433
2019-07-07Implement Option::contains, Result::contains and Result::contains_errSimon Ochsenreither-0/+78
This increases consistency with other common data structures.
2019-07-07Stablize Euclidean Modulo (feature euclidean_division)CrLF0710-33/+16
2019-07-07Rollup merge of #62379 - GuillaumeGomez:option-doc-links, r=QuietMisdreavusMazdak Farrokhzad-10/+22
Add missing links in Option documentation r? @rust-lang/docs
2019-07-07Rollup merge of #61990 - llogiq:questionmark-test, r=QuietMisdreavusMazdak Farrokhzad-4/+7
First question mark in doctest We have had `?` for `Result`s in doctests for some time, but so far haven't used them in doctests. With this PR, I want to start the de-`unwrap`ping of doctests – and the discussion on where to do so. There is one downside, which is that the code can no longer be copied into a plain `main()` method, on the other hand, there should be a workable error if one does this.
2019-07-06Rollup merge of #62243 - petrochenkov:macrodoc, r=eddybMazdak Farrokhzad-91/+629
Improve documentation for built-in macros This is the `libcore` part of https://github.com/rust-lang/rust/pull/62086. Right now the only effect is improved documentation. The changes in the last few commits are required to make the `libcore` change compile successfully.
2019-07-06Rollup merge of #60081 - pawroman:cleanup_unicode_script, r=varkorMazdak Farrokhzad-352/+740
Refactor unicode.py script Hi, I noticed that the `unicode.py` script used some deprecated escapes in regular expressions. E.g. `\d`, `\w`, `\.` will be illegal in the future without "raw strings". This is now fixed. I have also cleaned up the script quite a bit. ## Escape deprecation OK (note the `r`): `re.compile(r"\d")` Deprecated (from Python 3.6 onwards, see [here][link1] and [here][link2]): `re.compile("\d")`. [link1]: https://docs.python.org/3.6/whatsnew/3.6.html#deprecated-python-behavior [link2]: https://bugs.python.org/issue27364 This was evident running the script using Python 3.7 like so: ``` $ python3 -Wall unicode.py unicode.py:227: DeprecationWarning: invalid escape sequence \w re1 = re.compile("^ *([0-9A-F]+) *; *(\w+)") unicode.py:228: DeprecationWarning: invalid escape sequence \. re2 = re.compile("^ *([0-9A-F]+)\.\.([0-9A-F]+) *; *(\w+)") unicode.py:453: DeprecationWarning: invalid escape sequence \d pattern = "for Version (\d+)\.(\d+)\.(\d+) of the Unicode" ``` The documentation states that > A backslash-character pair that is not a valid escape sequence now generates a DeprecationWarning. Although this will eventually become a SyntaxError, that will not be for several Python releases. ## Testing To test my changes, I had to add support for choosing the Unicode version to use. The script will default to latest release (which is 12.0.0 at the moment, repo has 11.0.0 checked in). The script generates the exact same output for version 11.0.0 with Python 2.7 and 3.7 and no longer generates any deprecation warnings: ``` $ python3 -Wall unicode.py -v 11.0.0 Using Unicode version: 11.0.0 Regenerated tables.rs. $ git diff tables.rs $ python2 -Wall unicode.py -v 11.0.0 Using Unicode version: 11.0.0 Regenerated tables.rs. $ git diff tables.rs $ python2 --version Python 2.7.16 $ python3 --version Python 3.7.3 ``` ## Extra functionality Furthermore, the script will check and download the latest Unicode version by default (without the `-v` argument). The `--help` is below: ``` $ ./unicode.py --help usage: unicode.py [-h] [-v VERSION] Regenerate Unicode tables (tables.rs). optional arguments: -h, --help show this help message and exit -v VERSION, --version VERSION Unicode version to use (if not specified, defaults to latest available final release). ``` ## Cleanups I have cleaned up the code quite a bit, with Python best practices and code style in mind. I'm happy to provide more details and rationale for all my changes if the reviewers so desire. One externally visible change is that the Unicode data will now be downloaded into `src/libcore/unicode/downloaded` directory suffixed by Unicode version: ``` $ pwd .../rust/src/libcore/unicode $ exa -T downloaded/ downloaded ├── 11.0.0 │ ├── DerivedCoreProperties.txt │ ├── DerivedNormalizationProps.txt │ ├── PropList.txt │ ├── ReadMe.txt │ ├── Scripts.txt │ ├── SpecialCasing.txt │ └── UnicodeData.txt └── 12.0.0 ├── DerivedCoreProperties.txt ├── DerivedNormalizationProps.txt ├── PropList.txt ├── ReadMe.txt ├── Scripts.txt ├── SpecialCasing.txt └── UnicodeData.txt ```
2019-07-06Improve documentation for built-in macrosVadim Petrochenkov-76/+614
2019-07-06`#[rustc_doc_only_macro]` -> `#[rustc_builtin_macro]`Vadim Petrochenkov-16/+16
2019-07-05Wrap lineChris Gregory-1/+2
2019-07-05Add messages to Option and Result must_use for is_*Chris Gregory-4/+4
2019-07-05Do not use pointer alignment on unsupported platformsJustin Ridgewell-1/+1
2019-07-05Rollup merge of #62133 - petrochenkov:norustc, r=eddybMazdak Farrokhzad-0/+1
Feature gate `rustc` attributes harder Fixes https://github.com/rust-lang/rust/issues/62116
2019-07-05Rollup merge of #62323 - Centril:clarify-read-unaligned, r=RalfJungMazdak Farrokhzad-35/+53
Clarify unaligned fields in ptr::{read,write}_unaligned r? @RalfJung
2019-07-05Rollup merge of #62150 - alex:mem-uninit-refactor, r=RalfJungMazdak Farrokhzad-13/+9
Implement mem::{zeroed,uninitialized} in terms of MaybeUninit. Refs #62061 r? @oli-obk
2019-07-05Rollup merge of #62123 - jeremystucki:needless_lifetimes_std, r=alexcrichtonMazdak Farrokhzad-3/+3
Remove needless lifetimes (std) Split from #62039
2019-07-04Add missing type links in Pin documentationGuillaume Gomez-63/+81
2019-07-04Add missing links in Option documentationGuillaume Gomez-10/+22
2019-07-04Switch master to 1.38Mark Rousskov-68/+5
2019-07-04Implement mem::{zeroed,uninitialized} in terms of MaybeUninit.Alex Gaynor-13/+9
Refs #62061
2019-07-04ptr::{read,write}_unaligned: use no_run and reword slightly.Mazdak Farrokhzad-4/+4
2019-07-04Clarify unaligned fields in ptr::read_unaligned.Mazdak Farrokhzad-35/+53
2019-07-03Improve formatting of 'ManuallyDrop'Aaron Hill-1/+1
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-03Document that ManuallyDrop::drop should not called more than onceAaron Hill-1/+2
Double dropping is unsound (e.g. https://github.com/rust-lang/rust/issues/60977). This commit documents the fact that `ManuallyDrop::drop` should not be called multiple times on the same instance, as it might not be immediately obvious that this counts as a use of uninitialized data.
2019-07-04Rollup merge of #62351 - RalfJung:drop-in-place, r=cramertjMazdak Farrokhzad-27/+5
remove bogus example from drop_in_place Fixes https://github.com/rust-lang/rust/issues/62313
2019-07-04Rollup merge of #62346 - RalfJung:miri-tests, r=CentrilMazdak Farrokhzad-7/+4
enable a few more tests in Miri and update the comment for others
2019-07-04Rollup merge of #62344 - matklad:simplify-option, r=sfacklerMazdak Farrokhzad-9/+1
simplify Option::get_or_insert I am pretty sure that the optimized result will be the same, and it's one `unsafe` less in the stdlib!
2019-07-04Rollup merge of #62316 - khuey:efficient_last, r=sfacklerMazdak Farrokhzad-0/+16
When possible without changing semantics, implement Iterator::last in terms of DoubleEndedIterator::next_back for types in liballoc and libcore. Provided that the iterator has finite length and does not trigger user-provided code, this is safe. What follows is a full list of the DoubleEndedIterators in liballoc/libcore and whether this optimization is safe, and if not, why not. src/liballoc/boxed.rs Box: Pass through to avoid defeating optimization of the underlying DoubleIterator implementation. This has no correctness impact. src/liballoc/collections/binary_heap.rs Iter: Pass through to avoid defeating optimizations on slice::Iter IntoIter: Not safe, changes Drop order Drain: Not safe, changes Drop order src/liballoc/collections/btree/map.rs Iter: Safe to call next_back, invokes no user defined code. IterMut: ditto IntoIter: Not safe, changes Drop order Keys: Safe to call next_back, invokes no user defined code. Values: ditto ValuesMut: ditto Range: ditto RangeMut: ditto src/liballoc/collections/btree/set.rs Iter: Safe to call next_back, invokes no user defined code. IntoIter: Not safe, changes Drop order Range: Safe to call next_back, invokes no user defined code. src/liballoc/collections/linked_list.rs Iter: Safe to call next_back, invokes no user defined code. IterMut: ditto IntoIter: Not safe, changes Drop order src/liballoc/collections/vec_deque.rs Iter: Safe to call next_back, invokes no user defined code. IterMut: ditto IntoIter: Not safe, changes Drop order Drain: ditto src/liballoc/string.rs Drain: Safe because return type is a primitive (char) src/liballoc/vec.rs IntoIter: Not safe, changes Drop order Drain: ditto Splice: ditto src/libcore/ascii.rs EscapeDefault: Safe because return type is a primitive (u8) src/libcore/iter/adapters/chain.rs Chain: Not safe, invokes user defined code (Iterator impl) src/libcore/iter/adapters/flatten.rs FlatMap: Not safe, invokes user defined code (Iterator impl) Flatten: ditto FlattenCompat: ditto src/libcore/iter/adapters/mod.rs Rev: Not safe, invokes user defined code (Iterator impl) Copied: ditto Cloned: Not safe, invokes user defined code (Iterator impl and T::clone) Map: Not safe, invokes user defined code (Iterator impl + closure) Filter: ditto FilterMap: ditto Enumerate: Not safe, invokes user defined code (Iterator impl) Skip: ditto Fuse: ditto Inspect: ditto src/libcore/iter/adapters/zip.rs Zip: Not safe, invokes user defined code (Iterator impl) src/libcore/iter/range.rs ops::Range: Not safe, changes Drop order, but ALREADY HAS SPECIALIZATION ops::RangeInclusive: ditto src/libcore/iter/sources.rs Repeat: Not safe, calling last should iloop. Empty: No point, iterator is at most one item long. Once: ditto OnceWith: ditto src/libcore/option.rs Item: No point, iterator is at most one item long. Iter: ditto IterMut: ditto IntoIter: ditto src/libcore/result.rs Iter: No point, iterator is at most one item long IterMut: ditto IntoIter: ditto src/libcore/slice/mod.rs Split: Not safe, invokes user defined closure SplitMut: ditto RSplit: ditto RSplitMut: ditto Windows: Safe, already has specialization Chunks: ditto ChunksMut: ditto ChunksExact: ditto ChunksExactMut: ditto RChunks: ditto RChunksMut: ditto RChunksExact: ditto RChunksExactMut: ditto src/libcore/str/mod.rs Chars: Safe, already has specialization CharIndices: ditto Bytes: ditto Lines: Safe to call next_back, invokes no user defined code. LinesAny: Deprecated Everything that is generic over P: Pattern: Not safe because Pattern invokes user defined code. SplitWhitespace: Safe to call next_back, invokes no user defined code. SplitAsciiWhitespace: ditto This is attempt 2 of #60130. r? @sfackler
2019-07-04Rollup merge of #62252 - czipperz:change-mem-replace-doc-example, r=dtolnayMazdak Farrokhzad-8/+20
Update mem::replace example to not be identical to mem::take This also adds assertions that the operations work as expected.
2019-07-04Rollup merge of #62249 - czipperz:use-mem-take-instead-of-replace-default, ↵Mazdak Farrokhzad-1/+2
r=dtolnay,Centril Use mem::take instead of mem::replace with default
2019-07-03remove bogus example from drop_in_placeRalf Jung-27/+5
2019-07-03enable a few more tests in Miri and update the comment for othersRalf Jung-7/+4
2019-07-03simplify Option::get_or_insertAleksey Kladov-9/+1
2019-07-03First question mark in doctestAndre Bogus-4/+7
2019-07-03Rollup merge of #62327 - Flast:patch-1, r=Mark-SimulacrumMark Rousskov-16/+16
Fixed document bug, those replaced each other Originally reported by #57686, introduced by #58005
2019-07-03Rollup merge of #62319 - ia0:fix_kleene, r=petrochenkovMark Rousskov-2/+2
Fix mismatching Kleene operators
2019-07-03Rollup merge of #62186 - GuillaumeGomez:add-missing-type-links-into, r=docsMark Rousskov-2/+3
Add missing type urls in Into trait r? @rust-lang/docs
2019-07-03Rollup merge of #62161 - GuillaumeGomez:add-missing-tryfrom-links, r=docsMark Rousskov-9/+11
Add missing links for TryFrom docs r? @rust-lang/docs
2019-07-03Rollup merge of #62064 - wizAmit:feature/chunks_exact_nth_back, r=scottmcmMark Rousskov-0/+34
nth_back for chunks_exact wip nth_back for chunks_exact working nth_back for chunks exact Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com> r? @timvermeulen r? @scottmcm
2019-07-03Fixed document bug, those replaced each otherKohei Takahashi-16/+16
Introduced by #58005
2019-07-03Fix mismatching Kleene operatorsJulien Cretin-2/+2
2019-07-02When possible without changing semantics, implement Iterator::last in terms ↵Kyle Huey-0/+16
of DoubleEndedIterator::next_back for types in liballoc and libcore. Provided that the iterator has finite length and does not trigger user-provided code, this is safe. What follows is a full list of the DoubleEndedIterators in liballoc/libcore and whether this optimization is safe, and if not, why not. src/liballoc/boxed.rs Box: Pass through to avoid defeating optimization of the underlying DoubleIterator implementation. This has no correctness impact. src/liballoc/collections/binary_heap.rs Iter: Pass through to avoid defeating optimizations on slice::Iter IntoIter: Not safe, changes Drop order Drain: Not safe, changes Drop order src/liballoc/collections/btree/map.rs Iter: Safe to call next_back, invokes no user defined code. IterMut: ditto IntoIter: Not safe, changes Drop order Keys: Safe to call next_back, invokes no user defined code. Values: ditto ValuesMut: ditto Range: ditto RangeMut: ditto src/liballoc/collections/btree/set.rs Iter: Safe to call next_back, invokes no user defined code. IntoIter: Not safe, changes Drop order Range: Safe to call next_back, invokes no user defined code. src/liballoc/collections/linked_list.rs Iter: Safe to call next_back, invokes no user defined code. IterMut: ditto IntoIter: Not safe, changes Drop order src/liballoc/collections/vec_deque.rs Iter: Safe to call next_back, invokes no user defined code. IterMut: ditto IntoIter: Not safe, changes Drop order Drain: ditto src/liballoc/string.rs Drain: Safe because return type is a primitive (char) src/liballoc/vec.rs IntoIter: Not safe, changes Drop order Drain: ditto Splice: ditto src/libcore/ascii.rs EscapeDefault: Safe because return type is a primitive (u8) src/libcore/iter/adapters/chain.rs Chain: Not safe, invokes user defined code (Iterator impl) src/libcore/iter/adapters/flatten.rs FlatMap: Not safe, invokes user defined code (Iterator impl) Flatten: ditto FlattenCompat: ditto src/libcore/iter/adapters/mod.rs Rev: Not safe, invokes user defined code (Iterator impl) Copied: ditto Cloned: Not safe, invokes user defined code (Iterator impl and T::clone) Map: Not safe, invokes user defined code (Iterator impl + closure) Filter: ditto FilterMap: ditto Enumerate: Not safe, invokes user defined code (Iterator impl) Skip: ditto Fuse: ditto Inspect: ditto src/libcore/iter/adapters/zip.rs Zip: Not safe, invokes user defined code (Iterator impl) src/libcore/iter/range.rs ops::Range: Not safe, changes Drop order, but ALREADY HAS SPECIALIZATION ops::RangeInclusive: ditto src/libcore/iter/sources.rs Repeat: Not safe, calling last should iloop. Empty: No point, iterator is at most one item long. Once: ditto OnceWith: ditto src/libcore/option.rs Item: No point, iterator is at most one item long. Iter: ditto IterMut: ditto IntoIter: ditto src/libcore/result.rs Iter: No point, iterator is at most one item long IterMut: ditto IntoIter: ditto src/libcore/slice/mod.rs Split: Not safe, invokes user defined closure SplitMut: ditto RSplit: ditto RSplitMut: ditto Windows: Safe, already has specialization Chunks: ditto ChunksMut: ditto ChunksExact: ditto ChunksExactMut: ditto RChunks: ditto RChunksMut: ditto RChunksExact: ditto RChunksExactMut: ditto src/libcore/str/mod.rs Chars: Safe, already has specialization CharIndices: ditto Bytes: ditto Lines: Safe to call next_back, invokes no user defined code. LinesAny: Deprecated Everything that is generic over P: Pattern: Not safe because Pattern invokes user defined code. SplitWhitespace: Safe to call next_back, invokes no user defined code. SplitAsciiWhitespace: ditto