about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2020-02-04Make overflowing arithmetic `const`Dylan MacKenzie-4/+9
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04Make checked arithmetic besides division `const`Dylan MacKenzie-13/+27
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04Make euclidean division `const`Dylan MacKenzie-16/+33
Co-Authored-By: 9999years <rbt@sent.as>
2020-02-04Auto merge of #68708 - Mark-Simulacrum:stage0-step, r=pietroalbinibors-23/+1
Step stage0 to bootstrap from 1.42 This also includes a commit which fixes the rustfmt downloading logic to redownload when the rustfmt channel changes, and bumps rustfmt to a more recent version.
2020-02-04Remove `finished` flag from `MapWhile`Waffle-47/+36
2020-02-03Remove Copy impl from OnceWithOliver Middleton-1/+1
Iterators typically don't implement `Copy` and this shouldn't be an exception.
2020-02-03Rollup merge of #68800 - JohnTitor:stabilize-once-with, r=CentrilDylan DPC-14/+8
Stabilize `core::iter::once_with()` Fixes #57581 FCP: https://github.com/rust-lang/rust/issues/57581#issuecomment-576178031 r? @SimonSapin
2020-02-04Stabilize `core::iter::once_with()`Yuki Okushi-14/+8
2020-02-03Optimize core::ptr::align_offsetAmos Onn-2/+1
- As explained in the comment inside mod_inv, it is valid to work mod `usize::max_value()` right until the end.
2020-02-03Optimize core::ptr::align_offsetAmos Onn-13/+20
- When calculating the inverse, it's enough to work `mod a/g` instead of `mod a`.
2020-02-03Optimize core::ptr::align_offsetAmos Onn-2/+2
- Stopping condition inside mod_inv can be >= instead of > - Remove intrinsics::unchecked_rem, we are working modulu powers-of-2 so we can simply mask
2020-02-02Rollup merge of #68733 - cata0309:patch-1, r=Dylan-DPCMazdak Farrokhzad-2/+2
Update option.rs I updated the example of the `expect` examples so they won't contain depressing sentences any more !
2020-02-02Add a resume type parameter to `Generator`Jonas Schievink-4/+31
2020-02-01Remove `Alloc` in favor of `AllocRef`Tim Diekmann-7/+0
`AllocRef` was reexported as `Alloc` in order to not break toolstate in the week before the next stable release.
2020-02-01Update option.rsMarincia Catalin-2/+2
I updated the example of the `expect` examples so they won't contain depressing sentences any more !
2020-02-01Remove some unsound specializationsMatthew Jasper-57/+91
2020-01-31Add methods to leak RefCell borrows to referencesAndreas Molzer-0/+63
Usually, references to the interior are only created by the `Deref` and `DerefMut` impl of the guards `Ref` and `RefMut`. Note that `RefCell` already has to cope with leaks of such guards which, when it occurs, effectively makes it impossible to ever acquire a mutable guard or any guard for `Ref` and `RefMut` respectively. It is already safe to use this to create a reference to the inner of the ref cell that lives as long as the reference to the `RefCell` itself, e.g. ```rust fn leak(r: &RefCell<usize>) -> Option<&usize> { let guard = r.try_borrow().ok()?; let leaked = Box::leak(Box::new(guard)); Some(&*leaked) } ``` The newly added methods allow the same reference conversion without an indirection over a leaked allocation and composing with both borrow and try_borrow without additional method combinations.
2020-01-31Drop cfg(bootstrap) codeMark Rousskov-23/+1
2020-01-31Rollup merge of #68638 - GuillaumeGomez:links-cmp-traits, r=Dylan-DPCDylan DPC-20/+31
Add missing links for cmp traits r? @Dylan-DPC
2020-01-30Auto merge of #66577 - WaffleLapkin:iter_take_while_map, r=mark-simulcrumbors-1/+195
Add `Iterator::map_while` In `Iterator` trait there is `*_map` version of [`filter`] — [`filter_map`], however, there is no `*_map` version of [`take_while`], that can also be useful. ### Use cases In my code, I've found that I need to iterate through iterator of `Option`s, stopping on the first `None`. So I've written code like this: ```rust let arr = [Some(4), Some(10), None, Some(3)]; let mut iter = arr.iter() .take_while(|x| x.is_some()) .map(|x| x.unwrap()); assert_eq!(iter.next(), Some(4)); assert_eq!(iter.next(), Some(10)); assert_eq!(iter.next(), None); assert_eq!(iter.next(), None); ``` Thit code 1) isn't clean 2) In theory, can generate bad bytecode (I'm actually **not** sure, but I think that `unwrap` would generate additional branches with `panic!`) The same code, but with `map_while` (in the original PR message it was named "take_while_map"): ```rust let arr = [Some(4), Some(10), None, Some(3)]; let mut iter = arr.iter().map_while(std::convert::identity); ``` Also, `map_while` can be useful when converting something (as in [examples]). [`filter`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.filter [`filter_map`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.filter_map [`take_while`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.take_while [examples]: https://github.com/rust-lang/rust/compare/master...WaffleLapkin:iter_take_while_map?expand=1#diff-7e57917f962fe6ffdfba51e4955ad6acR1042
2020-01-30Add missing links for cmp traitsGuillaume Gomez-20/+31
2020-01-30Auto merge of #68325 - faern:move-numeric-consts-to-associated-consts-step1, ↵bors-56/+192
r=LukasKalbertodt Move numeric consts to associated consts step1 A subset of #67913. Implements the first step of RFC https://github.com/rust-lang/rfcs/pull/2700 This PR adds the new constants as unstable constants and defines the old ones in terms of the new ones. Then fix a tiny bit of code that started having naming collisions because of the new assoc consts. Removed a test that did not seem relevant any longer. Since doing just `u8::MIN` should now indeed be valid.
2020-01-29Document `From` implementation for NonZero numsLeSeulArtichaut-2/+6
2020-01-28Minor: note why we can rely on Any trait for safetyPeter Todd-2/+6
2020-01-28Fill tracking issue for `iter_map_while` featureWaffle-5/+5
2020-01-28Add `Iterator::map_while` method and corresponding `MapWhile` adapterWaffle-1/+195
2020-01-28Simplify `Skip::nth` and `Skip::last` implementationsOliver Middleton-13/+7
The main improvement is to make `last` no longer recursive.
2020-01-28Auto merge of #68529 - TimDiekmann:rename-alloc, r=Amanieubors-11/+26
Rename `Alloc` to `AllocRef` The allocator-wg has decided to merge this change upstream in https://github.com/rust-lang/wg-allocators/issues/8#issuecomment-577122958. This renames `Alloc` to `AllocRef` because types that implement `Alloc` are a reference, smart pointer, or ZSTs. It is not possible to have an allocator like `MyAlloc([u8; N])`, that owns the memory and also implements `Alloc`, since that would mean, that moving a `Vec<T, MyAlloc>` would need to correct the internal pointer, which is not possible as we don't have move constructors. For further explanation please see https://github.com/rust-lang/wg-allocators/issues/8#issuecomment-489464843 and the comments after that one. Additionally it clarifies the semantics of `Clone` on an allocator. In the case of `AllocRef`, it is clear that the cloned handle still points to the same allocator instance, and that you can free data allocated from one handle with another handle. The initial proposal was to rename `Alloc` to `AllocHandle`, but `Ref` expresses the semantics better than `Handle`. Also, the only appearance of `Handle` in `std` are for windows specific resources, which might be confusing. Blocked on https://github.com/rust-lang/miri/pull/1160
2020-01-28Auto merge of #68234 - CAD97:slice-from-raw-parts, r=KodrAusbors-7/+5
Stabilize ptr::slice_from_raw_parts[_mut] Closes #36925, the tracking issue. Initial impl: #60667 r? @rust-lang/libs In addition to stabilizing, I've adjusted the example of `ptr::slice_from_raw_parts` to use `slice_from_raw_parts` instead of `slice_from_raw_parts_mut`, which was unnecessary for the example as written.
2020-01-28stabilize the debug_map_key_value featureAshley Mannix-5/+2
2020-01-27Rename `Alloc` to `AllocRef`Tim Diekmann-11/+26
2020-01-27Auto merge of #68165 - thomcc:lt_ones, r=sfacklerbors-0/+138
Add leading_ones and trailing_ones methods to the primitive integer types I was surprised these were missing (given that `leading_zeros` and `trailing_zeros` exist), and they seem trivial and hopefully not controversial. Note that there's some precedent in that `count_ones` and `count_zeros` are both supported even though only one of these has an intrinsic. I'm not sure if these need a `rustc_const_unstable` flag (the tests don't seem to mind that it's missing). I just made them const, since there's not really any reason for these to be non-const when the `_zeros` variants are const. Note: My understanding is trivial stuff like (hopefully) this can land without an RFC, but I'm not fully sure about the process though. Questions like "when does the tracking issue get filed?", are a total mystery to me. So, any guidance is appreciated, and sorry in advance if I should have gone through some more involved process for this.
2020-01-24Use Self instead of self return typeLzu Tao-10/+10
2020-01-24Rollup merge of #68469 - ollie27:skip_count, r=sfacklerTyler Mandry-2/+8
Avoid overflow in `std::iter::Skip::count` The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items. Fixes #68139
2020-01-24Rollup merge of #68424 - estebank:suggest-borrow-for-non-copy-vec, r=davidtwcoTyler Mandry-0/+2
Suggest borrowing `Vec<NonCopy>` in for loop Partially address #64167.
2020-01-23Updating str.chars docs to mention crates.io.Steven Degutis-1/+2
This might spare someone else a little time searching the stdlib for unicode/grapheme support.
2020-01-23Unlock assoc_int_consts in documentation examples using itLinus Färnstrand-0/+4
2020-01-23Unlock assoc_int_consts in core+stdLinus Färnstrand-0/+1
2020-01-23Fix some float operations to work together with the assoc constsLinus Färnstrand-5/+5
2020-01-23Add relevant associated constants to the float typesLinus Färnstrand-28/+135
2020-01-23Add MIN/MAX associated constants to the integer typesLinus Färnstrand-23/+47
2020-01-23use `diagnostic_item` and modify wordingEsteban Küber-0/+2
2020-01-22Avoid overflow in `std::iter::Skip::count`Oliver Middleton-2/+8
The call to `count` on the inner iterator can overflow even if `Skip` itself would return less that `usize::max_value()` items.
2020-01-20Auto merge of #68405 - JohnTitor:rollup-kj0x4za, r=JohnTitorbors-44/+40
Rollup of 8 pull requests Successful merges: - #67734 (Remove appendix from Apache license) - #67795 (Cleanup formatting code) - #68290 (Fix some tests failing in `--pass check` mode) - #68297 ( Filter and test predicates using `normalize_and_test_predicates` for const-prop) - #68302 (Fix #[track_caller] and function pointers) - #68339 (Add `riscv64gc-unknown-linux-gnu` into target list in build-manifest) - #68381 (Added minor clarification to specification of GlobalAlloc::realloc.) - #68397 (rustdoc: Correct order of `async` and `unsafe` in `async unsafe fn`s) Failed merges: r? @ghost
2020-01-21Rollup merge of #68381 - mjp41:master, r=Dylan-DPCYuki Okushi-1/+2
Added minor clarification to specification of GlobalAlloc::realloc. The specification of `realloc` is slightly unclear: ``` /// * `layout` must be the same layout that was used /// to allocate that block of memory, ``` https://github.com/rust-lang/rust/blob/master/src/libcore/alloc.rs#L541-L542 In the case of an `alloc` or `alloc_zeroed` this is fairly evidently the `layout` parameter passed into the original call. In the case of a `realloc`, this I assume is `layout` modified to contain `new_size`. However, I could not find this case specified in the documentation. Thus technically in a sequence of calls to `realloc`, it would be valid to provide the second call to `realloc` the same `layout` as the first call to `realloc`, which is almost certainly not going to be handled correctly. This PR attempts to clarify the specification.
2020-01-20Auto merge of #68066 - CAD97:stabilize-manuallydrop-take, ↵bors-7/+8
r=Amanieu,Mark-Simulacrum Stabilize ManuallyDrop::take Tracking issue: closes #55422 FCP merge: https://github.com/rust-lang/rust/issues/55422#issuecomment-572653619 Reclaims the doc improvements from closed #62198. ----- Stable version is a simple change if necessary. Proposal: [relnotes] (this changes how to best take advantage of `ManuallyDrop`, esp. wrt. `Drop::drop` and finalize-by-value members)
2020-01-20Drop args from FormatterMark Rousskov-13/+6
These are no longer used by Formatter methods.
2020-01-20Move run/getcount to functionsMark Rousskov-38/+35
These are only called from one place and don't generally support being called from other places; furthermore, they're the only formatter functions that look at the `args` field (which a future commit will remove).
2020-01-20Delete unused "next" variants from formatting infrastructureMark Rousskov-10/+15
The formatting infrastructure stopped emitting these a while back, and in removing them we can simplify related code.
2020-01-20Added minor clarification to specification of realloc.Matthew Parkinson-1/+2
The `layout` for the returned allocation of a `realloc` is only implicitly specified. This change makes it explicit.