about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2017-11-14Rollup merge of #45970 - GuillaumeGomez:from-str-docs, r=QuietMisdreavusGuillaume Gomez-2/+5
Add missing links in FromStr docs r? @QuietMisdreavus
2017-11-14Fixed several pulldown warnings when documenting libstd.kennytm-1/+1
2017-11-13Add missing links in FromStr docsGuillaume Gomez-2/+5
2017-11-13Rollup merge of #45933 - shanavas786:refactor-filter, r=alexcrichtonkennytm-8/+4
Refactor Option::filter method
2017-11-11Auto merge of #45333 - alkis:master, r=blussbors-30/+136
Improve SliceExt::binary_search performance Improve the performance of binary_search by reducing the number of unpredictable conditional branches in the loop. In addition improve the benchmarks to test performance in l1, l2 and l3 caches on sorted arrays with or without dups. Before: ``` test slice::binary_search_l1 ... bench: 48 ns/iter (+/- 1) test slice::binary_search_l2 ... bench: 63 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 152 ns/iter (+/- 12) test slice::binary_search_l1_with_dups ... bench: 36 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 64 ns/iter (+/- 1) test slice::binary_search_l3_with_dups ... bench: 153 ns/iter (+/- 6) ``` After: ``` test slice::binary_search_l1 ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2 ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 100 ns/iter (+/- 17) test slice::binary_search_l1_with_dups ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3_with_dups ... bench: 98 ns/iter (+/- 14) ```
2017-11-11Improve the performance of binary_search by reducing the number ofAlkis Evlogimenos-30/+136
unpredictable conditional branches in the loop. In addition improve the benchmarks to test performance in l1, l2 and l3 caches on sorted arrays with or without dups. Before: ``` test slice::binary_search_l1 ... bench: 48 ns/iter (+/- 1) test slice::binary_search_l2 ... bench: 63 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 152 ns/iter (+/- 12) test slice::binary_search_l1_with_dups ... bench: 36 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 64 ns/iter (+/- 1) test slice::binary_search_l3_with_dups ... bench: 153 ns/iter (+/- 6) ``` After: ``` test slice::binary_search_l1 ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2 ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 100 ns/iter (+/- 17) test slice::binary_search_l1_with_dups ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3_with_dups ... bench: 98 ns/iter (+/- 14) ```
2017-11-11Refactor Option::filter methodShanavas M-8/+4
2017-11-11Rollup merge of #45919 - lukaramu:patch-1, r=kennytmGuillaume Gomez-1/+1
Fix broken link markup in Hasher::finish docs Just a quick fix: there were apostrophes when there needed to be backticks.
2017-11-11Auto merge of #45772 - leodasvacas:fix-auto-bounds-in-trait-objects, ↵bors-1/+1
r=nikomatsakis Fix checking of auto trait bounds in trait objects. Any auto trait is allowed in trait object bounds. Fix duplicate check of type and lifetime parameter count, which we were [emitting twice](https://play.rust-lang.org/?gist=37dbbdbbec62dec423bb8f6d92f137cc&version=stable). Note: This was the last use of `Send` in the compiler, meaning after a new `stage0` we could remove the `send` lang item.
2017-11-10Fix broken link markup in Hasher::finish docsLukas H-1/+1
There were apostrophes when there needed to be backticks.
2017-11-10Rollup merge of #45887 - xfix:assert-eq-trailling-comma, r=dtolnaykennytm-0/+6
Allow a trailling comma in assert_eq/ne macro From Rust beginners IRC: <???> It sure does annoy me that assert_eq!() does not accept a trailing comma after the last argument. <???> ???: File an issue against https://github.com/rust-lang/rust and CC @rust-lang/libs Figured that might as well submit it. Will become insta-stable after merging (danger zone). cc @rust-lang/libs
2017-11-10Rollup merge of #45882 - japaric:gh45802, r=kennytmkennytm-0/+1
fix core for targets with max-atomic-width = 0 closes #45802 cc @kennytm
2017-11-10Rollup merge of #45869 - GuillaumeGomez:debug-doc, r=frewsxcvkennytm-0/+20
Add missing example for Debug trait r? @rust-lang/docs
2017-11-10Rollup merge of #45863 - LukasKalbertodt:add-option-filter, r=dtolnaykennytm-0/+39
Add `Option::filter()` according to RFC 2124 (*old PR: https://github.com/rust-lang/rust/pull/44996*) This is the implementation of [RFC "Add `Option::filter` to the standard library"](https://github.com/rust-lang/rfcs/pull/2124). Tracking issue: https://github.com/rust-lang/rust/issues/45860 **Questions for code reviewers:** - Is the documentation sufficiently long? - Is the documentation easy enough to understand? - Is the position of the new method (after `and_then()`) a good one?
2017-11-10Auto merge of #45773 - Badel2:dotdoteq, r=petrochenkovbors-9/+6
Add error for `...` in expressions Follow-up to https://github.com/rust-lang/rust/pull/44709 Tracking issue: https://github.com/rust-lang/rust/issues/28237 * Using `...` in expressions was a warning, now it's an error * The error message suggests using `..` or `..=` instead, and explains the difference * Updated remaining occurrences of `...` to `..=` r? petrochenkov
2017-11-09Allow a trailing comma in assert_eq/ne macroKonrad Borowski-0/+6
2017-11-08std: Remove `rand` crate and moduleAlex Crichton-3/+2
This commit removes the `rand` crate from the standard library facade as well as the `__rand` module in the standard library. Neither of these were used in any meaningful way in the standard library itself. The only need for randomness in libstd is to initialize the thread-local keys of a `HashMap`, and that unconditionally used `OsRng` defined in the standard library anyway. The cruft of the `rand` crate and the extra `rand` support in the standard library makes libstd slightly more difficult to port to new platforms, namely WebAssembly which doesn't have any randomness at all (without interfacing with JS). The purpose of this commit is to clarify and streamline randomness in libstd, focusing on how it's only required in one location, hashmap seeds. Note that the `rand` crate out of tree has almost always been a drop-in replacement for the `rand` crate in-tree, so any usage (accidental or purposeful) of the crate in-tree should switch to the `rand` crate on crates.io. This then also has the further benefit of avoiding duplication (mostly) between the two crates!
2017-11-09fix core for targets with max-atomic-width = 0Jorge Aparicio-0/+1
closes #45802
2017-11-08Add missing example for Debug traitGuillaume Gomez-0/+20
2017-11-08Add `Option::filter()` according to RFC 2124Lukas Kalbertodt-0/+39
2017-11-08Auto merge of #45379 - cuviper:unit_from_iter, r=alexcrichtonbors-0/+32
impl FromIterator<()> for () This just collapses all unit items from an iterator into one. This is more useful when combined with higher-level abstractions, like collecting to a `Result<(), E>` where you only care about errors: ```rust use std::io::*; data = vec![1, 2, 3, 4, 5]; let res: Result<()> = data.iter() .map(|x| writeln!(stdout(), "{}", x)) .collect(); assert!(res.is_ok()); ```
2017-11-07Auto merge of #44932 - cuviper:unsized-ptr-is_null, r=alexcrichtonbors-6/+63
Remove `T: Sized` on pointer `as_ref()` and `as_mut()` `NonZero::is_zero()` was already casting all pointers to thin `*mut u8` to check for null. The same test on unsized fat pointers can also be used with `as_ref()` and `as_mut()` to get fat references. (This PR formerly changed `is_null()` too, but checking just the data pointer is not obviously correct for trait objects, especially if `*const self` sorts of methods are ever allowed.)
2017-11-07Remove `send` lang item.leonardo.yvens-1/+1
It's completely unused.
2017-11-06Add RefCell<T>::replace_withHavvy-13/+38
2017-11-07Auto merge of #45571 - zackmdavis:regenerate_char_private, r=alexcrichtonbors-74/+83
regenerate libcore/char_private.rs (filed separately from the work in #45569, because of this matter of the updated Unicode data; see also #45567) char_private.rs is generated programmatically by char_private.py, using data retrieved from the Unicode Consortium's website. The motivation here was to make `is_printable` crate-visible (with `pub(crate)`), but it would seem that the Unicode data has changed slightly since char_private.rs was last generated.
2017-11-06Inclusive range updated to `..=` syntaxBadel2-9/+6
2017-11-05Auto merge of #44042 - LukasKalbertodt:ascii-methods-on-instrinsics, ↵bors-0/+644
r=alexcrichton Copy all `AsciiExt` methods to the primitive types directly in order to deprecate it later **EDIT:** [this PR is ready now](https://github.com/rust-lang/rust/pull/44042#issuecomment-333883548). I edited this post to reflect the current status of discussion, which is (apart from code review) pretty much settled. --- This is my current progress in order to prepare stabilization of #39658. As discussed there (and in #39659), the idea is to deprecated `AsciiExt` and copy all methods to the type directly. Apparently there isn't really a reason to have those methods in an extension trait¹. ~~This is **work in progress**: copy&pasting code while slightly modifying the documentation isn't the most exciting thing to do. Therefore I wanted to already open this WIP PR after doing basically 1/4 of the job (copying methods to `&[u8]`, `char` and `&str` is still missing) to get some feedback before I continue. Some questions possibly worth discussing:~~ 1. ~~Does everyone agree that deprecating `AsciiExt` is a good idea? Does everyone agree with the goal of this PR?~~ => apparently yes 2. ~~Are my changes OK so far? Did I do something wrong?~~ 3. ~~The issue of the unstable-attribute is currently set to 0. I would wait until you say "Ok" to the whole thing, then create a tracking issue and then insert the correct issue id. Is that ok?~~ 4. ~~I tweaked `eq_ignore_ascii_case()`: it now takes the argument `other: u8` instead of `other: &u8`. The latter was enforced by the trait. Since we're not bound to a trait anymore, we can drop the reference, ok?~~ => I reverted this, because the interface has to match the `AsciiExt` interface exactly. ¹ ~~Could it be that we can't write `impl [u8] {}`? This might be the reason for `AsciiExt`. If that is the case: is there a good reason we can't write such an impl block? What can we do instead?~~ => we couldn't at the time this PR was opened, but Simon made it possible. /cc @SimonSapin @zackw
2017-11-05Auto merge of #45754 - scottmcm:checked-npot, r=dtolnaybors-1/+3
Fix #18604: next_power_of_two should panic on overflow Fixes https://github.com/rust-lang/rust/issues/18604 Is it possible to write a test for this? My experiments showed `x.py test` running in release mode, so my attempt at a `#[should_panic]` didn't work.
2017-11-04CR feedbackScott McMurray-12/+6
2017-11-04Use Add::add for overflow checks instead of [rustc_inherit_overflow_checks]Scott McMurray-2/+3
2017-11-04Rollup merge of #45718 - Ljzn:patch-2, r=BurntSushikennytm-2/+2
Fix typo `accomodate` -> `accommodate`
2017-11-04Rollup merge of #45610 - strake:atomic_from, r=nagisakennytm-0/+12
impl From<T> for AtomicT
2017-11-03Fix #18604: next_power_of_two should panic on overflowScott McMurray-0/+1
2017-11-03Mark several ascii methods as unstable againLukas Kalbertodt-10/+30
We don't want to stabilize them now already. The goal of this set of commits is just to add inherent methods to the four types. Stabilizing all of those methods can be done later.
2017-11-03Fix lists in doc comments for ascii methods of u8 and charLukas Kalbertodt-2/+4
2017-11-03Add missing space in match armLukas Kalbertodt-2/+2
2017-11-03Tweak documentation for `u8::eq_ignore_ascii_case()`Lukas Kalbertodt-2/+1
2017-11-03Revert signature of eq_ignore_ascii_case() to originalLukas Kalbertodt-2/+2
Since the methods on u8 directly will shadow the AsciiExt methods, we cannot change the signature without breaking everything. It would have been nice to take `u8` as argument instead of `&u8`, but we cannot break stuff! So this commit reverts it to the original `&u8` version.
2017-11-03Make ascii methods on u8 insta-stableLukas Kalbertodt-48/+16
Those methods will shadow the methods of `AsciiExt`, so if we don't make them insta-stable, everyone will hitting stability errors. It is fine adding those as stable, because they are just being moved around [according to sfackler][1]. OPEN QUESTION: this commit also stabilizes the `AsciiExt` methods that were previously feature gated by the `ascii_ctype` feature. Maybe we don't want to stablilize those yet. [1]: https://github.com/rust-lang/rust/pull/44042#issuecomment-329939279
2017-11-03Add all methods of AsciiExt to u8 directlyLukas Kalbertodt-0/+655
This is the first step in order to deprecate AsciiExt. Since this is a WIP commit, there is still some code duplication (notably the static arrays) that will be removed later.
2017-11-03auto trait future compatibility lintleonardo.yvens-0/+6
2017-11-02Fix typoLance John-2/+2
`accomodate` -> `accommodate`
2017-11-02Auto merge of #45306 - whitequark:ref_slice, r=alexcrichtonbors-0/+16
Bring back slice::ref_slice as slice::from_ref. These functions were deprecated and removed in 1.5, but such simple functionality shouldn't require using unsafe code, and it isn't cluttering libstd too much. The original removal was quite contentious (see #27774), since then we've had precedent for including such nuggets of functionality (see rust-lang/rfcs#1789), and @nikomatsakis has provided a lot of use cases in https://github.com/rust-lang/rfcs/pull/1789#issuecomment-314640034. Hence this PR. I'm not too sure what to do with stability, feel free to correct me. It seems pointless to go through stabilization for these functions though. cc @aturon
2017-11-01De-stabilize core::slice::{from_ref, from_ref_mut}.whitequark-2/+2
2017-10-31Auto merge of #44764 - nvzqz:master, r=alexcrichtonbors-0/+76
Implement TryFrom<&[T]> for &[T; N] There are many cases where a buffer with a static compile-time size is preferred over a slice with a dynamic size. This allows for performing a checked conversion from `&[T]` to `&[T; N]`. This may also lead to compile-time optimizations involving `[T; N]` such as loop unrolling. This is my first PR to Rust, so I'm not sure if discussion of this change should happen here or does it need its own RFC? I figured these changes would be a subset of #33417.
2017-10-31since = "1.23.0"M Farkas-Dyck-2/+2
2017-10-29Add link to stablized version of an intrinsicWesley Wiser-0/+3
2017-10-29Fundamental internal iteration with try_foldScott McMurray-181/+934
This is the core method in terms of which the other methods (fold, all, any, find, position, nth, ...) can be implemented, allowing Iterator implementors to get the full goodness of internal iteration by only overriding one method (per direction).
2017-10-29feature = "atomic_from"M Farkas-Dyck-2/+2
2017-10-29Fix references to zero_memory and copy_memory in ptr docsFlorian Hartwig-9/+9