about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-03-19Remove `SpecOptionPartialEq`clubby789-71/+10
2024-03-19SeqCst->Relaxed in doc examples.Mara Bos-6/+3
SeqCst is unnecessary here.
2024-03-19[doc]:fix error code exampleheisen-li-3/+3
2024-03-19Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends ↵Oli Scherer-9/+18
implementing it
2024-03-19Make `vtable_align` a rustc_intrinsicOli Scherer-2/+14
2024-03-19Make `const_eval_select` a rustc_intrinsicOli Scherer-56/+74
2024-03-19add notes on how to store 'ptr or int'Ralf Jung-2/+6
2024-03-18Reimplement `CaseMappingIter` with `core::array::IntoIter`Jules Bertholet-128/+181
Makes the iterator 2*usize larger, but I doubt that matters much. In exchange, we save a lot on instruction count. In the absence of delegation syntax, we must forward all the specialized impls manually…
2024-03-19Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obkbors-1/+1
Stabilize associated type bounds (RFC 2289) This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses. ### What are we stabilizing? We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation. In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info). Associated type bounds are stabilized in four positions: * **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`. * **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629. * **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`. * **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound. The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds. ### How does this differ from the RFC? Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular: * It does *not* desugar to anonymous associated items in associated type item bounds. * It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds. This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example: * Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531. * Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types. This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719. ### Implementation history: Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out-- * #57428 * #108063 * #110512 * #112629 * #120719 * #120584 Closes #52662 [RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-18Rollup merge of #122675 - tmfink:doc-clarify, r=scottmcmMatthias Krüger-0/+2
core: document default attribute stabilization As of now, the first release which stabilized the `#[default]` macro for the deriving the `Default` trait for enus is not documented. I have had to search the [`RELEASES.md`](https://github.com/rust-lang/rust/blob/master/RELEASES.md) when making sure my code would be accepted by an older Rust compiler. I just added a line in the doc comment since, as far as I know, there's no option to pass to the `#[stable()]` attribute. I am open to improvements in the wording.
2024-03-18remove retag_box_to_raw, it is no longer neededRalf Jung-13/+0
2024-03-17Let codegen decide when to `mem::swap` with immediatesScott McMurray-25/+26
Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea. So introduce a new `typed_swap` intrinsic with a fallback body, but replace that implementation for immediates and scalar pairs.
2024-03-17chore(121952): echo comments on the `*_assign` methodsPetr Portnov-0/+3
2024-03-17chore(121952): remove redundant commentsPetr Portnov-3/+0
These were only relevant for the unsafe-containing implementations Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2024-03-17feat: implement `{Div,Rem}Assign<NonZero<X>>` on `X`Petr Portnov-1/+20
Signed-off-by: Petr Portnov <me@progrm-jarvis.ru>
2024-03-17Rollup merge of #119411 - yotamofek:array-ptr-get, r=NilstriebMatthias Krüger-0/+99
Add as_(mut_)ptr and as_(mut_)slice to raw array pointers Hey, first time contributing to the standard libraries so not completely sure about the process. These functions are complementary to the ones being added in #74265 . I found them missing on array pointers. See also: - ACP: https://github.com/rust-lang/libs-team/issues/321 - Tracking issue: #119834
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/+99
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/+33
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/+33
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-22/+398
Implement MaybeUninit::fill{,_with,_from} ACP: rust-lang/libs-team#156