summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2021-10-14Use correct edition for panic in [debug_]assert!() etc.Mara Bos-0/+1
2021-10-13revert stabilization of `core::task::ready!`Ibraheem Ahmed-2/+5
(cherry picked from commit 5f7e7d2e93afd9478856d3dc026c6923a0f21641)
2021-10-13Revert "Stabilize `Iterator::intersperse()`"Jane Lusby-12/+18
(cherry picked from commit 8965b5884af5ce22a6b4f263f19f262052d818a5)
2021-10-04Rollup merge of #89184 - joshtriplett:master, r=estebankJubilee-26/+26
Temporarily rename int_roundings functions to avoid conflicts These functions are unstable, but because they're inherent they still introduce conflicts with stable trait functions in crates. Temporarily rename them to fix these conflicts, until we can resolve those conflicts in a better way.
2021-10-04Auto merge of #89144 - sexxi-goose:insig_stdlib, r=nikomatsakisbors-0/+1
2229: Mark insignificant dtor in stdlib I looked at all public [stdlib Drop implementations](https://doc.rust-lang.org/stable/std/ops/trait.Drop.html#implementors) and categorized them into Insigificant/Maybe/Significant Drop. Reasons are noted here: https://docs.google.com/spreadsheets/d/19edb9r5lo2UqMrCOVjV0fwcSdS-R7qvKNL76q7tO8VA/edit#gid=1838773501 One thing missing from this PR is tagging HashMap as insigificant destructor as that needs some discussion. r? `@Mark-Simulacrum` cc `@nikomatsakis`
2021-09-03Rollup merge of #88610 - m-ou-se:array-into-iter-docs, r=AmanieuMara Bos-2/+7
Update outdated docs of array::IntoIter::new.
2021-09-03Rollup merge of #88579 - ast-ral:master, r=m-ou-seMara Bos-4/+0
remove redundant / misplaced sentence from docs Removes sentence that seems to have drifted down into the examples section. Luckily, someone already added an explanation of what happens with packed structs back into the initial section of the doc entry and this wayward sentence can likely just be deleted.
2021-09-03Rollup merge of #88202 - azdavis:master, r=jyn514Mara Bos-0/+12
Add an example for deriving PartialOrd on enums For some reason, I always forget which variants are smaller and which are larger when you derive PartialOrd on an enum. And the wording in the current docs is not entirely clear to me. So, I often end up making a small enum, deriving PartialOrd on it, and then writing a `#[test]` with an assert that the top one is smaller than the bottom one (or the other way around) to figure out which way the deriving goes. So then I figured, it would be great if the standard library docs just had that example, so if I keep forgetting, at least I can figure it out quickly by looking at std's docs.
2021-09-03Update outdated docs of array::IntoIter::new.Mara Bos-2/+7
2021-09-02Rollup merge of #88582 - jhpratt:int_roundings, r=joshtriplettMara Bos-0/+271
Implement #88581 See #88581 for details. This API was discussed on Zulip. `@rustbot` label: +T-libs-api +S-waiting-on-review r? `@joshtriplett`
2021-09-02Rollup merge of #88560 - klensy:formatter-pad-shrink, r=m-ou-seMara Bos-12/+17
`fmt::Formatter::pad`: don't call chars().count() more than one time First commit merges two branches of match to call chars().count() only once: that should be faster if this method hits place of 3rd (previous) branch, plus quarter shorter. Second commit fixes some clippy lints while i'm here (should it be separate PR?).
2021-09-02Rollup merge of #88505 - ibraheemdev:use-unwrap-unchecked, r=kennytmMara Bos-10/+4
Use `unwrap_unchecked` where possible
2021-09-02Implement #88581Jacob Pratt-0/+271
2021-09-01remove redundant / misplaced sentence from docsast-ral-4/+0
2021-09-02Auto merge of #83342 - Count-Count:win-console-incomplete-utf8, r=m-ou-sebors-1/+1
Allow writing of incomplete UTF-8 sequences to the Windows console via stdout/stderr # Problem Writes of just an incomplete UTF-8 byte sequence (e.g. `b"\xC3"` or `b"\xF0\x9F"`) to stdout/stderr with a Windows console attached error with `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` even though further writes could complete the codepoint. This is currently a rare occurence since the [linewritershim](https://github.com/rust-lang/rust/blob/2c56ea38b045624dc8b42ec948fc169eaff1206a/library/std/src/io/buffered/linewritershim.rs) implementation flushes complete lines immediately and buffers up to 1024 bytes for incomplete lines. It can still happen as described in #83258. The problem will become more pronounced once the developer can switch stdout/stderr from line-buffered to block-buffered or immediate when the changes in the "Switchable buffering for Stdout" pull request (#78515) get merged. # Patch description If there is at least one valid UTF-8 codepoint all valid UTF-8 is passed through to the extracted `write_valid_utf8_to_console()` fn. The new code only comes into play if `write()` is being passed a short byte slice comprising an incomplete UTF-8 codepoint. In this case up to three bytes are buffered in the `IncompleteUtf8` struct associated with `Stdout` / `Stderr`. The bytes are accepted one at a time. As soon as an error can be detected `io::ErrorKind::InvalidData, "Windows stdio in console mode does not support writing non-UTF-8 byte sequences"` is returned. Once a complete UTF-8 codepoint is received it is passed to the `write_valid_utf8_to_console()` and the buffer length is set to zero. Calling `flush()` will neither error nor write anything if an incomplete codepoint is present in the buffer. # Tests Currently there are no Windows-specific tests for console writing code at all. Writing (regression) tests for this problem is a bit challenging since unit tests and UI tests don't run in a console and suddenly popping up another console window might be surprising to developers running the testsuite and it might not work at all in CI builds. To just test the new functionality in unit tests the code would need to be refactored. Some guidance on how to proceed would be appreciated. # Public API changes * `std::str::verifications::utf8_char_width()` would be exposed as `std::str::utf8_char_width()` behind the "str_internals" feature gate. # Related issues * Fixes #83258. * PR #78515 will exacerbate the problem. # Open questions * Add tests? * Squash into one commit with better commit message?
2021-09-01fix clippy lintsklensy-3/+3
2021-09-01`fmt::Formatter::pad`: don't call chars().count() more than one timeklensy-9/+14
2021-09-01Rollup merge of #88551 - inquisitivecrystal:unsafe_cell_raw_get, r=m-ou-seMara Bos-3/+2
Stabilize `UnsafeCell::raw_get()` This PR stabilizes the associated function `UnsafeCell::raw_get()`. The FCP has [already completed](https://github.com/rust-lang/rust/issues/66358#issuecomment-899095068). While there was some discussion about the naming after the close of the FCP, it looks like people have agreed on this name. Still, it would probably be best if a `libs-api` member had a look at this and stated whether more discussion is needed. While I was at it, I added some tests for `UnsafeCell`, because there were barely any. Closes #66358.
2021-08-31Stabilize `Iterator::intersperse()`inquisitivecrystal-18/+12
2021-08-31Stabilize `UnsafeCell::raw_get()`inquisitivecrystal-3/+2
2021-08-31Rollup merge of #85017 - clarfonthey:carrying_widening, r=m-ou-seMara Bos-0/+202
Add carrying_add, borrowing_sub, widening_mul, carrying_mul methods to integers This comes in part from my own attempts to make (crude) big integer implementations, and also due to the stalled discussion in [RFC 2417](https://github.com/rust-lang/rfcs/pull/2417). My understanding is that changes like these are best offered directly as code and then an RFC can be opened if there needs to be more discussion before stabilisation. Since all of these methods are unstable from the start, I figured I might as well offer them now. I tried looking into intrinsics, messed around with a few different implementations, and ultimately concluded that these are "good enough" implementations for now to at least put up some code and maybe start bikeshedding on a proper API for these. For the `carrying_add` and `borrowing_sub`, I tried looking into potential architecture-specific code and realised that even using the LLVM intrinsics for `addcarry` and `subborrow` on x86 specifically, I was getting exactly the same assembly as the naive implementation using `overflowing_add` and `overflowing_sub`, although the LLVM IR did differ because of the architecture-specific code. Longer-term I think that they would be best suited to specific intrinsics as that would make optimisations easier (instructions like add-carry tend to use implicit flags, and thus can only be optimised if they're done one-after-another, and thus it would make the most sense to have compact intrinsics that can be merged together easily). For `widening_mul` and `carrying_mul`, for now at least, I simply cast to the larger type and perform arithmetic that way, since we currently have no intrinsic that would work better for 128-bit integers. In the future, I also think that some form of intrinsic would work best to cover that case, but for now at least, I think that they're "good enough" for now. The main reasoning for offering these directly to the standard library even though they're relatively niche optimisations is to help ensure that the code generated for them is optimal. Plus, these operations alone aren't enough to create big integer implementations, although they could help simplify the code required to do so and make it a bit more accessible for the average implementor. That said, I 100% understand if any or all of these methods are not desired simply because of how niche they are. Up to you. 🤷🏻
2021-08-30use `unwrap_unchecked` where possibleibraheemdev-10/+4
2021-08-29Adding examples to docs of std::time moduleJoão M. Bezerra-5/+12
And adding missing link to Duration from Instant
2021-08-28Auto merge of #87921 - kellerkindt:master, r=kennytmbors-0/+1044
Add Saturating type (based on Wrapping type) Tracking #87920 ### Unresolved Questions <!-- Include any open questions that need to be answered before the feature can be stabilised. --> - [x] ~`impl Div for Saturating<T>` falls back on inner integer division - which seems alright?~ - [x] add `saturating_div`? (to respect division by `-1`) - [x] There is no `::saturating_shl` and `::saturating_shr`. (How to) implement `Shl`, `ShlAssign`, `Shr` and `ShrAssign`? - [naively](3f7d2ce28f8cf4dec56bf65fa2e6da0cf329ec55) - [x] ~`saturating_neg` is only implemented on [signed integer types](https://doc.rust-lang.org/std/?search=saturating_n)~ - [x] Is the implementation copied over from the `Wrapping`-type correct for `Saturating`? - [x] `Saturating::rotate_left` - [x] `Saturating::rotate_right` - [x] `Not` - [x] `BitXorOr` and `BitXorOrAssign` - [x] `BitOr` and `BitOrAssign` - [x] `BitAnd` and `BitAndAssign` - [x] `Saturating::swap_bytes` - [x] `Saturating::reverse_bits`
2021-08-28Unimpl Shl{Assign} for signed Saturating types until the correct impl is clearMichael Watzko-59/+63
2021-08-28Fix mentions of wrapping operationsMichael Watzko-2/+2
2021-08-28Use wrapping shift for unsigned typesMichael Watzko-2/+2
2021-08-26Add carrying_add, borrowing_sub, widening_mul, carrying_mul methods to integersltdk-0/+202
2021-08-26Auto merge of #88066 - LeSeulArtichaut:patterns-cleanups, r=nagisabors-7/+4
Use if-let guards in the codebase and various other pattern cleanups Dogfooding if-let guards as experimentation for the feature. Tracking issue #51114. Conflicts with #87937.
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-7/+4
2021-08-25Rollup merge of #88291 - mdsn:partition-in-blocks-safety, r=Mark-SimulacrumLéo Lanteri Thauvin-0/+26
Add SAFETY comments to core::slice::sort::partition_in_blocks A few more SAFETY comments for #66219. There are still a few more in this module. `@rustbot` label T-libs T-compiler C-cleanup
2021-08-25Rollup merge of #88273 - jhpratt:update-iterator-docs, r=jyn514Léo Lanteri Thauvin-4/+4
Fix references to `ControlFlow` in docs The `Iterator::for_each` method previously stated that it was not possible to use `break` and `continue` in it — this has been updated to acknowledge the stabilization of `ControlFlow`. Additionally, `ControlFlow` was referred to as `crate::ops::ControlFlow` which is not the correct path for an end user. r? `@jyn514`
2021-08-25Rollup merge of #88223 - scottmcm:fix-alias, r=yaahcLéo Lanteri Thauvin-15/+9
Remove the `TryV2` alias Post-bootstrap-update cleanup. (No more `try_trait_transition` feature.)
2021-08-25Rollup merge of #87944 - oconnor663:as_array_of_cells, r=scottmcmLéo Lanteri Thauvin-0/+20
add Cell::as_array_of_cells, similar to Cell::as_slice_of_cells I'd like to propose adding `Cell::as_array_of_cells`, as a natural analog to `Cell::as_slice_of_cells`. I don't have a specific use case in mind, other than that supporting slices but not arrays feels like a gap. Do other folks agree with that intuition? Would this addition be substantial enough to need an RFC? --- Previously, converting `&mut [T; N]` to `&[Cell<T>; N]` looks like this: ```rust let array = &mut [1, 2, 3]; let cells: &[Cell<i32>; 3] = Cell::from_mut(&mut array[..]) .as_slice_of_cells() .try_into() .unwrap(); ``` With this new helper method, it looks like this: ```rust let array = &mut [1, 2, 3]; let cells = Cell::from_mut(array).as_array_of_cells(); ```
2021-08-24Add SAFETY comments to core::slice::sort::partition_in_blocksMariano Casco-0/+26
2021-08-23Fix references to `ControlFlow` in docsJacob Pratt-4/+4
2021-08-23Auto merge of #83302 - camsteffen:write-piece-unchecked, r=dtolnaybors-4/+50
Get piece unchecked in `write` We already use specialized `zip`, but it seems like we can do a little better by not checking `pieces` length at all. `Arguments` constructors are now unsafe. So the `format_args!` expansion now includes an `unsafe` block. <details> <summary>Local Bench Diff</summary> ```text name before ns/iter after ns/iter diff ns/iter diff % speedup fmt::write_str_macro1 22,967 19,718 -3,249 -14.15% x 1.16 fmt::write_str_macro2 35,527 32,654 -2,873 -8.09% x 1.09 fmt::write_str_macro_debug 571,953 575,973 4,020 0.70% x 0.99 fmt::write_str_ref 9,579 9,459 -120 -1.25% x 1.01 fmt::write_str_value 9,573 9,572 -1 -0.01% x 1.00 fmt::write_u128_max 176 173 -3 -1.70% x 1.02 fmt::write_u128_min 138 134 -4 -2.90% x 1.03 fmt::write_u64_max 139 136 -3 -2.16% x 1.02 fmt::write_u64_min 129 135 6 4.65% x 0.96 fmt::write_vec_macro1 24,401 22,273 -2,128 -8.72% x 1.10 fmt::write_vec_macro2 37,096 35,602 -1,494 -4.03% x 1.04 fmt::write_vec_macro_debug 588,291 589,575 1,284 0.22% x 1.00 fmt::write_vec_ref 9,568 9,732 164 1.71% x 0.98 fmt::write_vec_value 9,516 9,625 109 1.15% x 0.99 ``` </details>
2021-08-23Rollup merge of #88230 - steffahn:a_an, r=oli-obkMara Bos-10/+10
Fix typos “a”→“an” Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an. While automation was used to find these, every change was checked manually. Changes in submodules get separate PRs: * https://github.com/rust-lang/stdarch/pull/1201 * https://github.com/rust-lang/cargo/pull/9821 * https://github.com/rust-lang/miri/pull/1874 * https://github.com/rust-lang/rls/pull/1746 * https://github.com/rust-analyzer/rust-analyzer/pull/9984 _folks @ rust-analyzer are fast at merging…_ * https://github.com/rust-analyzer/rust-analyzer/pull/9985 * https://github.com/rust-analyzer/rust-analyzer/pull/9987 * https://github.com/rust-analyzer/rust-analyzer/pull/9989 _For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._ <hr> This has some overlap with #88226, but neither is a strict superset of the other. If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23add Cell::as_array_of_cells, similar to Cell::as_slice_of_cellsJack O'Connor-0/+20
Previously, converting `&mut [T; N]` to `&[Cell<T>; N]` looks like this: let array = &mut [1, 2, 3]; let cells: &[Cell<i32>; 3] = Cell::from_mut(&mut array[..]) .as_slice_of_cells() .try_into() .unwrap(); With this new helper method, it looks like this: let array = &mut [1, 2, 3]; let cells: &[Cell<i32>; 3] = Cell::from_mut(array).as_array_of_cells();
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-5/+5
same search
2021-08-22Fix more “a”/“an” typosFrank Steffahn-1/+1
2021-08-22Fix more “a”/“an” typosFrank Steffahn-1/+1
2021-08-22Fix typos “a”→“an”Frank Steffahn-3/+3
2021-08-22Auto merge of #88122 - Seppel3210:master, r=dtolnaybors-8/+10
Fix example in `Extend<(A, B)>` impl After looking over the examples in my last PR (#85835) on doc.rust-lang.org/nightly I realized that the example didn't actually show what I wanted it to show 😅 So here's the better example
2021-08-21Remove the `TryV2` aliasScott McMurray-15/+9
Post-bootstrap-update cleanup.
2021-08-20Add an example for deriving PartialOrd on enumsAriel Davis-0/+12
For some reason, I always forget which variants are smaller and which are larger when you derive PartialOrd on an enum. And the wording in the current docs is not entirely clear to me. So, I often end up making a small enum, deriving PartialOrd on it, and then writing a `#[test]` with an assert that the top one is smaller than the bottom one (or the other way around) to figure out which way the deriving goes. So then I figured, it would be great if the standard library docs just had that example, so if I keep forgetting, at least I can figure it out quickly by looking at std's docs.
2021-08-19Simplify saturating_divMichael Watzko-8/+3
2021-08-19Simplify Div impl for Saturating by using saturating_divMichael Watzko-37/+31
2021-08-19Add saturating_div to unsigned integer typesMichael Watzko-0/+30
2021-08-19Add doctests to and fix saturating_div for signed integer typesMichael Watzko-9/+22