about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2019-09-14Rollup merge of #64203 - alexreg:rush-pr-2, r=centrilMazdak Farrokhzad-8/+8
A few cosmetic improvements to code & comments in liballoc and libcore Factored out from hacking on rustc for work on the REPL. r? @Centril
2019-09-11Rollup merge of #64349 - arnohaase:pr_documentation_atomicptr, r=cramertjMazdak Farrokhzad-4/+2
documentation for AtomicPtr CAS operations The examples in the documentation for AtomicPtr CAS operations only show code that does *not* perform the CAS operation. I suggest to change them so that they actually do exchange the AtomicPtr's value.
2019-09-10Rollup merge of #63786 - tspiteri:const-abs, r=alexcrichtonMazdak Farrokhzad-21/+9
Make `abs`, `wrapping_abs`, `overflowing_abs` const functions This makes `abs`, `wrapping_abs` and `overflowing_abs` const functions like #58044 makes `wrapping_neg` and `overflowing_neg` const functions. `abs` is made const by returning `(self ^ -1) - -1` = `!self + 1` = `-self` for negative numbers and `(self ^ 0) - 0` = `self` for non-negative numbers. The subexpression `self >> ($BITS - 1)` evaluates to `-1` for negative numbers and `0` otherwise. The subtraction overflows when `self` is `min_value()`, as we would be subtracting `max_value() - -1`; this is when `abs` should overflow. `wrapping_abs` and `overflowing_abs` make use of `wrapping_sub` and `overflowing_sub` instead of the subtraction operator.
2019-09-10documentation for AtomicPtr CAS operationsArno Haase-4/+2
2019-09-09Auto merge of #64313 - Centril:rollup-7w8b67g, r=Centrilbors-1/+78
Rollup of 5 pull requests Successful merges: - #63468 (Resolve attributes in several places) - #64121 (Override `StepBy::{try_fold, try_rfold}`) - #64278 (check git in bootstrap.py) - #64306 (Fix typo in config.toml.example) - #64312 (Unify escape usage) Failed merges: r? @ghost
2019-09-09Rollup merge of #64121 - timvermeulen:iter_step_by_internal, r=scottmcmMazdak Farrokhzad-1/+78
Override `StepBy::{try_fold, try_rfold}` Previous PR: https://github.com/rust-lang/rust/pull/51435 The previous PR was closed in favor of https://github.com/rust-lang/rust/pull/51601, which was later reverted. I don't think these implementations will make it harder to specialize `StepBy<Range<_>>` later, so we should be able to land this without any consequences. This should fix https://github.com/rust-lang/rust/issues/57517 – in my benchmarks `iter` and `iter.step_by(1)` now perform equally well, provided internal iteration is used.
2019-09-09Auto merge of #63118 - Centril:stabilize-bind-by-move, r=matthewjasperbors-1/+1
Stabilize `bind_by_move_pattern_guards` in Rust 1.39.0 Closes https://github.com/rust-lang/rust/issues/15287. After stabilizing `#![feature(bind_by_move_pattern_guards)]`, you can now use bind-by-move bindings in patterns and take references to those bindings in `if` guards of `match` expressions. For example, the following now becomes legal: ```rust fn main() { let array: Box<[u8; 4]> = Box::new([1, 2, 3, 4]); match array { nums // ---- `nums` is bound by move. if nums.iter().sum::<u8>() == 10 // ^------ `.iter()` implicitly takes a reference to `nums`. => { drop(nums); // --------- Legal as `nums` was bound by move and so we have ownership. } _ => unreachable!(), } } ``` r? @matthewjasper
2019-09-08Rollup merge of #62205 - timvermeulen:iter_order_by, r=KodrAusMazdak Farrokhzad-6/+160
Add Iterator comparison methods that take a comparison function This PR adds `Iterator::{cmp_by, partial_cmp_by, eq_by, ne_by, lt_by, le_by, gt_by, ge_by}`. We already have `Iterator::{cmp, partial_cmp, ...}` which are less general (but not any simpler) than the ones I'm proposing here. I'm submitting this PR now because #61505 has been merged, so this change should not have a noticeable effect on the `Iterator` docs page size. The diff is quite messy, here's what I changed: - The logic of `cmp` / `partial_cmp` / `eq` is moved to `cmp_by` / `partial_cmp_by` / `eq_by` respectively, changing `x.cmp(&y)` to `cmp(&x, &y)` in the `cmp` method where `cmp` is the given comparison function (and similar for `partial_cmp_by` and `eq_by`). - `ne_by` / `lt_by` / `le_by` / `gt_by` / `ge_by` are each implemented in terms of one of the three methods above. - The existing comparison methods are each forwarded to their `_by` counterpart, passing one of `Ord::cmp` / `PartialOrd::partial_cmp` / `PartialEq::eq` as the comparison function. The corresponding `_by_key` methods aren't included because they're not as fundamental as the `_by` methods and can easily be implemented in terms of them. Is that reasonable, or would adding the `_by_key` methods be desirable for the sake of completeness? I didn't add any tests – I couldn't think of any that weren't already covered by our existing tests. Let me know if there's a particular test that would be useful to add.
2019-09-08bootstrap -> boostrap_stdarch_ignore_thisMazdak Farrokhzad-1/+1
2019-09-08Dont use gate bind_by_move_pattern_guards internally.Mazdak Farrokhzad-1/+1
2019-09-08Rollup merge of #64255 - varkor:bool-to-option, r=CentrilMazdak Farrokhzad-0/+55
Add methods for converting `bool` to `Option<T>` This provides a reference implementation for https://github.com/rust-lang/rfcs/pull/2757.
2019-09-07Support "soft" feature-gating using a lintVadim Petrochenkov-2/+4
Use it for feature-gating `#[bench]`
2019-09-07Add tracking issuevarkor-2/+2
2019-09-07Move `libcore/bool/mod.rs` to `libcore/bool.rs`varkor-3/+1
2019-09-07Add `bool::then` and `bool::then_with`varkor-1/+50
2019-09-07Add "bool" lang itemvarkor-0/+8
2019-09-06Rollup merge of #64208 - guanqun:py-is-not-none, r=matkladMazdak Farrokhzad-1/+1
it's more pythonic to use 'is not None' in python files
2019-09-06Rollup merge of #63969 - GuillaumeGomez:option-docs-example, r=sfacklerMazdak Farrokhzad-0/+31
Add missing examples for Option type cc @rust-lang/docs
2019-09-06A few cosmetic improvements to code & comments in liballoc and libcoreAlexander Regueiro-8/+8
2019-09-06Add Iterator comparison methods that take a comparison functionTim Vermeulen-6/+160
2019-09-06Rollup merge of #64174 - GuillaumeGomez:missing-iterator-examples, r=sfacklerMazdak Farrokhzad-0/+80
Add missing code examples on Iterator trait Fixes #63865 cc @rust-lang/docs
2019-09-06it's more pythonic to use 'is not None' in python filesGuanqun Lu-1/+1
2019-09-05Add missing code examples on Iterator traitGuillaume Gomez-0/+80
2019-09-05Rollup merge of #62848 - matklad:xid-unicode, r=petrochenkovMazdak Farrokhzad-408/+4
Use unicode-xid crate instead of libcore This PR proposes to remove `char::is_xid_start` and `char::is_xid_continue` functions from `libcore` and use `unicode_xid` crate from crates.io (note that this crate is already present in rust-lang/rust's Cargo.lock). Reasons to do this: * removing rustc-binary-specific stuff from libcore * making sure that, across the ecosystem, there's a single definition of what rust identifier is (`unicode-xid` has almost 10 million downs, as a `proc_macro2` dependency) * making it easier to share `rustc_lexer` crate with rust-analyzer: no need to `#[cfg]` if we are building as a part of the compiler Reasons not to do this: * increased maintenance burden: we'll need to upgrade unicode version both in libcore and in unicode-xid. However, this shouldn't be a too heavy burden: just running `./unicode.py` after new unicode version. I (@matklad) am ready to be a t-compiler side maintainer of unicode-xid. Moreover, given that xid-unicode is an important dependency of syn, *someone* needs to maintain it anyway. * xid-unicode implementation is significantly slower. It uses a more compact table with binary search, instead of a trie. However, this shouldn't matter in practice, because we have fast-path for ascii anyway, and code size savings is a plus. Moreover, in #59706 not using libcore turned out to be *faster*, presumably beacause checking for whitespace with match is even faster. <details> <summary>old description</summary> Followup to #59706 r? @eddyb Note that this doesn't actually remove tables from libcore, to avoid conflict with https://github.com/rust-lang/rust/pull/62641. cc https://github.com/unicode-rs/unicode-xid/pull/11 </details>
2019-09-05Rollup merge of #64142 - lzutao:fix-doc-cmp, r=jonas-schievinkMazdak Farrokhzad-6/+14
Fix doc links in `std::cmp` module r? @jonas-schievink
2019-09-05Rollup merge of #63985 - ghedo:stabilize_pin_into_inner, r=alexcrichtonMazdak Farrokhzad-2/+2
Stabilize pin_into_inner in 1.39.0 FCP: https://github.com/rust-lang/rust/issues/60245#issuecomment-522258129 Closes #60245
2019-09-05Rollup merge of #63549 - sfanxiang:rev-rposition, r=scottmcmMazdak Farrokhzad-7/+6
Rev::rposition counts from the wrong end Introduced in #43074. cc @SimonSapin
2019-09-04Fix doc links in `std::cmp` moduleLzu Tao-6/+14
These links are rendered in `core::cmp` but not in `std::cmp`.
2019-09-04Override `StepBy::{try_fold, try_rfold}`Tim Vermeulen-1/+78
2019-09-04remove XID and Pattern_White_Space unicode tables from libcoreAleksey Kladov-408/+4
They are only used by rustc_lexer, and are not needed elsewhere. So we move the relevant definitions into rustc_lexer (while the actual unicode data comes from the unicode-xid crate) and make the rest of the compiler use it.
2019-09-04Auto merge of #63166 - ksqsf:master, r=alexcrichtonbors-0/+81
Add Result::cloned{,_err} and Result::copied{,_err} This is a little nice addition to `Result`. 1. I'm not sure how useful are `cloned_err` and `copied_err`, but for the sake of completeness they are here. 2. Naming is similar to `map`/`map_err`. I thought about naming `cloned` as `cloned_ok` and add another method called `cloned` that clones both Ok and Err, but `cloned_ok` should be more prevalent than `cloned_both`.
2019-09-02Auto merge of #63692 - iluuu1994:issue-49660, r=sfacklerbors-0/+8
Test that Wrapping arithmetic ops are implemented for all int types Closes #49660
2019-08-31Fix word repetition in str documentationJulian Gehring-4/+4
Fixes a few repetitions of "like like" in the `trim*` methods documentation of `str`.
2019-08-30Rollup merge of #63999 - GuillaumeGomez:as-ref-missing-links, r=Mark-SimulacrumMazdak Farrokhzad-11/+13
Add missing links on AsRef trait cc @rust-lang/docs
2019-08-30Rev::rposition counts from the wrong endXiang Fan-7/+6
Because of a compiler bug that adding `Self: ExactSizeIterator` makes the compiler forget `Self::Item` is `<I as Iterator>::Item`, we remove this specialization for now.
2019-08-30Add missing examples for Option typeGuillaume Gomez-0/+31
2019-08-30Add a "diagnostic item" schemeOliver Scherer-1/+2
This allows lints and other diagnostics to refer to items by a unique ID instead of relying on whacky path resolution schemes that may break when items are relocated.
2019-08-29Add missing links on AsRef traitGuillaume Gomez-11/+13
2019-08-29Rollup merge of #63992 - lzutao:integer-ord, r=nagisaMazdak Farrokhzad-2/+2
Small improvement for Ord implementation of integers Godbolt link: https://godbolt.org/z/tuTDOg ### Before **asm** ```asm example::cmp: mov eax, dword ptr [rdi] xor ecx, ecx cmp eax, dword ptr [rsi] seta cl mov eax, 255 cmovae eax, ecx ret ``` **llvm-mca** ``` Iterations: 100 Instructions: 700 Total Cycles: 217 Total uOps: 1100 Dispatch Width: 6 uOps Per Cycle: 5.07 IPC: 3.23 Block RThroughput: 1.8 ``` ### After **asm** ```asm example::cmp: mov eax, dword ptr [rdi] xor ecx, ecx cmp eax, dword ptr [rsi] setne cl mov eax, 255 cmovae eax, ecx ret ``` **llvm-mca** ``` Iterations: 100 Instructions: 700 Total Cycles: 209 Total uOps: 1000 Dispatch Width: 6 uOps Per Cycle: 4.78 IPC: 3.35 Block RThroughput: 1.7 ``` r? @nagisa
2019-08-29Small improvement for Ord implementation of integersLzu Tao-2/+2
2019-08-28Stabilize pin_into_inner in 1.39.0Alessandro Ghedini-2/+2
FCP: https://github.com/rust-lang/rust/issues/60245#issuecomment-522258129 Closes #60245
2019-08-28add missing `#[repr(C)]` on a unionDodo-0/+1
2019-08-26Rollup merge of #63845 - DevQps:47091-remove-bad-example, r=nikomatsakisMazdak Farrokhzad-8/+0
Removed a confusing FnOnce example # Description See #47091 for a discussion. ## Changes - Removed an example that might suggest readers that square_x is (only) FnOnce. closes #47091
2019-08-26Auto merge of #62891 - vext01:improve-black-box-docs, r=RalfJung,Centril,gnzlbgbors-4/+12
Improve the documentation for std::hint::black_box. The other day a colleague was reviewing some of my code which was using `black_box` to block constant propogation. There was a little confusion because the documentation kind of implies that `black_box` is only useful for dead code elimination, and only in benchmarking scenarios. The docs currently say: > A function that is opaque to the optimizer, to allow benchmarks to pretend to use outputs to assist in avoiding dead-code elimination. Here is our discussion, in which I show (using godbolt) that a black box can also block constant propagation: https://github.com/softdevteam/yk/pull/21#discussion_r302985038 This change makes the docstring for `black_box` a little more general, and while we are here, I've added an example (the same one from our discussion). ![image](https://user-images.githubusercontent.com/604955/61701322-ddf1e400-ad35-11e9-878c-b5b44a20770c.png) OK to go in?
2019-08-24Improve the documentation for std::hint::black_box.Edd Barrett-4/+12
2019-08-24Auto merge of #63823 - petrochenkov:noapply2, r=matthewjasperbors-8/+0
Audit uses of `apply_mark` in built-in macros + Remove default macro transparencies Every use of `apply_mark` in a built-in or procedural macro is supposed to look like this ```rust location.with_ctxt(SyntaxContext::root().apply_mark(ecx.current_expansion.id)) ``` where `SyntaxContext::root()` means that the built-in/procedural macro is defined directly, rather than expanded from some other macro. However, few people understood what `apply_mark` does, so we had a lot of copy-pasted uses of it looking e.g. like ```rust span = span.apply_mark(ecx.current_expansion.id); ``` , which doesn't really make sense for procedural macros, but at the same time is not too harmful, if the macros use the traditional `macro_rules` hygiene. So, to fight this, we stop using `apply_mark` directly in built-in macro implementations, and follow the example of regular proc macros instead and use analogues of `Span::def_site()` and `Span::call_site()`, which are much more intuitive and less error-prone. - `ecx.with_def_site_ctxt(span)` takes the `span`'s location and combines it with a def-site context. - `ecx.with_call_site_ctxt(span)` takes the `span`'s location and combines it with a call-site context. Even if called multiple times (which sometimes happens due to some historical messiness of the built-in macro code) these functions will produce the same result, unlike `apply_mark` which will grow the mark chain further in this case. --- After `apply_mark`s in built-in macros are eliminated, the remaining `apply_mark`s are very few in number, so we can start passing the previously implicit `Transparency` argument to them explicitly, thus eliminating the need in `default_transparency` fields in hygiene structures and `#[rustc_macro_transparency]` annotations on built-in macros. So, the task of making built-in macros opaque can now be formulated as "eliminate `with_legacy_ctxt` in favor of `with_def_site_ctxt`" rather than "replace `#[rustc_macro_transparency = "semitransparent"]` with `#[rustc_macro_transparency = "opaque"]`". r? @matthewjasper
2019-08-24Added an extra line to make the formatting conform to the rest of the document.Christian-0/+1
2019-08-24Removed the confusing FnOnce example. closes #47091Christian-9/+0
2019-08-23Auto merge of #63808 - Rosto75:master, r=KodrAusbors-2/+2
A bunch of minor documentation tweaks and fixes.
2019-08-23Remove default macro transparenciesVadim Petrochenkov-8/+0
All transparancies are passed explicitly now. Also remove `#[rustc_macro_transparency]` annotations from built-in macros, they are no longer used. `#[rustc_macro_transparency]` only makes sense for declarative macros now.