about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-11-26Rollup merge of #133282 - tgross35:maybe-uninit-debug, r=AmanieuMichael Goulet-1/+12
Shorten the `MaybeUninit` `Debug` implementation Currently the `Debug` implementation for `MaybeUninit` winds up being pretty verbose. This struct: ```rust #[derive(Debug)] pub struct Foo { pub a: u32, pub b: &'static str, pub c: MaybeUninit<u32>, pub d: MaybeUninit<String>, } ``` Prints as: Foo { a: 0, b: "hello", c: core::mem::maybe_uninit::MaybeUninit<u32>, d: core::mem::maybe_uninit::MaybeUninit<alloc::string::String>, } The goal is just to be a standin for content so the path prefix doesn't add any useful information. Change the implementation to trim `MaybeUninit`'s leading path, meaning the new result is now: Foo { a: 0, b: "hello", c: MaybeUninit<u32>, d: MaybeUninit<alloc::string::String>, }
2024-11-26Rollup merge of #133136 - ChayimFriedman2:get-many-mut, r=AmanieuMichael Goulet-19/+249
Support ranges in `<[T]>::get_many_mut()` As per T-libs-api decision in #104642. I implemented that with a separate trait and not within `SliceIndex`, because doing that via `SliceIndex` requires adding support for range types that are (almost) always overlapping e.g. `RangeFrom`, and also adding fake support code for `impl SliceIndex<str>`. An inconvenience that I ran into was that slice indexing takes the index by value, but I only have it by reference. I could change slice indexing to take by ref, but this is pretty much the hottest code ever so I'm afraid to touch it. Instead I added a requirement for `Clone` (which all index types implement anyway) and cloned. This is an internal requirement the user won't see and the clone should always be optimized away. I also implemented `Clone`, `PartialEq` and `Eq` for the error type, since I noticed it does not do that when writing the tests and other errors in std seem to implement them. I didn't implement `Copy` because maybe we will want to put something non-`Copy` there.
2024-11-25Fix typos in pin.rsAakarshit Uppal-3/+3
2024-11-25Constify Drop and DestructMichael Goulet-1/+2
2024-11-25Auto merge of #133247 - GuillaumeGomez:reduce-integer-display-impl, ↵bors-48/+32
r=workingjubilee Reduce integer `Display` implementation size I was thinking about #128204 and how we could reduce the size of the code and just realized that we didn't need the `_fmt` method to be implemented on signed integers, which in turns allow to simplify greatly the macro call. r? `@workingjubilee`
2024-11-25Support ranges in `<[T]>::get_many_mut()`Chayim Refael Friedman-19/+249
I implemented that with a separate trait and not within `SliceIndex`, because doing that via `SliceIndex` requires adding support for range types that are (almost) always overlapping e.g. `RangeFrom`, and also adding fake support code for `impl SliceIndex<str>`. An inconvenience that I ran into was that slice indexing takes the index by value, but I only have it by reference. I could change slice indexing to take by ref, but this is pretty much the hottest code ever so I'm afraid to touch it. Instead I added a requirement for `Clone` (which all index types implement anyway) and cloned. This is an internal requirement the user won't see and the clone should always be optimized away. I also implemented `Clone`, `PartialEq` and `Eq` for the error type, since I noticed it does not do that when writing the tests and other errors in std seem to implement them. I didn't implement `Copy` because maybe we will want to put something non-`Copy` there.
2024-11-25Rollup merge of #132533 - SUPERCILEX:patch-4, r=Mark-SimulacrumMatthias Krüger-0/+20
Add BorrowedBuf::into_filled{,_mut} methods to allow returning buffer with original lifetime See https://github.com/rust-lang/libs-team/issues/473 and tracking issue https://github.com/rust-lang/rust/issues/117693.
2024-11-25Rollup merge of #133260 - compiler-errors:deref, r=fee1-dead许杰友 Jieyou Xu (Joe)-0/+47
Constify the `Deref`/`DerefMut` traits, too One more constification. Rebased on that one commit that makes it so we don't need to provide stability on const impls. r? fee1-dead
2024-11-24Rollup merge of #133389 - eduardosm:stabilize-const_float_methods, r=RalfJungMatthias Krüger-49/+70
Stabilize `const_float_methods` Tracking issue: https://github.com/rust-lang/rust/issues/130843 Relnotes: #133383 Stabilized const API: ```rust // in `core` impl f32/f64 { pub const fn recip(self) -> Self; pub const fn to_degrees(self) -> Self; pub const fn to_radians(self) -> Self; pub const fn max(self, other: Self) -> Self; pub const fn min(self, other: Self) -> Self; pub const fn clamp(self, min: Self, max: Self) -> Self; pub const fn abs(self) -> Self; pub const fn signum(self) -> Self; pub const fn copysign(self, sign: Self) -> Self; } ``` Closes https://github.com/rust-lang/rust/issues/130843 r? libs-api cc `@RalfJung` -- I think the way const-stability attributes work have change a bit since the last time a wrote a const-stabilization PR, please make sure I got them right.
2024-11-24Rollup merge of #133301 - GuillaumeGomez:add-example-wrapping-neg, ↵Matthias Krüger-0/+1
r=workingjubilee Add code example for `wrapping_neg` method for signed integers With this example, we make it obvious that `wrapping_neg` works both ways (neg to pos and pos to neg). r? `@workingjubilee`
2024-11-24changes old intrinsic declaration to new declarationaaishwarymishra@gmail.com-595/+949
blesses tests/ui/intrinsics blesses tests/ui/intrinsics
2024-11-24Constify Deref and DerefMutMichael Goulet-0/+47
2024-11-23Match simd_relaxed_fma documentation to fmuladd intrinsicCaleb Zulawski-4/+8
2024-11-23Auto merge of #133379 - jieyouxu:rollup-00jxo71, r=jieyouxubors-0/+14
Rollup of 4 pull requests Successful merges: - #133217 ([AIX] Add option -X32_64 to the "strip" command) - #133237 (Minimally constify `Add`) - #133355 (Add language tests for aggregate types) - #133374 (show abi_unsupported_vector_types lint in future breakage reports) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-23Add simd_relaxed_fma intrinsicCaleb Zulawski-0/+10
2024-11-23Stabilize `const_float_methods`Eduardo Sánchez Muñoz-49/+70
2024-11-23Improve code by using `unsigned_abs`Guillaume Gomez-18/+2
2024-11-23Rollup merge of #133237 - fee1-dead-contrib:constadd, r=compiler-errors许杰友 Jieyou Xu (Joe)-0/+14
Minimally constify `Add` * This PR removes the requirement for `impl const` to have a const stability attribute. cc ``@RalfJung`` I believe you mentioned that it would make much more sense to require `const_trait`s to have const stability instead. I agree with that sentiment but I don't think that is _required_ for a small scale experimentation like this PR. https://github.com/rust-lang/project-const-traits/issues/16 should definitely be prioritized in the future, but removing the impl check should be good for now as all callers need `const_trait_impl` enabled for any const impl to work. * This PR is intentionally minimal as constifying other traits can become more complicated (`PartialEq`, for example, would run into requiring implementing it for `str` as that is used in matches, which runs into the implementation for slice equality which uses specialization) Per the reasons above, anyone who is interested in making traits `const` in the standard library are **strongly encouraged** to reach out to us on the [Zulip channel](https://rust-lang.zulipchat.com/#narrow/channel/419616-t-compiler.2Fproject-const-traits) before proceeding with the work. cc ``@rust-lang/project-const-traits`` I believe there is prior approval from libs that we can experiment, so r? project-const-traits
2024-11-23Rollup merge of #133332 - bjoernager:const-array-as-mut-slice, r=jhpratt许杰友 Jieyou Xu (Joe)-1/+2
Mark `<[T; N]>::as_mut_slice` with the `const` specifier. Tracking issue: #133333 `<[T; N]>::as_mut_slice` can have the `const` specifier without any changes to the function body.
2024-11-23Auto merge of #132329 - compiler-errors:fn-and-destruct, r=lcnrbors-1/+1
Implement `~const Destruct` effect goal in the new solver This also fixed a subtle bug/limitation of the `NeedsConstDrop` check. Specifically, the "`Qualif`" API basically treats const drops as totally structural, even though dropping something that has an explicit `Drop` implementation cannot be structurally decomposed. For example: ```rust #![feature(const_trait_impl)] #[const_trait] trait Foo { fn foo(); } struct Conditional<T: Foo>(T); impl Foo for () { fn foo() { println!("uh oh"); } } impl<T> const Drop for Conditional<T> where T: ~const Foo { fn drop(&mut self) { T::foo(); } } const FOO: () = { let _ = Conditional(()); //~^ This should error. }; fn main() {} ``` In this example, when checking if the `Conditional(())` rvalue is const-drop, since `Conditional` has a const destructor, we would previously recurse into the `()` value and determine it has nothing to drop, which means that it is considered to *not* need a const drop -- even though dropping `Conditional(())` would mean evaluating the destructor which relies on that `T: const Foo` bound to hold! This could be fixed alternatively by banning any const conditions on `const Drop` impls, but that really sucks -- that means that basically no *interesting* const drop impls could be written. We have the capability to totally and intuitively support the right behavior, which I've implemented here.
2024-11-22Shorten the `MaybeUninit` `Debug` implementationTrevor Gross-1/+12
Currently the `Debug` implementation for `MaybeUninit` winds up being pretty verbose. This struct: #[derive(Debug)] pub struct Foo { pub a: u32, pub b: &'static str, pub c: MaybeUninit<u32>, pub d: MaybeUninit<String>, } Prints as: Foo { a: 0, b: "hello", c: core::mem::maybe_uninit::MaybeUninit<u32>, d: core::mem::maybe_uninit::MaybeUninit<alloc::string::String>, } The goal is just to be a standin for content so the path prefix doesn't add any useful information. Change the implementation to trim `MaybeUninit`'s leading path, meaning the new result is now: Foo { a: 0, b: "hello", c: MaybeUninit<u32>, d: MaybeUninit<alloc::string::String>, }
2024-11-22Add code example for `wrapping_neg` method for signed integersGuillaume Gomez-0/+1
2024-11-22Deduplicate checking drop terminatorMichael Goulet-1/+1
2024-11-22Gate const drop behind const_destruct feature, and fix ↵Michael Goulet-1/+1
const_precise_live_drops post-drop-elaboration check
2024-11-22Auto merge of #133339 - jieyouxu:rollup-gav0nvr, r=jieyouxubors-4/+30
Rollup of 8 pull requests Successful merges: - #133238 (re-export `is_loongarch_feature_detected`) - #133288 (Support `each_ref` and `each_mut` in `[T; N]` in constant expressions.) - #133311 (Miri subtree update) - #133313 (Use arc4random of libc for RTEMS target) - #133319 (Simplify `fulfill_implication`) - #133323 (Bail in effects in old solver if self ty is ty var) - #133330 (library: update comment around close()) - #133337 (Fix typo in `std::thread::Scope::spawn` documentation.) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-22Rollup merge of #133288 - bjoernager:const-array-each-ref, r=jhpratt许杰友 Jieyou Xu (Joe)-4/+30
Support `each_ref` and `each_mut` in `[T; N]` in constant expressions. Tracking issue: #133289 The methods `<[T; N]>::each_ref` and `<[T; N]>::each_mut` can easily be reimplemented to allow marking them with the `const` specifier. This specific implementation takes a different approach than the original as to avoid using iterators (which are illegal in constant expressions).
2024-11-22Auto merge of #130867 - michirakara:steps_between, r=dtolnaybors-74/+89
distinguish overflow and unimplemented in Step::steps_between
2024-11-22Mark '<[T; N]>::as_mut_slice' as 'const';Gabriel Bjørnager Jensen-1/+2
2024-11-22Auto merge of #129238 - umgefahren:stabilize-ipv6-unique-local, r=dtolnaybors-6/+4
Stabilize `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local` Make `Ipv6Addr::is_unique_local` and `Ipv6Addr::is_unicast_link_local` stable (+const). Newly stable API: ```rust impl Ipv6Addr { // Newly stable under `ipv6_is_unique_local` const fn is_unique_local(&self) -> bool; // Newly stable under `ipv6_is_unique_local` const fn is_unicast_link_local(&self) -> bool; } ``` These stabilise a subset of the following tracking issue: - #27709 I have looked and could not find any issues with `is_unique_local` and `is_unicast_link_local`. There is a well received comment calling for stabilisation of the latter function. Both functions are well defined and consistent with implementations in other languages: - [Go](https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/net/netip/netip.go;l=518) - [Python](https://github.com/python/cpython/blob/e9d1bf353c3ccafc0d9b61b1b3688051bc976604/Lib/ipaddress.py#L2319-L2321) - [Ruby (unique local)](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html#private-3F-source) - [Ruby (unicast link local)](https://ruby-doc.org/stdlib-2.5.1/libdoc/ipaddr/rdoc/IPAddr.html#link_local-3F-source) cc implementor `@little-dude` (I can't find the original PR for `is_unqiue_local`) r? libs-api `@rustbot` label +T-libs-api +needs-fcp
2024-11-21distinguish overflow and unimplemented in Step::steps_betweenmichirakara-74/+89
2024-11-21Mark and implement 'each_ref' and 'each_mut' in '[T; N]' as const;Gabriel Bjørnager Jensen-4/+30
2024-11-21constify `Add`Deadbeef-0/+14
2024-11-20Rollup merge of #133226 - compiler-errors:opt-in-pointer-like, r=lcnrMatthias Krüger-0/+12
Make `PointerLike` opt-in instead of built-in The `PointerLike` trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, calling `layout_of` in the trait system also causes cycles. This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be `derive()`d for custom smart pointers, and we can trust *that* as a semver promise rather than risking library authors accidentally breaking it. On the other hand, we may never expose `PointerLike`, but at least now the implementation doesn't invoke `layout_of` which could cause ICEs or cause cycles. Right now for a `PointerLike` impl to be valid, it must be an ADT that is `repr(transparent)` and the non-1zst field needs to implement `PointerLike`. There are also some primitive impls for `&T`/ `&mut T`/`*const T`/`*mut T`/`Box<T>`.
2024-11-20Make PointerLike opt-in as a traitMichael Goulet-0/+12
2024-11-20Reduce integer `Display` implementation sizeGuillaume Gomez-41/+41
2024-11-20Stabilize const_pin_2George Bateman-4/+4
2024-11-20Rollup merge of #132732 - gavincrawford:as_ptr_attribute, r=UrgauJacob Pratt-0/+12
Use attributes for `dangling_pointers_from_temporaries` lint Checking for dangling pointers by function name isn't ideal, and leaves out certain pointer-returning methods that don't follow the `as_ptr` naming convention. Using an attribute for this lint cleans things up and allows more thorough coverage of other methods, such as `UnsafeCell::get()`.
2024-11-19Correct comments concerning updated dangling pointer lintgavincrawford-1/+1
2024-11-18const_panic: inline in bootstrap builds to avoid f16/f128 crashesRalf Jung-1/+1
2024-11-18rename rustc_const_stable_intrinsic -> rustc_intrinsic_const_stable_indirectRalf Jung-48/+48
2024-11-17Auto merge of #120370 - x17jiri:likely_unlikely_fix, r=saethlinbors-8/+40
Likely unlikely fix RFC 1131 ( https://github.com/rust-lang/rust/issues/26179 ) added likely/unlikely intrinsics, but they have been broken for a while: https://github.com/rust-lang/rust/issues/96276 , https://github.com/rust-lang/rust/issues/96275 , https://github.com/rust-lang/rust/issues/88767 . This PR tries to fix them. Changes: - added a new `cold_path()` intrinsic - `likely()` and `unlikely()` changed to regular functions implemented using `cold_path()`
2024-11-17Likely unlikely fixJiri Bobek-8/+40
2024-11-17Rollup merge of #133116 - RalfJung:const-null-ptr, r=dtolnay许杰友 Jieyou Xu (Joe)-33/+36
stabilize const_ptr_is_null FCP passed in https://github.com/rust-lang/rust/issues/74939. The second commit cleans up const stability around UB checks a bit, now that everything they need (except for `const_eval_select`) is stable. Fixes https://github.com/rust-lang/rust/issues/74939
2024-11-16clean up const stability around UB checksRalf Jung-24/+26
2024-11-16stabilize const_ptr_is_nullRalf Jung-10/+11
2024-11-16Add `DerefMut` for `Lazy[Cell/Lock]` that delegates to the unstable ↵Chayim Refael Friedman-1/+9
`force_mut()`
2024-11-16Rollup merge of #132449 - RalfJung:is_val_statically_known, r=compiler-errorsMatthias Krüger-9/+5
mark is_val_statically_known intrinsic as stably const-callable The intrinsic doesn't actually "do" anything in terms of language semantics, and we are already using it in stable const fn. So let's just properly mark it as stably const-callable to avoid needing `rustc_allow_const_fn_unstable` (and thus reducing noise and keeping the remaining `rustc_allow_const_fn_unstable` as a more clear signal). Cc `@rust-lang/lang` usually you have to approve exposing intrinsics in const, but this intrinsic is basically just a compiler implementation detail. So FCP doesn't seem necessary. Cc `@rust-lang/wg-const-eval`
2024-11-16Rollup merge of #131717 - tgross35:stabilize-const_atomic_from_ptr, r=RalfJungMatthias Krüger-3/+3
Stabilize `const_atomic_from_ptr` The API is already stable since https://github.com/rust-lang/rust/pull/115719, but const stability was blocked on `const_mut_refs`. Since that was recently stabilized, const stabilize the following: ```rust // core::atomic impl AtomicBool { pub const unsafe fn from_ptr<'a>(ptr: *mut bool) -> &'a AtomicBool; } impl<T> AtomicPtr<T> { pub const unsafe fn from_ptr<'a>(ptr: *mut *mut T) -> &'a AtomicPtr<T>; } impl AtomicU8 { pub const unsafe fn from_ptr<'a>(ptr: *mut u8) -> &'a AtomicU8; } impl AtomicU16 { pub const unsafe fn from_ptr<'a>(ptr: *mut u16) -> &'a AtomicU16; } impl AtomicU32 { pub const unsafe fn from_ptr<'a>(ptr: *mut u32) -> &'a AtomicU32; } impl AtomicU64 { pub const unsafe fn from_ptr<'a>(ptr: *mut u64) -> &'a AtomicU64; } impl AtomicUsize { pub const unsafe fn from_ptr<'a>(ptr: *mut usize) -> &'a AtomicUsize; } impl AtomicI8 { pub const unsafe fn from_ptr<'a>(ptr: *mut i8) -> &'a AtomicI8; } impl AtomicI16 { pub const unsafe fn from_ptr<'a>(ptr: *mut i16) -> &'a AtomicI16; } impl AtomicI32 { pub const unsafe fn from_ptr<'a>(ptr: *mut i32) -> &'a AtomicI32; } impl AtomicI64 { pub const unsafe fn from_ptr<'a>(ptr: *mut i64) -> &'a AtomicI64; } impl AtomicIsize { pub const unsafe fn from_ptr<'a>(ptr: *mut isize) -> &'a AtomicIsize; } ```
2024-11-14Rollup merge of #133050 - tgross35:inline-f16-f128, r=saethlinJubilee-6/+4
Always inline functions signatures containing `f16` or `f128` There are a handful of tier 2 and tier 3 targets that cause a LLVM crash or linker error when generating code that contains `f16` or `f128`. The cranelift backend also does not support these types. To work around this, every function in `std` or `core` that contains these types must be marked `#[inline]` in order to avoid sending any code to the backend unless specifically requested. However, this is inconvenient and easy to forget. Introduce a check for these types in the frontend that automatically inlines any function signatures that take or return `f16` or `f128`. Note that this is not a perfect fix because it does not account for the types being passed by reference or as members of aggregate types, but this is sufficient for what is currently needed in the standard library. Fixes: https://github.com/rust-lang/rust/issues/133035 Closes: https://github.com/rust-lang/rust/pull/133037
2024-11-14Rollup merge of #133048 - cyrgani:ptr-doc-update, r=AmanieuJubilee-8/+6
use `&raw` in `{read, write}_unaligned` documentation Fixes #133024 by using `&raw const` and `&raw mut` instead of `addr_of!` and `addr_of_mut!`.