about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-03-16core: document default attribute stabilizationTravis Finkenauer-0/+2
2024-03-16Optimize `core::char::CaseMappingIter` layoutJules Bertholet-27/+27
Godbolt says this saves a few instructions…
2024-03-17Auto merge of #121885 - reitermarkus:generic-nonzero-inner, ↵bors-51/+98
r=oli-obk,wesleywiser Move generic `NonZero` `rustc_layout_scalar_valid_range_start` attribute to inner type. Tracking issue: https://github.com/rust-lang/rust/issues/120257 r? `@dtolnay`
2024-03-16Add as_(mut_)ptr and as_(mut_)slice to raw array pointersYotam Ofek-0/+84
2024-03-16core: optimize `ptr::replace`joboet-3/+2
2024-03-15Workaround issue 122566Scott McMurray-6/+6
2024-03-14Stabilize `unchecked_{add,sub,mul}`Scott McMurray-50/+69
2024-03-14Rollup merge of #122479 - GrigorenkoPV:duration_millis_float, r=scottmcmMatthias Krüger-0/+42
Implement `Duration::as_millis_{f64,f32}` Implementation of #122451. Linked const-unstability to #72440, so the post there should probably be updated to mentions the 2 new methods when/if this PR is merged.
2024-03-14Hide implementation details for `NonZero` auto traits.Markus Reiter-1/+22
2024-03-14Implement ptr_as_ref_unchecked (#122034)Pavel Grigorenko-0/+151
2024-03-14Rollup merge of #122461 - the8472:fix-step-forward-unchecked, r=AmanieuMatthias Krüger-2/+28
fix unsoundness in Step::forward_unchecked for signed integers Fixes #122420 ```rust pub fn foo(a: i8, b: u8) -> i8 { unsafe { a.checked_add_unsigned(b).unwrap_unchecked() } } ``` still compiles down to a single arithmetic instruction ([godbolt](https://rust.godbolt.org/z/qsd3xYWfE)). But we may be losing some loop optimizations if llvm can no longer easily derive that it's a finite counted loop from the no-wrapping flags.
2024-03-14Rollup merge of #122421 - CAD97:step-trait-docs, r=jhprattMatthias Krüger-8/+7
Improve `Step` docs It [came up on urlo](https://users.rust-lang.org/t/implement-trait-step-in-1-76-0/108204?u=cad97) that the unstable reason string isn't helpful, so just remove it; there's nothing meaningful to add here. Also makes a couple drive-by improvements to the method docs -- removes incorrect references, changes `forward_checked`'s invariant formulation to match `backward_checked`'s, and adds a helpful corollary that `step_unchecked(a, 0)` is always safe.
2024-03-14Rollup merge of #104353 - clarfonthey:cstr-bytes-iter, r=cuviperMatthias Krüger-0/+91
Add CStr::bytes iterator See rust-lang/libs-team#135 for an ACP. Since rust-lang/libs-team#134 was also accepted, this type is now `core::ffi::c_str::Bytes` instead of `core::ffi::CStrBytes`.
2024-03-14fix unsoundness in Step::forward_unchecked for signed integersThe 8472-2/+28
2024-03-14Implement `Duration::as_millis_{f64,f32}`Pavel Grigorenko-0/+42
2024-03-13Improve Step docsChristopher Durham-8/+7
2024-03-12Reduce unsafe code, use more NonNull APIs per @cuviper reviewltdk-9/+11
2024-03-12transmute: caution against int2ptr transmutationRalf Jung-8/+29
2024-03-12Use `min_exhaustive_patterns` in core & stdNadrieril-1/+2
2024-03-11Rollup merge of #121840 - oli-obk:freeze, r=dtolnayJacob Pratt-2/+9
Expose the Freeze trait again (unstably) and forbid implementing it manually non-emoji version of https://github.com/rust-lang/rust/pull/121501 cc #60715 This trait is useful for generic constants (associated consts of generic traits). See the test (`tests/ui/associated-consts/freeze.rs`) added in this PR for a usage example. The builtin `Freeze` trait is the only way to do it, users cannot work around this issue. It's also a useful trait for building some very specific abstrations, as shown by the usage by the `zerocopy` crate: https://github.com/google/zerocopy/issues/941 cc ```@RalfJung``` T-lang signed off on reexposing this unstably: https://github.com/rust-lang/rust/pull/121501#issuecomment-1969827742
2024-03-11Rollup merge of #121148 - clarfonthey:try-range, r=dtolnayJacob Pratt-5/+56
Add slice::try_range This adds a fallible version of the unstable `slice::range` (tracking: #76393) which is highly requested in the tracking issue. Hoping this can slide by without an ACP (since the feature is already being tracked), but let me know otherwise.
2024-03-10Rollup merge of #122302 - ratmice:issue122234, r=cuviperMatthias Krüger-4/+4
docs: Correct ptr/ref verbiage in SliceIndex docs. Fixes #122234
2024-03-10Rollup merge of #122277 - RalfJung:BorrowedCursor, r=cuviperMatthias Krüger-2/+4
BorrowedCursor docs clarification If one reads the `BorrowedCursor` docs without having seen `BorrowedBuf` before, it is quite easy to assume that "unfilled" and "uninit" are synonyms.
2024-03-10Add CStr::bytes iteratorltdk-0/+89
2024-03-10docs: Correct ptr/ref verbiage in SliceIndex docs.matt rice-4/+4
Fixes #122234
2024-03-10Fix lint.Markus Reiter-0/+1
2024-03-10Move generic `NonZero` `rustc_layout_scalar_valid_range_start` attribute to ↵Markus Reiter-51/+76
inner type.
2024-03-10Rollup merge of #122271 - pitaj:diag_items-legacy_numeric_constants, r=NilstriebMatthias Krüger-0/+2
Fix legacy numeric constant diag items - missed syms for usize/isize - missed diag items on unsigned integers For rust-lang/rust-clippy#12312 r? ```@Nilstrieb``` Follow-up to #121272, #121361, #121667 This should be the last one 🤞 Sorry!
2024-03-10Rollup merge of #122244 - tvallotton:local_waker_leak_fix, r=NilstriebMatthias Krüger-5/+16
fix: LocalWaker memory leak and some stability attributes fixes #122180.
2024-03-10Rollup merge of #112136 - clarfonthey:ffi-c_str, r=cuviperMatthias Krüger-7/+24
Add std::ffi::c_str module ACP: rust-lang/libs-team#134 `std::ffi` docs before change: ![Structs: VaList, VaListImpl, CStr, CString, FromBytesWithNulError, FromVecWithNulError, IntoStringError, NulError, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/b2cf3534-30f9-4ef0-a655-bacdc3a19e17) `std::ffi` docs after change: ![Re-exports: self::c_str::{FromBytesWithNulError, FromBytesUntilNulError, FromVecWithNulError, NulError, IntoStringError} ; Modules: c_str ; Structs: VaList, VaListImpl, CStr, CString, OsStr, OsString](https://github.com/rust-lang/rust/assets/15850505/23aa6964-da7a-4942-bbf7-42bde2146f9e) (note: I'm omitting the `c_int`, etc. stuff from the screenshots since it's the same in both. this doesn't just delete those types)
2024-03-10BorrowedCursor docs clarificationRalf Jung-2/+4
2024-03-09fix legacy numeric constant diag itemsPeter Jaszkowiak-0/+2
- missed syms for usize/isize - missed diag items on unsigned integers
2024-03-10Auto merge of #121662 - saethlin:precondition-unification, r=RalfJungbors-202/+279
Distinguish between library and lang UB in assert_unsafe_precondition As described in https://github.com/rust-lang/rust/pull/121583#issuecomment-1963168186, `assert_unsafe_precondition` now explicitly distinguishes between language UB (conditions we explicitly optimize on) and library UB (things we document you shouldn't do, and maybe some library internals assume you don't do). `debug_assert_nounwind` was originally added to avoid the "only at runtime" aspect of `assert_unsafe_precondition`. Since then the difference between the macros has gotten muddied. This totally revamps the situation. Now _all_ preconditions shall be checked with `assert_unsafe_precondition`. If you have a precondition that's only checkable at runtime, do a `const_eval_select` hack, as done in this PR. r? RalfJung
2024-03-09Rollup merge of #121280 - ajwock:maybeuninit_fill, r=AmanieuGuillaume Boisseau-16/+186
Implement MaybeUninit::fill{,_with,_from} ACP: rust-lang/libs-team#156
2024-03-09Explain why we don't use intrinsics::is_nonoverlappingBen Kimock-0/+2
2024-03-09fix: remove memory leak due to missing drop implementation for local waker. ↵Tomás Vallotton-5/+16
Also, fix some of the stability attributes of LocalWaker's methods.
2024-03-09NonZero::from_mut_unchecked is library UBBen Kimock-1/+1
2024-03-09Improve docsBen Kimock-8/+10
2024-03-09Rollup merge of #122233 - RalfJung:custom-alloc-box, r=oli-obkMatthias Krüger-0/+13
miri: do not apply aliasing restrictions to Box with custom allocator This is the Miri side of https://github.com/rust-lang/rust/pull/122018. The "intrinsics with body" made this much more pleasant. :) Fixes https://github.com/rust-lang/miri/issues/3341. r? `@oli-obk`
2024-03-09Rollup merge of #122232 - RalfJung:misc, r=jhprattMatthias Krüger-6/+7
library/core: fix a comment, and a cfg(miri) warning Just two things I noticed while working on another PR.
2024-03-09Rollup merge of #121358 - GnomedDev:lower-align-typeid, r=Mark-SimulacrumMatthias Krüger-3/+8
Reduce alignment of TypeId to u64 alignment Closes #115620
2024-03-09miri: do not apply aliasing restrictions to Box with custom allocatorRalf Jung-0/+13
2024-03-09fn is_align_to: move some comments closer to the cast they refer toRalf Jung-6/+6
2024-03-09fix warning when building libcore for MiriRalf Jung-0/+1
2024-03-08Distinguish between library and lang UB in assert_unsafe_preconditionBen Kimock-202/+275
2024-03-08Stabilize associated type boundsMichael Goulet-1/+1
2024-03-08Rollup merge of #121201 - RalfJung:align_offset_contract, r=cuviperMatthias Krüger-16/+24
align_offset, align_to: no longer allow implementations to spuriously fail to align For a long time, we have allowed `align_offset` to fail to compute a properly aligned offset, and `align_to` to return a smaller-than-maximal "middle slice". This was done to cover the implementation of `align_offset` in const-eval and Miri. See https://github.com/rust-lang/rust/issues/62420 for more background. For about the same amount of time, this has caused confusion and surprise, where people didn't realize they have to write their code to be defensive against `align_offset` failures. Another way to put this is: the specification is effectively non-deterministic, and non-determinism is hard to test for -- in particular if the implementation everyone uses to test always produces the same reliable result, and nobody expects it to be non-deterministic to begin with. With https://github.com/rust-lang/rust/pull/117840, Miri has stopped making use of this liberty in the spec; it now always behaves like rustc. That only leaves const-eval as potential motivation for this behavior. I do not think this is sufficient motivation. Currently, none of the relevant functions are stably const: `align_offset` is unstably const, `align_to` is not const at all. I propose that if we ever want to make these const-stable, we just accept the fact that they can behave differently at compile-time vs at run-time. This is not the end of the world, and it seems to be much less surprising to programmers than unexpected non-determinism. (Related: https://github.com/rust-lang/rfcs/pull/3352.) `@thomcc` has repeatedly made it clear that they strongly dislike the non-determinism in align_offset, so I expect they will support this. `@oli-obk,` what do you think? Also, whom else should we involve? The primary team responsible is clearly libs-api, so I will nominate this for them. However, allowing const-evaluated code to behave different from run-time code is t-lang territory. The thing is, this is not stabilizing anything t-lang-worthy immediately, but it still does make a decision we will be bound to: if we accept this change, then - either `align_offset`/`align_to` can never be called in const fn, - or we allow compile-time behavior to differ from run-time behavior. So I will nominate for t-lang as well, with the question being: are you okay with accepting either of these outcomes (without committing to which one, just accepting that it has to be one of them)? This closes the door to "have `align_offset` and `align_to` at compile-time and also always have compile-time behavior match run-time behavior". Closes https://github.com/rust-lang/rust/issues/62420
2024-03-08Document overrides of `clone_from()`Noa-4/+40
Specifically, when an override doesn't just forward to an inner type, document the behavior and that it's preferred over simply assigning a clone of source. Also, change instances where the second parameter is "other" to "source".
2024-03-08align_offset, align_to: no longer allow implementations to spuriously fail ↵Ralf Jung-16/+24
to align
2024-03-08Rollup merge of #120608 - kornelski:slice-ptr-doc, r=cuviperMatthias Krüger-2/+26
Docs for std::ptr::slice_from_raw_parts