about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2021-10-11Rollup merge of #89651 - ibraheemdev:poll-ready, r=dtolnayMatthias Krüger-2/+97
Add `Poll::ready` and revert stabilization of `task::ready!` This PR adds an inherent `ready` method to `Poll` that can be used with the `?` operator as an alternative to the `task::ready!` macro: ```rust let val = ready!(fut.poll(cx)); let val = fut.poll(cx).ready()?; ``` I think this form is a nice, non-breaking middle ground between changing the `impl Try for Poll`, and adding a separate macro. It looks better than `ready!` in my opinion, and it composes well: ```rust let elem = ready!(fut.poll(cx)).pop().unwrap(); let elem = fut.poll(cx).ready()?.pop().unwrap(); ``` The planned stabilization of `ready!` in 1.56 has been reverted because I think this alternate approach is worth considering. r? rust-lang/libs
2021-10-11Add library tracking issue for poll_ready featureDavid Tolnay-7/+7
2021-10-11Auto merge of #83908 - Flying-Toast:master, r=davidtwcobors-0/+1
Add enum_intrinsics_non_enums lint There is a clippy lint to prevent calling [`mem::discriminant`](https://doc.rust-lang.org/std/mem/fn.discriminant.html) with a non-enum type. I think the lint is worthy of being included in rustc, given that `discriminant::<T>()` where `T` is a non-enum has an unspecified return value, and there are no valid use cases where you'd actually want this. I've also made the lint check [variant_count](https://doc.rust-lang.org/core/mem/fn.variant_count.html) (#73662). closes #83899
2021-10-11Auto merge of #89767 - GuillaumeGomez:rollup-sczixhk, r=GuillaumeGomezbors-1/+55
Rollup of 7 pull requests Successful merges: - #89655 (bootstrap: don't use `--merges` to look for commit hashes for downloading artifacts) - #89726 (Add #[must_use] to alloc constructors) - #89729 (Add #[must_use] to core and std constructors) - #89743 (Fix RUSTC_LOG handling) - #89753 (Add #[must_use] to from_value conversions) - #89754 (Cleanup .item-table CSS) - #89761 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-10-11Rollup merge of #89753 - jkugelman:must-use-from_value-conversions, ↵Guillaume Gomez-1/+42
r=joshtriplett Add #[must_use] to from_value conversions I added two methods to the list myself. Clippy did not flag them because they take `mut` args, but neither modifies their argument. ```rust core::str const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str; std::ffi::CString unsafe fn from_raw(ptr: *mut c_char) -> CString; ``` I put a custom note on `from_raw`: ```rust #[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"] pub unsafe fn from_raw(ptr: *mut c_char) -> CString { ``` Parent issue: #89692 r? ``@joshtriplett``
2021-10-11Rollup merge of #89729 - jkugelman:must-use-core-std-constructors, ↵Guillaume Gomez-0/+13
r=joshtriplett Add #[must_use] to core and std constructors Parent issue: #89692 r? ``@joshtriplett``
2021-10-11Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkovbors-1/+3
Apply clippy suggestions for rustc and core
2021-10-11Add enum_intrinsics_non_enums lintFlying-Toast-0/+1
2021-10-11Auto merge of #89755 - jkugelman:must-use-conversions-that-move-self, ↵bors-0/+13
r=joshtriplett Add #[must_use] to conversions that move self Everything here got the same message. Is the wording okay? ```rust #[must_use = "`self` will be dropped if the result is not used"] ``` I want to draw attention to these methods in particular: ```rust alloc::sync::Arc<MaybeUninit<T>> unsafe fn assume_init(self) -> Arc<T>; alloc::sync::Arc<[MaybeUninit<T>]> unsafe fn assume_init(self) -> Arc<[T]>; core::pin::Pin<&'a mut T> const fn into_ref(self) -> Pin<&'a T>; core::pin::Pin<&'a mut T> const fn get_mut(self) -> &'a mut T; core::pin::Pin<&'a mut T> const unsafe fn get_unchecked_mut(self) -> &'a mut T; core::pin::Pin<&'a mut T> unsafe fn map_unchecked_mut(self, func: F) -> Pin<&'a mut U>; core::pin::Pin<&'a mut Pin<P>> fn as_deref_mut(self) -> Pin<&'a mut P::Target>; ``` Parent issue: #89692 r? `@joshtriplett`
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+13
2021-10-10Add #[must_use] to from_value conversionsJohn Kugelman-1/+42
2021-10-10Rollup merge of #89720 - jkugelman:must-use-math-operations, r=joshtriplettMatthias Krüger-19/+255
Add #[must_use] to math and bit manipulation methods Also tidied up a few other nearby `#[must_use]`s. Parent issue: #89692
2021-10-10Rollup merge of #89719 - jkugelman:must-use-char-escape-methods, r=joshtriplettMatthias Krüger-0/+6
Add #[must_use] to char escape methods Parent issue: #89692
2021-10-10Rollup merge of #89718 - jkugelman:must-use-is_condition-tests, r=joshtriplettMatthias Krüger-0/+58
Add #[must_use] to is_condition tests There's nothing insightful to say about these so I didn't write any extra explanations. Parent issue: #89692
2021-10-10Rollup merge of #89705 - nbdd0121:doc, r=GuillaumeGomezMatthias Krüger-0/+1
Cfg hide no_global_oom_handling and no_fp_fmt_parse These are unstable sysroot customisation cfg options that only projects building their own sysroot will use (e.g. Rust-for-linux). Most users shouldn't care. `no_global_oom_handling` can be especially annoying since it's applied on many commonly used alloc crate methods (e.g. `Box::new`, `Vec::push`). r? ```@GuillaumeGomez```
2021-10-10Rollup merge of #89438 - pierwill:prefix-free-hash, r=AmanieuMatthias Krüger-0/+12
docs: `std::hash::Hash` should ensure prefix-free data Attempt to synthesize the discussion in #89429 into a suggestion regarding `Hash` implementations (not a hard requirement). Closes #89429.
2021-10-10Rollup merge of #88713 - falk-hueffner:int-log10-documentation-fixes, r=scottmcmMatthias Krüger-25/+24
Improve docs for int_log * Clarify rounding. * Avoid "wrapping" wording. * Omit wrong claim on 0 only being returned in error cases. * Typo fix for one_less_than_next_power_of_two.
2021-10-10Rollup merge of #88374 - joshlf:patch-2, r=JohnTitorMatthias Krüger-1/+1
Fix documentation in Cell
2021-10-10Apply clippy suggestionsClemens Wasser-1/+3
2021-10-10Auto merge of #89219 - nickkuk:str_split_once_get_unchecked, r=Mark-Simulacrumbors-2/+4
Use get_unchecked in str::[r]split_once This PR removes indices checking in `str::split_once` and `str::rsplit_once` methods.
2021-10-10Add #[must_use] to core and std constructorsJohn Kugelman-0/+13
2021-10-09Add #[must_use] to math and bit manipulation methodsJohn Kugelman-19/+255
Also tidied up a few other nearby `#[must_use]`s.
2021-10-09Add #[must_use] to char escape methodsJohn Kugelman-0/+6
2021-10-09Add #[must_use] to is_condition testsJohn Kugelman-0/+58
There's nothing insightful to say about these so I didn't write any extra explanations.
2021-10-09Update library/core/src/hash/mod.rspierwill-1/+1
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2021-10-09Cfg hide no_global_oom_handling and no_fp_fmt_parseGary Guo-0/+1
2021-10-09Rollup merge of #89614 - cuviper:unicode-14, r=joshtriplettGuillaume Gomez-553/+653
Update to Unicode 14.0 The Unicode Standard [announced Version 14.0](https://home.unicode.org/announcing-the-unicode-standard-version-14-0/) on September 14, 2021, and this pull request updates the generated tables in `core` accordingly. This did require a little prep-work in `unicode-table-generator`. First, #81358 had modified the generated file instead of the tool, so that change is now reflected in the tool as well. Next, I found that the "Alphabetic" property in version 14 was panicking when generating a bitset, "cannot pack 264 into 8 bits". We've been using the skiplist for that anyway, so I changed this to fail gracefully. Finally, I confirmed that the tool still created the exact same tables for 13 before moving to 14.
2021-10-09Rollup merge of #75644 - c410-f3r:array, r=yaahcGuillaume Gomez-17/+103
Add 'core::array::from_fn' and 'core::array::try_from_fn' These auxiliary methods fill uninitialized arrays in a safe way and are particularly useful for elements that don't implement `Default`. ```rust // Foo doesn't implement Default struct Foo(usize); let _array = core::array::from_fn::<_, _, 2>(|idx| Foo(idx)); ``` Different from `FromIterator`, it is guaranteed that the array will be fully filled and no error regarding uninitialized state will be throw. In certain scenarios, however, the creation of an **element** can fail and that is why the `try_from_fn` function is also provided. ```rust #[derive(Debug, PartialEq)] enum SomeError { Foo, } let array = core::array::try_from_fn(|i| Ok::<_, SomeError>(i)); assert_eq!(array, Ok([0, 1, 2, 3, 4])); let another_array = core::array::try_from_fn(|_| Err(SomeError::Foo)); assert_eq!(another_array, Err(SomeError::Foo)); ```
2021-10-09Rollup merge of #89694 - jkugelman:must-use-string-transforms, r=joshtriplettMatthias Krüger-0/+28
Add #[must_use] to string/char transformation methods These methods could be misconstrued as modifying their arguments instead of returning new values. Where possible I made the note recommend a method that does mutate in place. Parent issue: #89692
2021-10-09Rollup merge of #88707 - sylvestre:split_example, r=yaahcMatthias Krüger-0/+6
String.split_terminator: Add an example when using a slice of chars
2021-10-09Update library/core/src/num/mod.rsJohn Kugelman-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2021-10-09Add #[must_use] to string/char transformation methodsJohn Kugelman-0/+28
These methods could be misconstrued as modifying their arguments instead of returning new values. Where possible I made the note recommend a method that does mutate in place.
2021-10-08Cfg hide more conditions for coreLoïc BRANSTETT-0/+1
2021-10-07Rollup merge of #89622 - m-ou-se:debug-assert-2021, r=estebankJubilee-0/+1
Use correct edition for panic in [debug_]assert!(). See https://github.com/rust-lang/rust/issues/88638#issuecomment-915472783
2021-10-07Rollup merge of #88772 - orlp:result-map-or-else-docfix, r=yaahcJubilee-3/+2
Fixed confusing wording on Result::map_or_else. Fixes https://github.com/rust-lang/rust/issues/88195.
2021-10-07Auto merge of #89638 - rust-lang:revert-88548-intersperse, r=Mark-Simulacrumbors-12/+18
Revert "Stabilize `Iterator::intersperse()`" Reverts rust-lang/rust#88548 First step in resolving https://github.com/rust-lang/rust/issues/88967
2021-10-07revert stabilization of `core::task::ready!`Ibraheem Ahmed-2/+5
2021-10-07add `Poll::ready`Ibraheem Ahmed-0/+92
2021-10-07Revert "Stabilize `Iterator::intersperse()`"Jane Lusby-12/+18
2021-10-07Rollup merge of #89596 - GuillaumeGomez:implicit-doc-cfg, r=jyn514Guillaume Gomez-0/+25
Make cfg imply doc(cfg) This is a reopening of #79341, rebased and modified a bit (we made a lot of refactoring in rustdoc's types so they needed to be reflected in this PR as well): * `hidden_cfg` is now in the `Cache` instead of `DocContext` because `cfg` information isn't stored anymore on `clean::Attributes` type but instead computed on-demand, so we need this information in later parts of rustdoc. * I removed the `bool_to_options` feature (which makes the code a bit simpler to read for `SingleExt` trait implementation. * I updated the version for the feature. There is only one thing I couldn't figure out: [this comment](https://github.com/rust-lang/rust/pull/79341#discussion_r561855624) > I think I'll likely scrap the whole `SingleExt` extension trait as the diagnostics for 0 and >1 items should be different. How/why should they differ? EDIT: this part has been solved, the current code was fine, just needed a little simplification. cc `@Nemo157` r? `@jyn514` Original PR description: This is only active when the `doc_cfg` feature is active. The implicit cfg can be overridden via `#[doc(cfg(...))]`, so e.g. to hide a `#[cfg]` you can use something like: ```rust #[cfg(unix)] #[doc(cfg(all()))] pub struct Unix; ``` By adding `#![doc(cfg_hide(foobar))]` to the crate attributes the cfg `#[cfg(foobar)]` (and _only_ that _exact_ cfg) will not be implicitly treated as a `doc(cfg)` to render a message in the documentation.
2021-10-07Use correct edition for panic in [debug_]assert!() etc.Mara Bos-0/+1
2021-10-06Regenerate tables for Unicode 14.0.0Josh Stone-553/+653
2021-10-06Rollup merge of #88523 - kpreid:category, r=yaahcManish Goregaokar-4/+22
Expand documentation for `FpCategory`. I intend these changes to be helpful to readers who are not yet familiar with the quirks of floating-point numbers. Additionally, I felt it was misleading to describe `Nan` as being the result of division by zero, since most divisions by zero (except for 0/0) produce `Infinite` floats, so I moved that remark to the `Infinite` variant with adjustment. The first sentence of the `Nan` documentation is copied from `f32`; I followed the example of the `f64` documentation by referring to `f32` for general concepts, rather than duplicating the text. ---- I considered making similar changes to the documentation of the `is_*` methods of floats, but decided that that was a much larger and trickier problem; here, each of the variants' descriptions can be expected to be read in context of being mutually exclusive with the others.
2021-10-06Rollup merge of #87601 - a1phyr:feature_uint_add_signed, r=kennytmManish Goregaokar-9/+302
Add functions to add unsigned and signed integers This PR adds methods to unsigned integers to add signed integers with good overflow semantics under `#![feature(mixed_integer_ops)]`. The added API is: ```rust // `uX` is `u8`, `u16`, `u32`, `u64`,`u128`, `usize` impl uX { pub const fn checked_add_signed(self, iX) -> Option<Self>; pub const fn overflowing_add_signed(self, iX) -> (Self, bool); pub const fn saturating_add_signed(self, iX) -> Self; pub const fn wrapping_add_signed(self, iX) -> Self; } impl iX { pub const fn checked_add_unsigned(self, uX) -> Option<Self>; pub const fn overflowing_add_unsigned(self, uX) -> (Self, bool); pub const fn saturating_add_unsigned(self, uX) -> Self; pub const fn wrapping_add_unsigned(self, uX) -> Self; pub const fn checked_sub_unsigned(self, uX) -> Option<Self>; pub const fn overflowing_sub_unsigned(self, uX) -> (Self, bool); pub const fn saturating_sub_unsigned(self, uX) -> Self; pub const fn wrapping_sub_unsigned(self, uX) -> Self; } ``` Maybe it would be interesting to also have `add_signed` that panics in debug and wraps in release ?
2021-10-06Clean up code a bit:Guillaume Gomez-2/+3
* Remove "bool_to_options" feature * Update version for compiler feature * rustfmt
2021-10-06Rebase Result::map_or_else doc wording on top of #89400.Orson Peters-3/+2
2021-10-05Rollup merge of #89502 - FabianWolff:issue-89493, r=joshtriplettManish Goregaokar-2/+1
Fix Lower/UpperExp formatting for integers and precision zero Fixes the integer part of #89493 (I daren't touch the floating-point formatting code). The issue is that the "subtracted" precision essentially behaves like extra trailing zeros, but this is not currently reflected in the code properly.
2021-10-05Suppress some cfg from being shown in the stdlib docsWim Looman-1/+25
2021-10-05for signed overflowing remainder, delay comparing lhs with MINTrevor Spiteri-6/+4
Since the wrapped remainder is going to be 0 for all cases when the rhs is -1, there is no need to divide in this case. Comparing the lhs with MIN is only done for the overflow bool. In particular, this results in better code generation for wrapping remainder, which discards the overflow bool completely.
2021-10-05Use get_unchecked in str::[r]split_oncenickkuk-2/+4