about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2022-10-11add panic_fmt_nounwind for panicing without unwinding, and use it for ↵Ralf Jung-3/+19
panic_no_unwind
2022-10-11Rollup merge of #102445 - jmillikin:cstr-is-empty, r=Mark-SimulacrumMatthias Krüger-0/+28
Add `is_empty()` method to `core::ffi::CStr`. ACP: https://github.com/rust-lang/libs-team/issues/106 Tracking issue: https://github.com/rust-lang/rust/issues/102444
2022-10-11Rollup merge of #101774 - Riolku:atomic-update-aba, r=m-ou-seMatthias Krüger-0/+26
Warn about safety of `fetch_update` Specifically as it relates to the ABA problem. `fetch_update` is a useful function, and one that isn't provided by, say, C++. However, this does not mean the function is magic. It is implemented in terms of `compare_exchange_weak`, and in particular, suffers from the ABA problem. See the following code, which is a naive implementation of `pop` in a lock-free queue: ```rust fn pop(&self) -> Option<i32> { self.front.fetch_update(Ordering::Relaxed, Ordering::Acquire, |front| { if front == ptr::null_mut() { None } else { Some(unsafe { (*front).next }) } }.ok() } ``` This code is unsound if called from multiple threads because of the ABA problem. Specifically, suppose nodes are allocated with `Box`. Suppose the following sequence happens: ``` Initial: Queue is X -> Y. Thread A: Starts popping, is pre-empted. Thread B: Pops successfully, twice, leaving the queue empty. Thread C: Pushes, and `Box` returns X (very common for allocators) Thread A: Wakes up, sees the head is still X, and stores Y as the new head. ``` But `Y` is deallocated. This is undefined behaviour. Adding a note about this problem to `fetch_update` should hopefully prevent users from being misled, and also, a link to this common problem is, in my opinion, an improvement to our docs on atomics.
2022-10-11Rollup merge of #102258 - cjgillot:core-kappa, r=m-ou-seYuki Okushi-4/+0
Remove unused variable in float formatting.
2022-10-11Change tracking issue from #76156 to #102911woppopo-3/+3
2022-10-10Auto merge of #96711 - emilio:inline-slice-clone, r=nikicbors-0/+5
slice: #[inline] a couple iterator methods. The one I care about and actually saw in the wild not getting inlined is clone(). We ended up doing a whole function call for something that just copies two pointers. I ended up marking as_slice / as_ref as well because make_slice is inline(always) itself, and is also the kind of think that can kill performance in hot loops if you expect it to get inlined. But happy to undo those.
2022-10-09From<Alignment> for usize & NonZeroUsizeScott McMurray-0/+16
2022-10-09expand documentation on type conversion w.r.t. `UnsafeCell`Pointerbender-13/+21
2022-10-10Rollup merge of #102072 - scottmcm:ptr-alignment-type, r=thomccYuki Okushi-64/+115
Add `ptr::Alignment` type Essentially no new code here, just exposing the previously-`pub(crate)` `ValidAlign` type under the name from the ACP. ACP: https://github.com/rust-lang/libs-team/issues/108 Tracking Issue: https://github.com/rust-lang/rust/issues/102070 r? ``@ghost``
2022-10-08Rollup merge of #102812 - est31:remove_lazy, r=dtolnayMichael Howell-3/+0
Remove empty core::lazy and std::lazy PR #98165 with commits 7c360dc117d554a11f7193505da0835c4b890c6f and c1a2db3372a4d6896744919284f3287650a38ab7 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them.
2022-10-08Rollup merge of #99880 - ↵Matthias Krüger-2/+0
compiler-errors:escape-ascii-is-not-exact-size-iterator, r=thomcc `EscapeAscii` is not an `ExactSizeIterator` Fixes #99878 Do we want/need `EscapeAscii` to be an `ExactSizeIterator`? I guess we could precompute the length of the output if so?
2022-10-08Auto merge of #102315 - RalfJung:assert_unsafe_precondition, r=thomccbors-1/+6
add a few more assert_unsafe_precondition Add debug-assertion checking for `ptr.read()`, `ptr.write(_)`, and `unreachable_unchecked.` This is quite useful for [cargo-careful](https://github.com/RalfJung/cargo-careful).
2022-10-08Remove empty core::lazy and std::lazyest31-3/+0
PR #98165 with commits 7c360dc117d554a11f7193505da0835c4b890c6f and c1a2db3372a4d6896744919284f3287650a38ab7 has moved all of the components of these modules into different places, namely {std,core}::sync and {std,core}::cell. The empty modules remained. As they are unstable, we can simply remove them.
2022-10-07Rollup merge of #102300 - scottmcm:simpler-fold-closures, r=Mark-SimulacrumDylan DPC-114/+35
Use a macro to not have to copy-paste `ConstFnMutClosure::new(&mut fold, NeverShortCircuit::wrap_mut_2_imp)).0` everywhere Also use that macro to replace a bunch of places that had custom closure-wrappers. +35 -114 sounds good to me.
2022-10-07add a few more assert_unsafe_preconditionRalf Jung-1/+6
2022-10-06Fix handling of trailing bare CR in str::linesKonrad Borowski-5/+5
Previously "bare\r" was split into ["bare"] even though the documentation said that only LF and CRLF count as newlines. This fix is a behavioural change, even though it brings the behaviour into line with the documentation, and into line with that of `std::io::BufRead::lines()`. This is an alternative to #91051, which proposes to document rather than fix the behaviour. Fixes #94435. Co-authored-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-10-06Rename LinesAnyMap to LinesMapKonrad Borowski-4/+4
lines_any method was replaced with lines method, so it makes sense to rename this structure to match new name. Co-authored-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-10-06poll_fn and Unpin: fix pinningRalf Jung-4/+7
2022-10-05Add missing trailing `)]`Joshua Liebow-Feeser-1/+1
2022-10-05Fix typo (missing `>`)Joshua Liebow-Feeser-1/+1
2022-10-05Update library/core/src/num/nonzero.rsJoshua Liebow-Feeser-0/+2
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-10-04Rollup merge of #102647 - oli-obk:tilde_const_bounds, r=fee1-deadMatthias Krüger-1/+2
Only allow ~const bounds for traits with #[const_trait] r? `@fee1-dead`
2022-10-04Rollup merge of #101189 - daxpedda:ready-into-inner, r=joshtriplettDylan DPC-0/+24
Implement `Ready::into_inner()` Tracking issue: #101196. This implements a method to unwrap the value inside a `Ready` outside an async context. See https://docs.rs/futures/0.3.24/futures/future/struct.Ready.html#method.into_inner for previous work. This was discussed in [Zulip beforehand](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60Ready.3A.3Ainto_inner.28.29.60): > An example I'm hitting right now: I have a cross-platform library that provides a functions that returns a `Future`. The only reason why it returns a `Future` is because the WASM platform requires it, but the native doesn't, to make a cross-platform API that is equal for all I just return a `Ready` on the native targets. > > Now I would like to expose native-only functions that aren't async, that users can use to avoid having to deal with async when they are targeting native. With `into_inner` that's easily solvable now. > > I want to point out that some internal restructuring could be used to solve that problem too, but in this case it's not that simple, the library uses internal traits that return the `Future` already and playing around with that would introduce unnecessary `cfg` in a lot more places. So it is really only a quality-of-life feature.
2022-10-04Only allow ~const bounds for traits with #[const_trait]Oli Scherer-1/+2
2022-10-04Rollup merge of #102628 - H4x5:master, r=scottmcmMatthias Krüger-1/+1
Change the parameter name of From::from to `value` The `From` trait is currently defined as: ```rust pub trait From<T>: Sized { fn from(_: T) -> Self; } ``` The name of the argument is `_`. I am proposing to change it to `value`, ie. ```rust pub trait From<T>: Sized { fn from(value: T) -> Self; } ``` This would be more consistent with the `TryFrom`, which looks like this: ```rust pub trait TryFrom<T>: Sized { type Error; fn try_from(value: T) -> Result<Self, Self::Error>; } ``` The reason for this proposal is twofold: 1. Consistency with the rest of the standard library. The `TryFrom` trait uses `value`, and no `From` implementation uses the default name (as it is quite useless). 2. When generating trait implementations with rust-analyzer/IntelliJ, the parameter name is copied, and it always has to be changed. Optionally, another name like `x` could be used. I only propose `value` for consistency with `TryFrom`. Changing parameter names is not a breaking change. Note: this was originally posted as an internals thread [here](https://internals.rust-lang.org/t/change-the-argument-name-of-from-from/17480)
2022-10-04Auto merge of #99099 - Stargateur:phantomdata_debug, r=joshtriplettbors-1/+1
Add T to PhantomData impl Debug This add debug information for `PhantomData`, I believe it's make sense to add this to debug impl of `PhantomData` since `T` is what define what is the `PhantomData` just write `"PhantomData"` is not very useful for debugging. Alternative: * `PhantomData::<{}>` * `PhantomData { t: "str_type" }` `@rustbot` label +T-libs-api -T-libs
2022-10-03Auto merge of #102632 - matthiaskrgr:rollup-h8s3zmo, r=matthiaskrgrbors-19/+253
Rollup of 7 pull requests Successful merges: - #98218 (Document the conditional existence of `alloc::sync` and `alloc::task`.) - #99216 (docs: be less harsh in wording for Vec::from_raw_parts) - #99460 (docs: Improve AsRef / AsMut docs on blanket impls) - #100470 (Tweak `FpCategory` example order.) - #101040 (Fix `#[derive(Default)]` on a generic `#[default]` enum adding unnecessary `Default` bounds) - #101308 (introduce `{char, u8}::is_ascii_octdigit`) - #102486 (Add diagnostic struct for const eval error in `rustc_middle`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-10-03Rollup merge of #101308 - nerdypepper:feature/is-ascii-octdigit, r=joshtriplettMatthias Krüger-0/+65
introduce `{char, u8}::is_ascii_octdigit` This feature adds two new APIs: `char::is_ascii_octdigit` and `u8::is_ascii_octdigit`, under the feature gate `is_ascii_octdigit`. These methods are shorthands for `char::is_digit(self, 8)` and `u8::is_digit(self, 8)`: ```rust // core::char impl char { pub fn is_ascii_octdigit(self) -> bool; } // core::num impl u8 { pub fn is_ascii_octdigit(self) -> bool; } ``` --- Couple of things I need help understanding: - `const`ness: have I used the right attribute in this case? - is there a way to run the tests for `core::char` alone, instead of `./x.py test library/core`?
2022-10-03Rollup merge of #100470 - reitermarkus:patch-1, r=joshtriplettMatthias Krüger-1/+1
Tweak `FpCategory` example order. Follow same order for variable declarations and assertions.
2022-10-03Rollup merge of #99460 - JanBeh:PR_asref_asmut_docs, r=joshtriplettMatthias Krüger-18/+187
docs: Improve AsRef / AsMut docs on blanket impls There are several issues with the current state of `AsRef` and `AsMut` as [discussed here on IRLO](https://internals.rust-lang.org/t/semantics-of-asref/17016). See also #39397, #45742, #73390, #98905, and the FIXMEs [here](https://github.com/rust-lang/rust/blob/1.62.0/library/core/src/convert/mod.rs#L509-L515) and [here](https://github.com/rust-lang/rust/blob/1.62.0/library/core/src/convert/mod.rs#L530-L536). These issues are difficult to fix. This PR aims to update the documentation to better reflect the status-quo and to give advice on how `AsRef` and `AsMut` should be used. In particular: - Explicitly mention that `AsRef` and `AsMut` do not auto-dereference generally for all dereferencable types (but only if inner type is a shared and/or mutable reference) - Give advice to not use `AsRef` or `AsMut` for the sole purpose of dereferencing - Suggest providing a transitive `AsRef` or `AsMut` implementation for types which implement `Deref` - Add new section "Reflexivity" in documentation comments for `AsRef` and `AsMut` - Provide better example for `AsMut` - Added heading "Relation to `Borrow`" in `AsRef`'s docs to improve structure
2022-10-03Change the parameter name of From::from to `value`H4x5-1/+1
2022-10-03Rollup merge of #102607 - WaffleLapkin:docky_docky_slice_from_ptr_range, ↵Matthias Krüger-1/+23
r=joshtriplett Improve documentation of `slice::{from_ptr_range, from_ptr_range_mut}` Document panic conditions (`T` is a ZST) and sync docs of shared/unique version. cc `@wx-csy`
2022-10-03Rollup merge of #102569 - eduardosm:from_str-example, r=joshtriplettMatthias Krüger-5/+9
Improve `FromStr` example The `from_str` implementation from the example had an `unwrap` that would make it panic on invalid input strings. Instead of panicking, it nows returns an error to better reflect the intented behavior of the `FromStr` trait.
2022-10-03Add better assert messages for f32/f64 clampsJacob Kiesel-2/+2
2022-10-03Sync docs of `slice::{from_ptr_range, from_ptr_range_mut}`Maybe Waffle-1/+15
2022-10-03Document when `slice::from_ptr_range[_mut]` panicMaybe Waffle-0/+8
2022-10-02remove unneeded attributesLukas Markeffsky-12/+0
2022-10-02Auto merge of #98354 - camsteffen:is-some-and-by-value, r=m-ou-sebors-18/+27
Change `is_some_and` to take by value Consistent with other function-accepting `Option` methods. Tracking issue: #93050 r? `@m-ou-se`
2022-10-02always panic for invalid integer logarithmLukas Markeffsky-73/+15
2022-10-02Auto merge of #102548 - nikic:inline-cell-replace, r=scottmcmbors-0/+1
Mark Cell::replace() as #[inline] Giving this a try based on https://github.com/rust-lang/rust/issues/102539#issuecomment-1264398807.
2022-10-02Improve `FromStr` exampleEduardo Sánchez Muñoz-5/+9
The `from_str` implementation from the example had an `unwrap` that would make it panic on invalid input strings. Instead of panicking, it nows returns an error to better reflect the intented behavior of the `FromStr` trait.
2022-10-02Auto merge of #102535 - scottmcm:optimize-split-at-partition-point, r=thomccbors-3/+12
Tell LLVM that `partition_point` returns a valid fencepost This was already done for a successful `binary_search`, but this way `partition_point` can get similar optimizations. Demonstration that nightly can't do this optimization today, and leaves in the panicking path: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e1074cd2faf5f68e49cffd728ded243a> r? `@thomcc`
2022-10-02Rollup merge of #102405 - hkBst:patch-3, r=Mark-SimulacrumMatthias Krüger-3/+0
Remove a FIXME whose code got moved away in #62883. Remove a FIXME whose code got moved away in https://github.com/rust-lang/rust/pull/62883.
2022-10-01Change feature name to is_some_andCameron Steffen-6/+6
2022-10-01Change is_some_and to take by valueCameron Steffen-12/+21
2022-10-01Mark Cell::replace() as #[inline]Nikita Popov-0/+1
2022-09-30Tell LLVM that `partition_point` returns a valid fencepostScott McMurray-3/+12
This was already done for a successful `binary_search`, but this way `partition_point` can get similar optimizations.
2022-09-30Auto merge of #102520 - matthiaskrgr:rollup-7nreat0, r=matthiaskrgrbors-26/+40
Rollup of 6 pull requests Successful merges: - #102276 (Added more const_closure functionality) - #102382 (Manually order `DefId` on 64-bit big-endian) - #102421 (remove the unused :: between trait and type to give user correct diag…) - #102495 (Reinstate `hir-stats.rs` test for stage 1.) - #102505 (rustdoc: remove no-op CSS `h3.variant, .sub-variant h4 { border-bottom: none }`) - #102506 (Specify `DynKind::Dyn`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-09-30Add back ConstFnMutClosure::new, fix formattingonestacked-47/+48
2022-09-30Fixed Documentation for wrap_mut_2_imponestacked-1/+1