about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2025-02-28Do not require that unsafe fields lack drop glueJack Wrenn-2/+2
Instead, we adopt the position that introducing an `unsafe` field itself carries a safety invariant: that if you assign an invariant to that field weaker than what the field's destructor requires, you must ensure that field is in a droppable state in your destructor. See: - https://github.com/rust-lang/rfcs/pull/3458#discussion_r1971676100 - https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/unsafe.20fields.20RFC/near/502113897
2025-02-28Rollup merge of #137551 - folkertdev:import-simd-intrinsics, r=RalfJung许杰友 Jieyou Xu (Joe)-2/+2
import `simd_` intrinsics In most cases, we can import the simd intrinsics rather than redeclare them. Apparently, most of these tests were written before `std::intrinsics::simd` existed. There are a couple of exceptions where we can't yet import: - the intrinsics are not declared as `const fn` in the standard library, causing issues in the `const-eval` tests - the `simd_shuffle_generic` function is not exposed from `std::intrinsics` - the `simd_fpow` and `simd_fpowi` functions are not exposed from `std::intrinsics` (removed in https://github.com/rust-lang/rust/pull/137595) - some tests use `no_core`, and therefore cannot use `std::intrinsics` r? ```@RalfJung``` cc ```@workingjubilee``` do you have context on why some intrinsics are not exposed?
2025-02-28Rollup merge of #137197 - scottmcm:cmp-20, r=ibraheemdev许杰友 Jieyou Xu (Joe)-4/+4
Update some comparison codegen tests now that they pass in LLVM20 Fixes #106107 Needed one tweak to the default `PartialOrd::le` to get the test to pass. Everything but the derived 2-field `le` test passes even without the change to the defaults in the trait.
2025-02-27Fix char count in Display for ByteStrThalia Archibald-1/+3
2025-02-27Count char width at most once in Formatter::padThalia Archibald-37/+29
When both width and precision flags are specified, then the character width is counted twice. Instead, record the character width when truncating it to the precision, so it does not need to be recomputed. Simplify control flow so the cases are more clear.
2025-02-27make `simd_insert` and `simd_extract` `const fn`sFolkert de Vries-2/+2
2025-02-27Rollup merge of #137304 - pitaj:rangebounds-is_empty-intersect, r=ibraheemdevMatthias Krüger-5/+135
add `IntoBounds::intersect` and `RangeBounds::is_empty` - ACP: https://github.com/rust-lang/libs-team/issues/539 - Tracking issue for `is_empty`: #137300 - Tracking issue for `IntoBounds`: #136903
2025-02-27require trait impls to have matching const stabilities as the traitsDeadbeef-0/+4
2025-02-26Rollup merge of #136187 - hkBst:patch-27, r=workingjubileeLeón Orell Valerian Liehr-36/+37
Use less CString in the examples of CStr. Fixes #83999
2025-02-26Rollup merge of #134585 - cyrgani:uninit_array, r=AmanieuLeón Orell Valerian Liehr-36/+0
remove `MaybeUninit::uninit_array` Closes #134584. Closes #66845. The future of this unstable method was described in https://github.com/rust-lang/rust/pull/125082#issuecomment-2161242816. Since `inline_const` was stabilized in 1.79 (4 stable releases away) and no one expressed interest for keeping it in https://github.com/rust-lang/rust/issues/96097, I think it can be removed now as it is not a stable method.
2025-02-25fix doc in library/core/src/pin.rsxizheyin-2/+2
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-25Auto merge of #137571 - tgross35:rollup-i1tcnv1, r=tgross35bors-6/+3
Rollup of 8 pull requests Successful merges: - #134655 (Stabilize `hash_extract_if`) - #135933 (Explain how Vec::with_capacity is faithful) - #136668 (Stabilize `core::str::from_utf8_mut` as `const`) - #136775 (Update `String::from_raw_parts` safety requirements) - #137109 (stabilize extract_if) - #137349 (Implement `read_buf` for zkVM stdin) - #137493 (configure.py: don't instruct user to run nonexistent program) - #137516 (remove some unnecessary rustc_const_unstable) r? `@ghost` `@rustbot` modify labels: rollup
2025-02-25fix doc in library/core/src/sync/atomic.rsxizheyin-5/+5
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-02-24Rollup merge of #137489 - ↵Michael Goulet-1429/+356
RalfJung:no-more-rustc_intrinsic_must_be_overridden, r=oli-obk remove `#[rustc_intrinsic_must_be_overridde]` In https://github.com/rust-lang/rust/pull/135031, we gained support for just leaving away the body. Now that the bootstrap compiler got bumped, stop using the old style and remove support for it. r? `@oli-obk` There are a few more mentions of this attribute in RA code that I didn't touch; Cc `@rust-lang/rust-analyzer`
2025-02-24Rollup merge of #137516 - RalfJung:rustc_const_unstable-cleanup, r=AmanieuTrevor Gross-4/+1
remove some unnecessary rustc_const_unstable If the function is anyway unstable, it doesn't need to be `rustc_const_unstable`. `copy_from_slice` turns out to not do anything const-unstable itself, we just haven't stably committed to it being available in const yet. See [here](https://rustc-dev-guide.rust-lang.org/stability.html?highlight=rustc_const_stable_indirect) for more details on the `rustc_const_stable_indirect` attribute.
2025-02-24Rollup merge of #136668 - WaffleLapkin:from_utf8_mut, r=AmanieuTrevor Gross-2/+2
Stabilize `core::str::from_utf8_mut` as `const` cc #91006 (tracking issue) r? libs-api
2025-02-24Simplify trait error message for CoercePointee validationMichael Goulet-0/+1
2025-02-24span: add a "future" editionDavid Wood-0/+23
It's hard to implement edition migrations without having a perma-unstable "future" edition to target.
2025-02-24remove some unnecessary rustc_const_unstableRalf Jung-4/+1
2025-02-24Rollup merge of #137495 - ↵Jacob Pratt-0/+21
madhav-madhusoodanan:feature-unstable-control-flow-into-value, r=jhpratt Added into_value function to ControlFlow<T, T>
2025-02-24Rollup merge of #137484 - chenyukang:yukang-fix-sort-doc, r=NoratriebJacob Pratt-15/+33
Fix documentation for unstable sort on slice Fixes #136665
2025-02-24Rollup merge of #137393 - chorman0773:unbounded-shifts-stabilize, r=AmanieuJacob Pratt-8/+8
Stabilize `unbounded_shifts` This stabilizes and const-stabilizes `<iN>::unbounded_shl` and `<uN>::unbounded_shr` from https://github.com/rust-lang/rust/issues/129375.
2025-02-24Rollup merge of #137061 - progressive-galib:gen_future-closing#76249, ↵Jacob Pratt-4/+4
r=ibraheemdev Unstable `gen_future` Feature Tracking This PR removes the reference to the closed tracking issue **#50547** for the `gen_future` feature. Since `gen_future` is an internal feature used in async block desugaring, it does not require a public tracking issue. #### Changes: - Replaced `issue = "50547"` with `issue = "none"` in **library/core/src/future/mod.rs**. - Ensures that it is correctly identified as an internal feature. #### Rationale: With this change, the Unstable Book will now state: > *"This feature has no tracking issue and is therefore likely internal to the compiler, not being intended for general use."* Closes **#76249**. 🚀🦀
2025-02-24remove uses of rustc_intrinsic_must_be_overridden from standard libraryRalf Jung-1429/+356
2025-02-24Added into_value const function to ControlFlow<T, T>Madhav Madhusoodanan-0/+21
Fixed issue with usage of generics and moved feature gate to crate root Removed const tag Fixed alphabetical ordering of feature gate, added same to doctest Removed crate-level declaration of feature gate control_flow_into_value Used const_precise_live_drops to constify into_value without issue of a drop
2025-02-23Rollup merge of #137483 - bend-n:😅, r=NoratriebTrevor Gross-33/+33
rename sub_ptr to offset_from_unsigned i also made `byte_sub_ptr` `byte_offset_from_unsigned` fixes #137121 tracking issue #95892
2025-02-23Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35Trevor Gross-112/+85
intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic LLVM has three intrinsics here that all do the same thing (when used in the default FP environment). There's no reason Rust needs to copy that historically-grown mess -- let's just have one intrinsic and leave it up to the LLVM backend to decide how to lower that. Suggested by `@hanna-kruppe` in https://github.com/rust-lang/rust/issues/136459; Cc `@tgross35` try-job: test-various
2025-02-23rename sub_ptr 😅bendn-33/+33
2025-02-23Fix documentation for unstable sortyukang-15/+33
2025-02-23Stabilize `core::str::from_utf8_mut`Waffle Lapkin-2/+2
2025-02-23Auto merge of #137237 - cuviper:stage0, r=Mark-Simulacrumbors-150/+32
Master bootstrap update https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday r? `@Mark-Simulacrum`
2025-02-23add stdarch compatibility hackRalf Jung-0/+12
2025-02-23Rollup merge of #137383 - folkertdev:stabilize-unsigned-is-multiple-of, ↵Matthias Krüger-2/+2
r=Noratrieb stabilize `unsigned_is_multiple_of` tracking issue: https://github.com/rust-lang/rust/issues/128101 fcp completed in: https://github.com/rust-lang/rust/issues/128101#issuecomment-2674880635 ### Public API A version of this for all the unsigned types ```rust fn is_multiple_of(lhs: u64, rhs: u64) -> bool { match rhs { // prevent division by zero 0 => lhs == 0, _ => lhs % rhs == 0, } } ```
2025-02-23Rollup merge of #137121 - bend-n:master, r=NoratriebMatthias Krüger-20/+13
stabilize `(const_)ptr_sub_ptr` Tracking issue: #95892 Closes #95892 FCP Completed: https://github.com/rust-lang/rust/issues/95892#issuecomment-2561139730 r? ````@Noratrieb````
2025-02-22Stabilise c_str_moduleltdk-1/+1
2025-02-22make the new intrinsics safeRalf Jung-8/+8
2025-02-22Rollup merge of #136910 - okaneco:sig_ones, r=thomccMatthias Krüger-0/+156
Implement feature `isolate_most_least_significant_one` for integer types Accepted ACP - https://github.com/rust-lang/libs-team/issues/467 Tracking issue - #136909 Implement ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and `NonZero` integers. Add function `isolate_most_significant_one` Add function `isolate_least_significant_one` --- This PR adds the following impls ```rust impl {u8, u16, u32, u64, u128, usize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl {i8, i16, i32, i64, i128, isize} { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } impl NonZeroT { const fn isolate_most_significant_one(self) -> Self; const fn isolate_least_significant_one(self) -> Self; } ``` Example behavior ```rust assert_eq!(u8::isolate_most_significant_one(0b01100100), 0b01000000); assert_eq!(u8::isolate_least_significant_one(0b01100100), 0b00000100); ```
2025-02-22Rollup merge of #137207 - petertodd:2025-add-track-caller-to-duration-div, ↵Matthias Krüger-0/+2
r=jhpratt Add #[track_caller] to Duration Div impl Previously the location of the divide-by-zero error condition would be attributed to the code in the rust standard library, eg: thread 'main' panicked at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/time.rs:1172:31: divide by zero error when dividing duration by scalar With #[track_caller] the error is correctly attributed to the callee.
2025-02-21Rollup merge of #136609 - mammothbane:master, r=scottmcmMatthias Krüger-0/+60
libcore/net: `IpAddr::as_octets()` [ACP](https://github.com/rust-lang/libs-team/issues/535) [Tracking issue](https://github.com/rust-lang/rust/issues/137259) Adds `const` `core::net::IpAddr{,v4,v6}::as_octets()` methods to provide reference access to IP address contents. The concrete usecase for me is allowing the `IpAddr` to provide an extended lifetime in contexts that want a `&[u8]`: ```rust trait AddrSlice { fn addr_slice(&self) -> &[u8]; } impl AddrSlice for IpAddrV4 { fn addr_slice(&self) -> &[u8] { // self.octets() doesn't help us here, because we can't return a reference to the owned array. // Instead we want the IpAddrV4 to continue owning the memory: self.as_octets() } } ``` (Notably, in this case we can't parameterize `AddrSlice` by a `const N: usize` (such that `fn addr_slice(&self) -> [u8; N]`) and maintain object-safety.)
2025-02-21Rollup merge of #136148 - kpreid:type-str, r=joboetMatthias Krüger-3/+17
Optionally add type names to `TypeId`s. This feature is intended to provide expensive but thorough help for developers who have an unexpected `TypeId` value and need to determine what type it actually is. It causes `impl Debug for TypeId` to print the type name in addition to the opaque ID hash, and in order to do so, adds a name field to `TypeId`. The cost of this is the increased size of `TypeId` and the need to store type names in the binary; therefore, it is an optional feature. It does not expose any new public API, only change the `Debug` implementation. It may be enabled via `cargo -Zbuild-std -Zbuild-std-features=debug_typeid`. (Note that `-Zbuild-std-features` disables default features which you may wish to reenable in addition; see <https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features>.) Example usage and output: ``` fn main() { use std::any::{Any, TypeId}; dbg!(TypeId::of::<usize>(), drop::<usize>.type_id()); } ``` ``` TypeId::of::<usize>() = TypeId(0x763d199bccd319899208909ed1a860c6 = usize) drop::<usize>.type_id() = TypeId(0xe6a34bd13f8c92dd47806da07b8cca9a = core::mem::drop<usize>) ``` Also added feature declarations for the existing `debug_refcell` feature so it is usable from the `rust.std-features` option of `config.toml`. Related issues: * #68379 * #61533
2025-02-21Stabilize `unbounded_shifts`Connor Horman-8/+8
2025-02-21stabilize `unsigned_is_multiple_of`Folkert de Vries-2/+2
2025-02-21Do not use CString in the examples of CStr.Marijn Schouten-36/+37
Fixes #83999.
2025-02-20Rollup merge of #134340 - Urgau:stabilize-num_midpoint_signed, r=scottmcmJubilee-4/+4
Stabilize `num_midpoint_signed` feature This PR proposes that we stabilize the signed variants of [`iN::midpoint`](https://github.com/rust-lang/rust/issues/110840#issue-1684506201), the operation is equivalent to doing `(a + b) / 2` in a sufficiently large number. The stabilized API surface would be: ```rust /// Calculates the middle point of `self` and `rhs`. /// /// `midpoint(a, b)` is `(a + b) / 2` as if it were performed in a /// sufficiently-large signed integer type. This implies that the result is /// always rounded towards zero and that no overflow will ever occur. impl i{8,16,32,64,128,size} { pub const fn midpoint(self, rhs: Self) -> Self; } ``` T-libs-api previously stabilized the unsigned (and float) variants in #131784, the signed variants were left out because of the rounding that should be used in case of negative midpoint. This stabilization proposal proposes that we round towards zero because: - it makes the obvious `(a + b) / 2` in a sufficiently-large number always true - using another rounding for the positive result would be inconsistent with the unsigned variants - it makes `midpoint(-a, -b)` == `-midpoint(a, b)` always true - it is consistent with `midpoint(a as f64, b as f64) as i64` - it makes it possible to always suggest `midpoint` as a replacement for `(a + b) / 2` expressions *(which we may want to do as a future work given the 21.2k hits on [GitHub Search](https://github.com/search?q=lang%3Arust+%2F%5C%28%5Ba-zA-Z_%5D*+%5C%2B+%5Ba-zA-Z_%5D*%5C%29+%5C%2F+2%2F&type=code&p=1))* `@scottmcm` mentioned a drawback in https://github.com/rust-lang/rust/pull/132191#issuecomment-2439891200: > I'm torn, because rounding towards zero makes it "wider" than other values, which `>> 1` avoids -- `(a + b) >> 1` has the nice behaviour that `midpoint(a, b) + 2 == midpoint(a + 2, b + 2)`. > > But I guess overall sticking with `(a + b) / 2` makes sense as well, and I do like the negation property 🤷 Which I think is outweigh by the advantages cited above. Closes #110840 cc `@rust-lang/libs-api` cc `@scottmcm` r? `@dtolnay`
2025-02-20Auto merge of #136771 - scottmcm:poke-slice-iter-next, r=joboetbors-6/+29
Simplify `slice::Iter::next` enough that it inlines Inspired by this zulip conversation: <https://rust-lang.zulipchat.com/#narrow/channel/189540-t-compiler.2Fwg-mir-opt/topic/Feedback.20on.20a.20MIR.20optimization.20idea/near/498579990> ~~Draft for now because it needs #136735 to get the codegen tests to pass.~~
2025-02-20Implement 'PartialEq<{&Self, CString, Cow<Self>}>' for 'CStr'; Implement ↵Gabriel Bjørnager Jensen-0/+14
'PartialEq<{CStr, &CStr, Cow<CStr>}>' for 'CString'; Implement 'PartialEq<{CStr, &CStr, CString}>' for 'Cow<CStr>';
2025-02-20Guarantee behavior of transmuting Option::<T>::None subject to NPOJoshua Liebow-Feeser-14/+16
2025-02-20Implement feature `isolate_most_least_significant_one` for integer typesokaneco-0/+156
Implement accepted ACP for functions that isolate the most significant set bit and least significant set bit on unsigned, signed, and NonZero integers. Add function `isolate_most_significant_one` Add function `isolate_least_significant_one` Add tests
2025-02-19add `IntoBounds::intersect` and `RangeBounds::is_empty`Peter Jaszkowiak-5/+135
2025-02-20Auto merge of #137295 - matthiaskrgr:rollup-tdu3t39, r=matthiaskrgrbors-18/+7
Rollup of 9 pull requests Successful merges: - #135296 (interpret: adjust vtable validity check for higher-ranked types) - #137106 (Add customized compare for Link in rustdoc) - #137253 (Restrict `bevy_ecs` `ParamSet` hack) - #137262 (Make fewer crates depend on `rustc_ast_ir`) - #137263 (Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages) - #137266 (MIR visitor tweaks) - #137269 (Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions) - #137277 (stabilize `inherent_str_constructors`) - #137281 (Tweak "expected ident" parse error to avoid talking about doc comments) r? `@ghost` `@rustbot` modify labels: rollup