about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2022-09-24Rollup merge of #102186 - ink-feather-org:const_try_trait, r=fee1-deadMatthias Krüger-21/+104
Add const_closure, Constify Try trait Adds a struct for creating const `FnMut` closures (for now just copy pasted form my [const_closure](https://crates.io/crates/const_closure) crate). I'm not sure if this way is how it should be done. The `ConstFnClosure` and `ConstFnOnceClosure` structs can probably also be entirely removed. This is then used to constify the try trait. Not sure if i should add const_closure in its own pr and maybe make it public behind a perma-unstable feature gate. cc ```@fee1-dead``` ```@rust-lang/wg-const-eval```
2022-09-24Rollup merge of #100823 - WaffleLapkin:less_offsets, r=scottmcmMatthias Krüger-48/+48
Refactor some `std` code that works with pointer offstes This PR replaces `pointer::offset` in standard library with `pointer::add` and `pointer::sub`, [re]moving some casts and using `.addr()` while we are at it. This is a more complicated refactor than all other sibling PRs, so take a closer look when reviewing, please 😃 (though I've checked this multiple times and it looks fine). r? ````@scottmcm```` _split off from #100746, continuation of #100822_
2022-09-24Auto merge of #102167 - thomcc:exclusive-inline, r=scottmcmbors-1/+8
Add `#[inline]` to trivial functions on `core::sync::Exclusive` When optimizing for size things like these sometimes don't inlined even though they're generic. This is bad because they're no-ops. Only dodgy one is poll I guess since it forwards to the inner poll, but it's not like we're doing `#[inline(always)]` here.
2022-09-24Auto merge of #100845 - timvermeulen:iter_compare, r=scottmcmbors-62/+81
Use internal iteration in `Iterator` comparison methods Updates the `Iterator` methods `cmp_by`, `partial_cmp_by`, and `eq_by` to use internal iteration on `self`. I've also extracted their shared logic into a private helper function `iter_compare`, which will either short-circuit once the comparison result is known or return the comparison of the lengths of the iterators. This change also indirectly benefits calls to `cmp`, `partial_cmp`, `eq`, `lt`, `le`, `gt`, and `ge`. Unsurprising benchmark results: iterators that benefit from internal iteration (like `Chain`) see a speedup, while other iterators are unaffected. ``` name before ns/iter after ns/iter diff ns/iter diff % speedup iter::bench_chain_partial_cmp 208,301 54,978 -153,323 -73.61% x 3.79 iter::bench_partial_cmp 55,527 55,702 175 0.32% x 1.00 iter::bench_lt 55,502 55,322 -180 -0.32% x 1.00 ```
2022-09-23Constify Residual behind const_tryonestacked-2/+5
2022-09-23Remove unused `ConstFn(Once)Closure` structs.onestacked-125/+0
2022-09-23Added some spacing in const closureonestacked-0/+10
2022-09-23Added const Default impls for Arrays and Tuples.onestacked-2/+4
2022-09-23Rollup merge of #102115 - Alfriadox:master, r=thomccMatthias Krüger-0/+23
Add examples to `bool::then` and `bool::then_some` Added examples to `bool::then` and `bool::then_some` to show the distinction between the eager evaluation of `bool::then_some` and the lazy evaluation of `bool::then`.
2022-09-23Rollup merge of #102094 - GuillaumeGomez:bool-from-str-missing-docs, r=scottmcmMatthias Krüger-2/+2
Add missing documentation for `bool::from_str` Fixes #101870.
2022-09-23Fixed Doc-Testsonestacked-6/+6
2022-09-23Constifed Try traitonestacked-19/+34
2022-09-23Added const_closureonestacked-0/+180
2022-09-22rustfmtScott McMurray-10/+4
2022-09-22Make ZST checks in core/alloc more readableScott McMurray-17/+32
There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff. This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse. *Not* proposed for stabilization at this time. Would be `pub(crate)` except `alloc` wants to use it too. (And while it doesn't matter now, if we ever get something like 85836 making it a const can help codegen be simpler.)
2022-09-22Add `#[inline]` to trivial functions on `core::sync::Exclusive`Thom Chiovoloni-1/+8
2022-09-22Rollup merge of #102144 - chriss0612:const_convert_control_flow, r=scottmcmMatthias Krüger-2/+4
Extend const_convert with const {FormResidual, Try} for ControlFlow. Very small change so I just used the existing `const_convert` feature flag. #88674 Newly const API: ``` impl<B, C> const ops::Try for ControlFlow<B, C>; impl<B, C> const ops::FromResidual for ControlFlow<B, C>; ``` `@usbalbin` I hope it is ok that I added to your feature.
2022-09-22Derive Eq/PartialEq instead of manually implementing itScott McMurray-15/+23
2022-09-22Constify {FormResidual, Try} for ControlFlowonestacked-2/+4
2022-09-22Apply changes proposed in the reviewMaybe Waffle-33/+33
2022-09-22Added which number is computed in compute_float.Orson Peters-1/+1
2022-09-22Add missing assertionVenus Xeon-Blonde-0/+1
2022-09-22Auto merge of #100982 - fee1-dead-contrib:const-impl-requires-const-trait, ↵bors-59/+61
r=oli-obk Require `#[const_trait]` on `Trait` for `impl const Trait` r? `@oli-obk`
2022-09-21Remove trailing whitespaceVenus Xeon-Blonde-9/+9
Trailing whitespace seemed to be causing the CI checks to error out.
2022-09-22Rollup merge of #102102 - GuillaumeGomez:doc-aliases-sized-trait, r=thomccYuki Okushi-0/+1
Add doc aliases on Sized trait Fixes #101267. It adds both `?` and `?Sized` doc aliases for the `Sized` trait. Some screenshots of the result: ![Screenshot from 2022-09-21 16-19-55](https://user-images.githubusercontent.com/3050060/191529854-65a79b75-6c20-4fd4-88c2-56d617d1acff.png) ![Screenshot from 2022-09-21 16-20-04](https://user-images.githubusercontent.com/3050060/191529857-2d11b477-5c5d-4080-9382-0b07950fd7f6.png)
2022-09-21Add examples to `bool::then` and `bool::then_some`Venus Xeon-Blonde-0/+22
Added examples to `bool::then` and `bool::then_some` to show the distinction between the eager evaluation of `bool::then_some` and the lazy evaluation of `bool::then`.
2022-09-21Add `rustc_allow_const_fn_unstable` annotations to pre-existing `Layout` methodsScott McMurray-1/+7
2022-09-21Add doc aliases on Sized traitGuillaume Gomez-0/+1
2022-09-21Rollup merge of #101995 - scottmcm:carrying-mul-example, r=Mark-SimulacrumDylan DPC-0/+30
Add another example for `uN::carrying_mul` The prose talks about doing this, so might as well add a simple code example of it too.
2022-09-21Add missing documentation for `bool::from_str`Guillaume Gomez-2/+2
2022-09-21Auto merge of #100214 - scottmcm:strict-range, r=thomccbors-31/+268
Optimize `array::IntoIter` `.into_iter()` on arrays was slower than it needed to be (especially compared to slice iterator) since it uses `Range<usize>`, which needs to handle degenerate ranges like `10..4`. This PR adds an internal `IndexRange` type that's like `Range<usize>` but with a safety invariant that means it doesn't need to worry about those cases -- it only handles `start <= end` -- and thus can give LLVM more information to optimize better. I added one simple demonstration of the improvement as a codegen test. (`vec::IntoIter` uses pointers instead of indexes, so doesn't have this problem, but that only works because its elements are boxed. `array::IntoIter` can't use pointers because that would keep it from being movable.)
2022-09-20Add `ptr::Alignment` typeScott McMurray-53/+90
Essentially no new code here, just exposing the previously-`pub(crate)` `ValidAlign` type under the name from the ACP.
2022-09-20Add the `#[derive_const]` attributeDeadbeef-0/+17
2022-09-19Optimize `array::IntoIter`Scott McMurray-31/+268
`.into_iter()` on arrays was slower than it needed to be (especially compared to slice iterator) since it uses `Range<usize>`, which needs to handle degenerate ranges like `10..4`. This PR adds an internal `IndexRange` type that's like `Range<usize>` but with a safety invariant that means it doesn't need to worry about those cases -- it only handles `start <= end` -- and thus can give LLVM more information to optimize better. I added one simple demonstration of the improvement as a codegen test.
2022-09-19Rollup merge of #101798 - y86-dev:const_waker, r=lcnrMatthias Krüger-3/+7
Make `from_waker`, `waker` and `from_raw` unstably `const` Make - `Context::from_waker` - `Context::waker` - `Waker::from_raw` `const`. Also added a small test.
2022-09-19Rollup merge of #101389 - lukaslueg:rcgetmutdocs, r=m-ou-seMatthias Krüger-9/+12
Tone down explanation on RefCell::get_mut The language around `RefCell::get_mut` is remarkably sketchy and especially to the novice seems to quite strongly discourage using the method ("be cautious", "Also, please be aware", "special circumstances", "usually not what you want"). It was added six years ago in #40634 due to confusion about when to use `get_mut` and `borrow_mut`. While its signature limits the use-cases for `get_mut`, there is no chance for a safety footgun, and readers can be made aware of `borrow_mut` more softly. I've also just sent a [PR](https://github.com/rust-lang/rust-clippy/issues/9044) to lint situations where `get_mut` could be used to improve ergonomics and performance. So this PR tones down the language around `get_mut` and also brings it more in line with [`std::sync::Mutex::get_mut()`](https://doc.rust-lang.org/stable/std/sync/struct.Mutex.html#method.get_mut).
2022-09-19Added tracking issuey86-dev-3/+3
2022-09-18Add another example for `uN::carrying_mul`Scott McMurray-0/+30
The prose talked about doing this, so might as well add a simple code example of it too.
2022-09-18Auto merge of #101816 - raldone01:cleanup/select_nth_unstable, r=Mark-Simulacrumbors-7/+4
Cleanup slice sort related closures in core and alloc
2022-09-17Auto merge of #101949 - matthiaskrgr:rollup-xu5cqnd, r=matthiaskrgrbors-173/+190
Rollup of 7 pull requests Successful merges: - #101093 (Initial version of 1.64 release notes) - #101713 (change AccessLevels representation) - #101821 (Bump Unicode to version 15.0.0, regenerate tables) - #101826 (Enforce "joined()" and "joined_with_noop()" test) - #101835 (Allow using vendoring when running bootstrap from outside the source root) - #101942 (Revert "Copy stage0 binaries into stage0-sysroot") - #101943 (rustdoc: remove unused CSS `.non-exhaustive { margin-bottom }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-09-17Rollup merge of #101821 - thomcc:unicode-15, r=ManishearthMatthias Krüger-173/+190
Bump Unicode to version 15.0.0, regenerate tables r? `@Mark-Simulacrum`
2022-09-17Rollup merge of #101672 - idigdoug:array_try_into, r=Mark-SimulacrumMatthias Krüger-1/+70
array docs - advertise how to get array from slice On my first Rust project, I spent more time than I care to admit figuring out how to efficiently get an array from a slice. Update the array documentation to explain this a bit more clearly. (As a side note, it's a bit unfortunate that get-array-from-slice is only available via trait since that means it can't be used from const functions yet.)
2022-09-17Auto merge of #101784 - reitermarkus:const-memchr, r=thomccbors-25/+23
Simplify `const` `memchr`. Extracted from https://github.com/rust-lang/rust/pull/101607. Removes the need for `const_eval_select`.
2022-09-16Rollup merge of #101802 - chriss0612:const_fn_trait_ref_impls, r=fee1-deadDylan DPC-10/+15
Constify impl Fn* &(mut) Fn* Tracking Issue: [101803](https://github.com/rust-lang/rust/issues/101803) Feature gate: `#![feature(const_fn_trait_ref_impls)]` This feature allows using references to Fn* Items as Fn* Items themself in a const context.
2022-09-16Add `const_trait` to `Allocator`Deadbeef-0/+5
2022-09-16append_const_msg for std traitsDeadbeef-59/+16
2022-09-16Mark `Drop` with `#[const_trait]`Deadbeef-0/+1
2022-09-16Prevent errors for stage0 rustc buildDeadbeef-1/+1
2022-09-16Add more `const_trait` annotationsDeadbeef-3/+26
2022-09-16Add `const_trait`sDeadbeef-0/+11