about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2019-07-15Add debug assertions to write_bytes and copy*Valentin Tolmer-4/+35
2019-07-12Rollup merge of #62599 - RalfJung:uninit, r=cramertjMazdak Farrokhzad-1/+1
move mem::uninitialized deprecation back by 1 release, to 1.39 As per discussion at https://github.com/rust-lang/rust/issues/53491#issuecomment-509271182. Three releases also agrees with the precedent from `trim_left/right`. Three releases means that even nightly users (including rustc itself) get a full cycle from when the announcement is made in the stable release to when nightly starts to warn.
2019-07-12Rollup merge of #62431 - czipperz:add-messages-to-must-use-is_-methods, ↵Mazdak Farrokhzad-4/+5
r=scottmcm Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*` r? @RalfJung
2019-07-11move mem::uninitialized deprecation back by 1 release, to 1.39Ralf Jung-1/+1
2019-07-11Rollup merge of #62557 - taiki-e:typo, r=CentrilMazdak Farrokhzad-1/+2
Fix typo in libcore/intrinsics.rs
2019-07-11Rollup merge of #62476 - petrochenkov:expref, r=matthewjasperMazdak Farrokhzad-2/+5
Continue refactoring macro expansion and resolution This PR continues the work started in https://github.com/rust-lang/rust/pull/62042. It contains a set of more or less related refactorings with the general goal of making things simpler and more orthogonal. Along the way most of the issues uncovered in https://github.com/rust-lang/rust/pull/62086 are fixed. The PR is better read in per-commit fashion with whitespace changes ignored. I tried to leave some more detailed commit messages describing the motivation behind the individual changes. Fixes https://github.com/rust-lang/rust/issues/44692 Fixes https://github.com/rust-lang/rust/issues/52363 Unblocks https://github.com/rust-lang/rust/pull/62086 r? @matthewjasper
2019-07-11Rollup merge of #61665 - aschampion:slice-eq-ptr, r=sfacklerMazdak Farrokhzad-6/+17
core: check for pointer equality when comparing Eq slices Because `Eq` types must be reflexively equal, an equal-length slice to the same memory location must be equal. This is related to #33892 (and #32699) answering this comment from that PR: > Great! One more easy question: why does this optimization not apply in the non-BytewiseEquality implementation directly above? Because slices of non-reflexively equal types (like `f64`) are not equal even if it's the same slice. But if the types are `Eq`, we can use this same-address optimization, which this PR implements. Obviously this changes behavior if types violate the reflexivity condition of `Eq`, because their impls of `PartialEq` will no longer be called per-item, but 🤷‍♂ . It's not clear how often this optimization comes up in the real world outside of the same-`&str` case covered by #33892, so **I'm requesting a perf run** (on MacOS today, so can't run `rustc_perf` myself). I'm going ahead and making the PR on the basis of being surprised things didn't already work this way. This is my first time hacking rust itself, so as a perf sanity check I ran `./x.py bench --stage 0 src/lib{std,alloc}`, but the differences were noisy. To make the existing specialization for `BytewiseEquality` explicit, it's now a supertrait of `Eq + Copy`. `Eq` should be sufficient, but `Copy` was included for clarity.
2019-07-11hygiene: Fix wording of desugaring descriptionsVadim Petrochenkov-2/+2
Use variant names rather than descriptions for identifying desugarings in `#[rustc_on_unimplemented]`. Both are highly unstable, but variant name is at least a single identifier.
2019-07-11Remove unnecessary expansions created by `#[test_case/test/bench]`Vadim Petrochenkov-0/+3
The expansions were created to allow unstable things inside `#[test_case/test/bench]`, but that's not a proper way to do that. Put the required `allow_internal_unstable`s into the macros' properties instead.
2019-07-10Rollup merge of #62493 - Freyskeyd:valid_example_read-write_unaligned, r=rkruppeMazdak Farrokhzad-0/+32
#62357: doc(ptr): add example for {read,write}_unaligned related to #62357 > With #62323 the only example (that had UB and was thus invalid) in std::ptr::read_unaligned and std::ptr::write_unaligned is removed. > We should add a valid example of using the aforementioned functions. Signed-off-by: Freyskeyd <simon.paitrault@gmail.com>
2019-07-10Rollup merge of #62481 - czipperz:iterator-last-nth-use-for_each, r=scottmcmMazdak Farrokhzad-3/+1
Use `fold` in `Iterator::last` default implementation We already use it in all the other methods. Consistency + potential perf is a pretty nice win!
2019-07-10Fix typo in libcore/intrinsics.rsTaiki Endo-1/+2
2019-07-09Use fold in Iterator::lastChris Gregory-3/+1
Replace last impl with fold
2019-07-10Rollup merge of #62278 - cuviper:iter-partition, r=alexcrichtonMazdak Farrokhzad-0/+138
Add Iterator::partition_in_place() and is_partitioned() `partition_in_place()` swaps `&mut T` items in-place to satisfy the predicate, so all `true` items precede all `false` items. This requires a `DoubleEndedIterator` so we can search from front and back for items that need swapping. `is_partitioned()` checks whether the predicate is already satisfied.
2019-07-09Tracking issue 62544 for iter_is_partitionedJosh Stone-1/+1
2019-07-09Tracking issue 62543 for iter_partition_in_placeJosh Stone-1/+1
2019-07-09Unit test Iterator::partition_in_place and is_partitionedJosh Stone-0/+38
2019-07-09Return the true count from partition_in_placeJosh Stone-6/+35
2019-07-09Rename partition_mut to partition_in_placeJosh Stone-8/+8
2019-07-09Capitalize example commentJosh Stone-1/+1
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-09Add Iterator::partition_mut() and is_partitioned()Josh Stone-0/+71
`partition_mut()` swaps `&mut T` items in-place to satisfy the predicate, so all `true` items precede all `false` items. This requires a `DoubleEndedIterator` so we can search from front and back for items that need swapping. `is_partitioned()` checks whether the predicate is already satisfied.
2019-07-09Apply suggestions from code reviewAleksey Kladov-3/+3
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-09doc(ptr): add example for {read,write}_unalignedFreyskeyd-0/+32
Signed-off-by: Freyskeyd <simon.paitrault@gmail.com>
2019-07-09clarify that debug_assert does not completely omits the codeAleksey Kladov-6/+6
TIL that debug_assert is implemented using `if cfg!(debug_assertions)` rather than `#[cfg(debug_assertions)]`. This means one can not use API gated with `#[cfg(debug_assertions)]` in `debug_assert` family of macros.
2019-07-09Rollup merge of #60458 - KodrAus:debug_map_entry, r=alexcrichtonMazdak Farrokhzad-25/+229
Add key and value methods to DebugMap Implementation PR for an active (not approved) RFC: https://github.com/rust-lang/rfcs/pull/2696. Add two new methods to `std::fmt::DebugMap` for writing the key and value part of a map entry separately: ```rust impl<'a, 'b: 'a> DebugMap<'a, 'b> { pub fn key(&mut self, key: &dyn Debug) -> &mut Self; pub fn value(&mut self, value: &dyn Debug) -> &mut Self; } ``` I want to do this so that I can write a `serde::Serializer` that forwards to our format builders, so that any `T: Serialize` can also be treated like a `T: Debug`.
2019-07-09add feature to docsAshley Mannix-0/+2
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-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-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-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 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