about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2020-05-13Improve comments in iter::StepCAD97-3/+3
2020-04-08Adjust Step::forward_checked docs for large typesCAD97-12/+7
Co-Authored-By: Nadrieril Feneanar <nadrieril@users.noreply.github.com>
2020-04-08Redesign the Step traitCAD97-201/+539
2020-04-08Add inherent impls for unchecked math intrinsicsCAD97-0/+102
2020-04-06Use integer assoc consts in libcoreLinus Färnstrand-5/+5
2020-04-06Use assoc float consts in libcoreLinus Färnstrand-28/+18
2020-04-06Rollup merge of #70782 - faern:use-assoc-float-consts, r=dtolnayMazdak Farrokhzad-24/+4
Stop importing the float modules in documentation Follow up to #69860. I realized I had not searched for and fixed this for the float values. So with this PR they also use the associated constants instead of the module level constants. For the documentation where it also was using the `consts` submodule I opted to change it to import that directly. This becomes more in line with how other docs that use the `consts` submodule looks. And it also makes it so there are not two `f32` or `f64` things in the current namespace (both the module and the primitive type) and then hopefully confusing documentation readers less. r? @dtolnay
2020-04-06Rollup merge of #70750 - cuviper:direct-fuse, r=scottmcmMazdak Farrokhzad-74/+63
Match options directly in the Fuse implementation Rather than using `as_ref()`, `as_mut()`, and `?`, we can use `match` directly to save a lot of generated code. This was mentioned as a possibility in https://github.com/rust-lang/rust/pull/70366#issuecomment-603462546, and I found that it had a very large impact on #70332 using `Fuse` within `Chain`. Let's evaluate this change on its own first.
2020-04-05Rollup merge of #70777 - faern:use-assoc-int-consts2, r=dtolnayDylan DPC-39/+23
Don't import integer and float modules, use assoc consts Stop importing the standard library integer and float modules to reach the `MIN`, `MAX` and other constants. They are available directly on the primitive types now. This PR is a follow up of #69860 which made sure we use the new constants in documentation. This type of change touches a lot of files, and previously all my assoc int consts PRs had collisions and were accepted only after a long delay. So I'd prefer to do it in smaller steps now. Just removing these imports seem like a good next step. r? @dtolnay
2020-04-05Rollup merge of #70760 - PonasKovas:docs, r=Dylan-DPCDylan DPC-2/+4
docs: make the description of Result::map_or more clear The documentation of [`Result::map_or`](https://doc.rust-lang.org/std/result/enum.Result.html#method.map_or) is very unclear and confusing, probably because it was copied straight from [`Option::map_or`](https://doc.rust-lang.org/std/option/enum.Option.html#method.map_or) and someone forgot to adapt it for Result.
2020-04-05Make libcore float constant examples similar to libstdLinus Färnstrand-12/+4
2020-04-05Stop importing the float modules. Use assoc constsLinus Färnstrand-12/+0
2020-04-05Stop importing int/float modules in libcoreLinus Färnstrand-39/+23
2020-04-05Rollup merge of #70752 - yoshuawuyts:slice_fill, r=dtolnayDylan DPC-0/+24
Add slice::fill Adds the `slice::fill` method to fill a slice with an item. This replaces manual for loops where items are copied one-by-one. This is a counterpart to C++20's [`std::fill`](https://en.cppreference.com/w/cpp/algorithm/fill) function. ## Usage ```rust let mut buf = vec![0; 10]; buf.fill(1); assert_eq!(buf, vec![1; 10]); ``` ## Performance When compiling in release mode, for `[u8]` and `[u16]` this method will optimize to a `memset(3)` call ([godbolt](https://godbolt.org/z/85El_c)). The initial implementation relies on LLVM's optimizer to make it as fast as possible for any given input. But as @jonas-schievink [pointed out](https://twitter.com/sheevink/status/1245756597453885442) this can later be optimized through specialization to guarantee it has a specific performance profile. ## Why now? Conversations about adding `slice::fill` are not new. In fact, https://github.com/rust-lang/rfcs/issues/2067 was opened 3 years ago about this exact topic. However discussion stranded while discussing implementation details, and it's not seen much forward motion since. In ["The Hunt for the Fastest Zero"](https://travisdowns.github.io/blog/2020/01/20/zero.html) Travis Downs provides disects C++'s `std::fill` performance profile on gcc, comparing it among others to `memset(3)`. Even though `memset(3)` outperforms `std::fill` in their tests, the author notes the following: > That the optimization fails, perhaps unexpectedly, in some cases is unfortunate but it’s nice that you can fix it yourself. [...] Do we throw out modern C++ idioms, at least where performance matters, for example by replacing std::fill with memset? I don’t think so. Much of the article focuses on how how to fix the performance of `std::fill` by providing specializations for specific input. In Rust we don't have any dedicated methods to fill slices with values, so it either needs to be optimized at the MIR layer, or more likely rely on LLVM's optimizer. By adding a dedicated method for filling slices with values it opens up the ability for us to in the future guarantee that e.g. `Vec<u8>` will always optimize to `memset` even in debug mode. Or perhaps provide stronger guarantees about memory when zeroing values when a certain flag is passed. But regardless of that, it improves general ergonomics of working with slices by providing a dedicated method with documentation and examples. ## References - [slice-fill prototype on docs.rs](https://docs.rs/slice-fill/1.0.1/slice_fill/) - [The Hunt For The Fastest Zero](https://travisdowns.github.io/blog/2020/01/20/zero.html) - [Safe memset for slices](https://github.com/rust-lang/rfcs/issues/2067) - [C++20 std::fill](https://en.cppreference.com/w/cpp/algorithm/fill) - [ASM output on Godbolt](https://godbolt.org/z/5-XU66)
2020-04-05Add slice::fillYoshua Wuyts-0/+24
2020-04-04docs: make the description of Result::map_or more clearPonas-2/+4
2020-04-03Rollup merge of #69860 - faern:use-assoc-int-consts, r=dtolnayMazdak Farrokhzad-29/+27
Use associated numeric consts in documentation Now when the associated constants on int/float types are stabilized and the recommended way of accessing said constants (#68952). We can start using it in this repository, and recommend it via documentation example code. This PR is the reincarnation of #67913 minus the actual adding + stabilization of said constants. (EDIT: Now it's only changing the documentation. So users will see the new consts, but we don't yet update the internal code) Because of how fast bit rot happens to PRs that touch this many files, it does not try to replace 100% of the old usage of the constants in the entire repo, but a good chunk of them.
2020-04-03Use a macro to expand the specialized FuseJosh Stone-41/+23
2020-04-03Open-code Fuse's Option matchesJosh Stone-35/+42
2020-04-03Rollup merge of #70731 - JohnTitor:follow-up-rustc-middle, r=eddybDylan DPC-3/+6
Minor follow-up after renaming librustc(_middle) Fixes #70537 r? @Centril @eddyb
2020-04-03Rollup merge of #70728 - TimDiekmann:allocref-doc, r=AmanieuDylan DPC-19/+22
Minor doc improvements on `AllocRef` r? @Amanieu
2020-04-03Minor follow-up after renaming librustc(_middle)Yuki Okushi-3/+6
2020-04-03Replace float module consts with assoc consts in documentationLinus Färnstrand-11/+9
2020-04-03Replace max/min_value() with MAX/MIN assoc constsLinus Färnstrand-12/+12
2020-04-03Make documentation examples use new integer assoc constsLinus Färnstrand-6/+6
2020-04-03Update mod.rsTim Diekmann-1/+1
2020-04-03Minor doc improvements on `AllocRef`Tim Diekmann-19/+22
2020-04-03Rollup merge of #70708 - Pocakking:fix-ascii-case-conv-typo, r=sfacklerMazdak Farrokhzad-2/+2
Fix typo in u8::to_ascii_uppercase and u8::to_ascii_lowercase Corrects misspelling of fifth.
2020-04-03Rollup merge of #70700 - jrvidal:include-macro-paths, r=Dylan-DPCMazdak Farrokhzad-5/+11
Expand on platform details of `include_xxx` macros This is a small detail that is not explicitly mentioned, but it left me scratching my head for a while until I looked into its implementation details. Maybe worth mentioning.
2020-04-03Rollup merge of #70691 - TimDiekmann:allocref-docs, r=RalfJungMazdak Farrokhzad-5/+7
Improve docs in `AllocRef` r? @RalfJung
2020-04-03Rollup merge of #70487 - Mark-Simulacrum:float-unchecked-casts, r=SimonSapinMazdak Farrokhzad-18/+29
Stabilize float::to_int_unchecked This renames and stabilizes unsafe floating point to integer casts, which are intended to be the substitute for the currently unsound `as` behavior, once that changes to safe-but-slower saturating casts. As such, I believe this also likely unblocks #10184 (our oldest I-unsound issue!), as once this rolls out to stable it would be far easier IMO to change the behavior of `as` to be safe by default. This does not stabilize the trait or the associated method, as they are deemed internal implementation details (and consumers should not, generally, want to expose them, as in practice all callers likely know statically/without generics what the return type is). Closes #67058
2020-04-02Fix typo in u8::to_ascii_uppercase and u8::to_ascii_lowercasePocakking-2/+2
fith => fifth
2020-04-02Expand on platform details of `include_xxx` macrosRoberto Vidal-5/+11
2020-04-02Rollup merge of #70281 - xfix:infallible-hash, r=dtolnayMazdak Farrokhzad-0/+8
Implement Hash for Infallible https://www.reddit.com/r/rust/comments/fmllgx/never_crate_stable_alternative_to/ lists not implementing `Hash` as a reason for the `never` crate. I see no reason not to implement `Hash` for `Infallible`, so might as well do it. No changes necessary for `!`, because `!` already implements `Hash` (see https://github.com/rust-lang/rust/pull/51404).
2020-04-02Improve docs in `AllocRef`Tim Diekmann-5/+7
2020-04-02Auto merge of #70362 - TimDiekmann:alloc-overhaul, r=Amanieubors-1043/+906
Overhaul of the `AllocRef` trait to match allocator-wg's latest consens; Take 2 GitHub won't let me reopen #69889 so I make a new PR. In addition to #69889 this fixes the unsoundness of `RawVec::into_box` when using allocators supporting overallocating. Also it uses `MemoryBlock` in `AllocRef` to unify `_in_place` methods by passing `&mut MemoryBlock`. Additionally, `RawVec` now checks for `size_of::<T>()` again and ignore every ZST. The internal capacity of `RawVec` isn't used by ZSTs anymore, as `into_box` now requires a length to be specified. r? @Amanieu fixes rust-lang/wg-allocators#38 fixes rust-lang/wg-allocators#41 fixes rust-lang/wg-allocators#44 fixes rust-lang/wg-allocators#51
2020-04-01Rollup merge of #70081 - lcnr:issue68387, r=varkorDylan DPC-9/+9
add `unused_braces` lint Add the lint `unused_braces` which is warn by default. `unused_parens` is also extended and now checks anon consts. closes #68387 r? @varkor
2020-03-31fix internal lint falloutBastian Kauschke-9/+9
2020-03-31Rollup merge of #70588 - Coder-256:str-split-at-docs, r=Dylan-DPCMazdak Farrokhzad-2/+2
Fix incorrect documentation for `str::{split_at, split_at_mut}` The documentation for each method currently states: > Panics if `mid` is not on a UTF-8 code point boundary, or if it is beyond the last code point of the string slice. However, this is not consistent with the real behavior, or that of the corresponding methods for `[T]` slices. A comment inside each of the `str` methods states: > is_char_boundary checks that the index is in [0, .len()] That is what I would expect the behavior to be, and in fact this seems to be the real behavior. For example ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8e03dcc209d4dd176df2297523f9fee1)): ```rust fn main() { // Prints ("abc", "") and doesn't panic println!("{:?}", "abc".split_at(3)); } ``` In this case, I would interpret "the last code point of the string slice" to mean the byte at index 2 in UTF-8. However, it is possible to pass an index of 3, which is definitely "beyond the last code point of the string slice". I think that this is much clearer, but feel free to bikeshed.
2020-03-31Rollup merge of #69784 - benesch:fast-strip-prefix-suffix, r=kennytmMazdak Farrokhzad-30/+92
Optimize strip_prefix and strip_suffix with str patterns As mentioned in https://github.com/rust-lang/rust/issues/67302#issuecomment-585639226. I'm not sure whether adding these methods to `Pattern` is desirable—but they have default implementations so the change is backwards compatible. Plus it seems like they're slated for wholesale replacement soon anyway? #56345 ---- Constructing a Searcher in strip_prefix and strip_suffix is unnecessarily slow when the pattern is a fixed-length string. Add strip_prefix and strip_suffix methods to the Pattern trait, and add optimized implementations of these methods in the str implementation. The old implementation is retained as the default for these methods.
2020-03-30Fix incorrect documentation for `str::{split_at, split_at_mut}`Jacob Greenfield-2/+2
2020-03-30Optimize strip_prefix and strip_suffix with str patternsNikhil Benesch-30/+92
Constructing a Searcher in strip_prefix and strip_suffix is unnecessarily slow when the pattern is a fixed-length string. Add strip_prefix and strip_suffix methods to the Pattern trait, and add optimized implementations of these methods in the str implementation. The old implementation is retained as the default for these methods.
2020-03-30rustc -> rustc_middle part 2Mazdak Farrokhzad-1/+1
2020-03-30rustc -> rustc_middle part 1Mazdak Farrokhzad-2/+2
2020-03-29Rollup merge of #70140 - Nemo157:result-flatten, r=AmanieuMazdak Farrokhzad-1/+33
Add Result<Result<T, E>, E>::flatten -> Result<T, E> This PR makes this possible (modulo type inference): ```rust assert_eq!(Ok(6), Ok(Ok(6)).flatten()); ``` Tracking issue: #70142 <sub>largely cribbed directly from <https://github.com/rust-lang/rust/pull/60256></sub>
2020-03-29Stabilize float::to_int_uncheckedMark Rousskov-18/+29
This renames and stabilizes unsafe floating point to integer casts, which are intended to be the substitute for the currently unsound `as` behavior, once that changes to safe-but-slower saturating casts.
2020-03-29Fix links for `AllocInit` methodsTim Diekmann-2/+2
2020-03-29Revert "Fix links for `AllocInit` methods"Tim Diekmann-2/+2
This reverts commit d241db2d4e620277ddb47dd26779982709f851d8.
2020-03-29Rollup merge of #70101 - tmiasko:intrinsics-copy, r=eddybMazdak Farrokhzad-112/+112
Add copy bound to atomic & numeric intrinsics
2020-03-29Auto merge of #70370 - petrochenkov:nosmatch, r=Centrilbors-2/+0
Remove attribute `#[structural_match]` and any references to it A small remaining part of https://github.com/rust-lang/rust/issues/63438.