about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-01-19Transform async ResumeTy in generator transformArpad Borsos-0/+5
- Eliminates all the `get_context` calls that async lowering created. - Replace all `Local` `ResumeTy` types with `&mut Context<'_>`. The `Local`s that have their types replaced are: - The `resume` argument itself. - The argument to `get_context`. - The yielded value of a `yield`. The `ResumeTy` hides a `&mut Context<'_>` behind an unsafe raw pointer, and the `get_context` function is being used to convert that back to a `&mut Context<'_>`. Ideally the async lowering would not use the `ResumeTy`/`get_context` indirection, but rather directly use `&mut Context<'_>`, however that would currently lead to higher-kinded lifetime errors. See <https://github.com/rust-lang/rust/issues/105501>. The async lowering step and the type / lifetime inference / checking are still using the `ResumeTy` indirection for the time being, and that indirection is removed here. After this transform, the generator body only knows about `&mut Context<'_>`.
2023-01-18Implement `SpecOptionPartialEq` for `cmp::Ordering`Scott McMurray-1/+9
2023-01-18Rollup merge of #103702 - ↵Dylan DPC-48/+15
WaffleLapkin:lift-sized-bounds-from-pointer-methods-where-applicable, r=m-ou-se Lift `T: Sized` bounds from some `strict_provenance` pointer methods This PR removes requirement for `T` (pointee type) to be `Sized` to call `pointer::{addr, expose_addr, with_addr, map_addr}`. These functions don't use `T`'s size, so there is no reason for them to require this. Updated public API: cc ``@Gankra,`` #95228 r? libs-api
2023-01-18Rollup merge of #106997 - Sp00ph:introselect, r=scottmcmMatthias Krüger-0/+22
Add heapsort fallback in `select_nth_unstable` Addresses #102451 and #106933. `slice::select_nth_unstable` uses a quick select implementation based on the same pattern defeating quicksort algorithm that `slice::sort_unstable` uses. `slice::sort_unstable` uses a recursion limit and falls back to heapsort if there were too many bad pivot choices, to ensure O(n log n) worst case running time (known as introsort). However, `slice::select_nth_unstable` does not have such a fallback strategy, which leads to it having a worst case running time of O(n²) instead. #102451 links to a playground which generates pathological inputs that show this quadratic behavior. On my machine, a randomly generated slice of length `1 << 19` takes ~200µs to calculate its median, whereas a pathological input of the same length takes over 2.5s. This PR adds an iteration limit to `select_nth_unstable`, falling back to heapsort, which ensures an O(n log n) worst case running time (introselect). With this change, there was no noticable slowdown for the random input, but the same pathological input now takes only ~1.2ms. In the future it might be worth implementing something like Median of Medians or Fast Deterministic Selection instead, which guarantee O(n) running time for all possible inputs. I've left this as a `FIXME` for now and only implemented the heapsort fallback to minimize the needed code changes. I still think we should clarify in the `select_nth_unstable` docs that the worst case running time isn't currently O(n) (the original reason that #102451 was opened), but I think it's a lot better to be able to guarantee O(n log n) instead of O(n²) for the worst case.
2023-01-17Rollup merge of #106889 - scottmcm:windows-mut, r=cuviperMatthias Krüger-0/+16
Mention the lack of `windows_mut` in `windows` This is a common request, going back to at least 2015 (#23783), so mention in the docs that it can't be done and offer a workaround using <https://doc.rust-lang.org/std/cell/struct.Cell.html#method.as_slice_of_cells>. (See also URLO threads like <https://internals.rust-lang.org/t/a-windows-mut-method-on-slice/16941/10?u=scottmcm>.)
2023-01-17Add heapsort fallback in `select_nth_unstable`Markus Everling-0/+22
2023-01-16Constify `TypeId` ordering implsonestacked-1/+2
2023-01-16Implement DoubleEnded and ExactSize for Take<Repeat> and Take<RepeatWith>Michal Nazarewicz-0/+147
Repeat iterator always returns the same element and behaves the same way backwards and forwards. Take iterator can trivially implement backwards iteration over Repeat inner iterator by simply doing forwards iteration. DoubleEndedIterator is not currently implemented for Take<Repeat<T>> because Repeat doesn’t implement ExactSizeIterator which is a required bound on DEI implementation for Take. Similarly, since Repeat is an infinite iterator which never stops, Take can trivially know how many elements it’s going to return. This allows implementing ExactSizeIterator on Take<Repeat<T>>. While at it, observe that ExactSizeIterator can also be implemented for Take<RepeatWhile<F>> so add that implementation too. Since in contrast to Repeat, RepeatWhile doesn’t guarante to always return the same value, DoubleEndedIterator isn’t implemented. Those changes render core::iter::repeat_n somewhat redundant. Issue: https://github.com/rust-lang/rust/issues/104434 Issue: https://github.com/rust-lang/rust/issues/104729
2023-01-15replace manual ptr arithmetic with ptr_subThe 8472-23/+7
2023-01-15Rollup merge of #106880 - tspiteri:borrowing-sub-typo, r=cuviperMatthias Krüger-1/+1
doc: fix typo
2023-01-14Mention the lack of `windows_mut` in `windows`Scott McMurray-0/+16
2023-01-14doc: fix typoTrevor Spiteri-1/+1
2023-01-14Rollup merge of #106860 - anden3:doc-double-spaces, r=Dylan-DPCMatthias Krüger-20/+20
Remove various double spaces in the libraries. I was just pretty bothered by this when reading the source for a function, and was suggested to check if this happened elsewhere.
2023-01-14Rollup merge of #105526 - Xiretza:iter-from-generator-derive, r=scottmcmMatthias Krüger-4/+19
libcore: make result of iter::from_generator Clone `@rustbot` label +A-generators
2023-01-14Fix some missed double spaces.André Vennberg-4/+4
2023-01-14Remove various double spaces in source comments.André Vennberg-16/+16
2023-01-14Use associated items of `char` instead of freestanding items in `core::char`Lukas Markeffsky-32/+12
2023-01-14Rollup merge of #106762 - WaffleLapkin:atomicptr+as_mut_ptr, r=m-ou-seYuki Okushi-2/+38
Add `AtomicPtr::as_mut_ptr` See https://github.com/rust-lang/rust/issues/66893#issuecomment-720125447 r? thomcc
2023-01-14Rollup merge of #105172 - alexs-sh:issue-98861-fix-next, r=scottmcmYuki Okushi-0/+5
Added error documentation for write_fmt This continuation of work at rust-lang#98861
2023-01-14Rollup merge of #104965 - zacklukem:p-option-as_ref-docs, r=scottmcmYuki Okushi-6/+7
reword Option::as_ref and Option::map examples The description for the examples of `Option::as_ref` and `Option::map` imply that the example is only doing type conversion, when it is actually finding the length of a string. Changes the wording to imply that some operation is being run on the value contained in the `Option` closes #104476
2023-01-13Allow fmt::Arguments::as_str() to return more Some(_).Mara Bos-3/+20
2023-01-12Implement `signum` with `Ord`Scott McMurray-5/+6
2023-01-13Auto merge of #106004 - fee1-dead-contrib:const-closures, r=oli-obkbors-10/+17
Const closures cc https://github.com/rust-lang/rust/issues/106003
2023-01-13Rollup merge of #106740 - petar-dambovaliev:float-iterator-hint, r=NilstriebYuki Okushi-0/+5
Adding a hint on iterator type errors Issue reference https://github.com/rust-lang/rust/issues/106728 - [x] add a case in the attribute - [x] add a test closes #106728
2023-01-12add note for float iteratorPetar Dambovaliev-0/+5
2023-01-12Make `// SAFETY` comment part of the doctest, and not surrounding codeMaybe Waffle-1/+1
2023-01-12Remove unused `mut` from a doctestMaybe Waffle-1/+1
2023-01-12Add `AtomicPtr::as_mut_ptr`Maybe Waffle-0/+36
2023-01-11Rollup merge of #106323 - starkat99:stabilize-f16c_target_feature, ↵Michael Goulet-1/+1
r=petrochenkov Stabilize f16c_target_feature Resolves https://github.com/rust-lang/stdarch/issues/1234 Library PR for stabilizing corresponding intrinsics: https://github.com/rust-lang/stdarch/pull/1366 See also #44839 tracking issue for target_feature
2023-01-11Rollup merge of #103800 - danielhenrymantilla:stabilize-pin-macro, r=dtolnayMichael Goulet-8/+3
Stabilize `::{core,std}::pin::pin!` As discussed [over here](https://github.com/rust-lang/rust/issues/93178#issuecomment-1295843548), it looks like a decent time to stabilize the `pin!` macro. ### Public API ```rust // in module `core::pin` /// API: `fn pin<T>($value: T) -> Pin<&'local mut T>` pub macro pin($value:expr $(,)?) { … } ``` - Tracking issue: #93178 (now all this needs is an FCP by the proper team?)
2023-01-11Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-seMichael Goulet-36/+75
doc: rewrite doc for signed int::{carrying_add,borrowing_sub} Reword the documentation for bigint helper methods, signed `int::{carrying_add,borrowing_sub}` (#85532). This change is a follow-up to #101889, which was for the unsigned methods.
2023-01-12test use in libcoreDeadbeef-10/+17
2023-01-12Make core::fmt::rt::v1::Argument::new const+inline.Mara Bos-1/+2
2023-01-11Stabilize `::{core,std}::pin::pin!`Daniel Henry-Mantilla-8/+3
2023-01-11Add new fn to core::fmt::rt::v1::Argument.Mara Bos-0/+13
2023-01-11Turn format arguments types into lang items.Mara Bos-1/+7
2023-01-11Rollup merge of #106570 - Xaeroxe:div-duration-tests, r=JohnTitornils-0/+26
add tests for div_duration_* functions Per https://github.com/rust-lang/rust/issues/63139#issuecomment-817070719 this adds unit tests for the functions that will hopefully effectively demonstrate that `div_duration` is ready to be stabilized.
2023-01-10Rollup merge of #105034 - HintringerFabian:improve_iterator_flatten_doc, ↵Yuki Okushi-0/+12
r=cuviper Add example for iterator_flatten Adds an Example to iterator_flatten Fixes #82687
2023-01-09Remove unstable featureCaio-8/+0
2023-01-09Stabilize `nonzero_min_max`Caio-4/+4
2023-01-09Relocate changesFabian Hintringer-12/+12
2023-01-08Rollup merge of #104163 - H4x5:once-repeat-with-debug, r=dtolnayMichael Goulet-2/+22
Don't derive Debug for `OnceWith` & `RepeatWith` Closures don't impl Debug, so the derived impl is kinda useless. The behavior of not debug-printing closures is consistent with the rest of the iterator adapters/sources.
2023-01-08Auto merge of #104658 - thomcc:rand-update-and-usable-no_std, r=Mark-Simulacrumbors-13/+23
Update `rand` in the stdlib tests, and remove the `getrandom` feature from it. The main goal is actually removing `getrandom`, so that eventually we can allow running the stdlib test suite on tier3 targets which don't have `getrandom` support. Currently those targets can only run the subset of stdlib tests that exist in uitests, and (generally speaking), we prefer not to test libstd functionality in uitests, which came up recently in https://github.com/rust-lang/rust/pull/104095 and https://github.com/rust-lang/rust/pull/104185. Additionally, the fact that we can't update `rand`/`getrandom` means we're stuck with the old set of tier3 targets, so can't test new ones. ~~Anyway, I haven't checked that this actually does allow use on tier3 targets (I think it does not, as some work is needed in stdlib submodules) but it moves us slightly closer to this, and seems to allow at least finally updating our `rand` dep, which definitely improves the status quo.~~ Checked and works now. For the most part, our tests and benchmarks are fine using hard-coded seeds. A couple tests seem to fail with this (stuff manipulating the environment expecting no collisions, for example), or become pointless (all inputs to a function become equivalent). In these cases I've done a (gross) dance (ab)using `RandomState` and `Location::caller()` for some extra "entropy". Trying to share that code seems *way* more painful than it's worth given that the duplication is a 7-line function, even if the lines are quite gross. (Keeping in mind that sharing it would require adding `rand` as a non-dev dep to std, and exposing a type from it publicly, all of which sounds truly awful, even if done behind a perma-unstable feature). See also some previous attempts: - https://github.com/rust-lang/rust/pull/86963 (in particular https://github.com/rust-lang/rust/pull/86963#issuecomment-885438936 which explains why this is non-trivial) - https://github.com/rust-lang/rust/pull/89131 - https://github.com/rust-lang/rust/pull/96626#issuecomment-1114562857 (I tried in that PR at the same time, but settled for just removing the usage of `thread_rng()` from the benchmarks, since that was the main goal). - https://github.com/rust-lang/rust/pull/104185 - Probably more. It's very tempting of a thing to "just update". r? `@Mark-Simulacrum`
2023-01-07Improve the documentation of `black_box`Trevor Gross-0/+69
2023-01-07Rollup merge of #106564 - Folyd:feat-repeatn, r=scottmcmMatthias Krüger-1/+1
Change to immutable borrow when cloning element of RepeatN
2023-01-07Rollup merge of #104081 - joshlf:patch-6, r=dtolnayMatthias Krüger-0/+6
PhantomData layout guarantees
2023-01-07Don't derive Debug for `OnceWith` & `RepeatWith`Sky-2/+22
2023-01-07add tests for div_duration_* functionsJacob Kiesel-0/+26
2023-01-07Change to immutable borrow when cloning element of RepeatNFolyd-1/+1
2023-01-06Remove HTML tags around warningGijs Burghoorn-6/+0