about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2024-09-01Rollup merge of #128495 - joboet:more_memcmp, r=scottmcmMatthias Krüger-10/+33
core: use `compare_bytes` for more slice element types `bool`, `NonZero<u8>`, `Option<NonZero<u8>>` and `ascii::Char` can be compared the same way as `u8`.
2024-08-31Auto merge of #129831 - matthiaskrgr:rollup-befq6zx, r=matthiaskrgrbors-1/+1
Rollup of 11 pull requests Successful merges: - #128523 (Add release notes for 1.81.0) - #129605 (Add missing `needs-llvm-components` directives for run-make tests that need target-specific codegen) - #129650 (Clean up `library/profiler_builtins/build.rs`) - #129651 (skip stage 0 target check if `BOOTSTRAP_SKIP_TARGET_SANITY` is set) - #129684 (Enable Miri to pass pointers through FFI) - #129762 (Update the `wasm-component-ld` binary dependency) - #129782 (couple more crash tests) - #129816 (tidy: say which feature gate has a stability issue mismatch) - #129818 (make the const-unstable-in-stable error more clear) - #129824 (Fix code examples buttons not appearing on click on mobile) - #129826 (library: Fix typo in `core::mem`) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-31Remove stray dot in `std::char::from_u32_unchecked` documentationEduardo Sánchez Muñoz-1/+1
2024-08-31Update mod.rsAlcaro-1/+1
This typo looks unnecessary
2024-08-31Rollup merge of #129730 - RalfJung:float-arithmetic, r=workingjubileeMatthias Krüger-44/+48
f32 docs: define 'arithmetic' operations r? ````@workingjubilee```` Fixes https://github.com/rust-lang/rust/issues/129699
2024-08-31Fix `elided_named_lifetimes` in codePavel Grigorenko-10/+10
2024-08-31Improve documentation for <integer>::from_str_radixKappa322-26/+53
Two improvements to the documentation: - Document `-` as a valid character for signed integer destinations - Make the documentation even more clear that extra whitespace and non-digit characters is invalid. Many other languages, e.g. c++, are very permissive in string to integer routines and simply try to consume as much as they can, ignoring the rest. This is trying to make the transition for developers who are used to the conversion semantics in these languages a bit easier.
2024-08-31Fixed more typos in library/coreranger-ross-5/+5
2024-08-30enumerate the two parts of the NaN rulesRalf Jung-20/+21
2024-08-30add hyphen in floating-pointRalf Jung-12/+12
2024-08-29Rollup merge of #128166 - ChaiTRex:isqrt, r=tgross35Guillaume Gomez-35/+371
Improved `checked_isqrt` and `isqrt` methods ### Improved tests of `isqrt` and `checked_isqrt` implementations * Inputs chosen more thoroughly and systematically. * Checks that `isqrt` and `checked_isqrt` have equivalent results for signed types, either equivalent numerically or equivalent as a panic and a `None`. * Checks that `isqrt` has numerically-equivalent results for unsigned types and their `NonZero` counterparts. ### Added benchmarks for `isqrt` implementations ### Greatly sped up `checked_isqrt` and `isqrt` methods * Uses a lookup table for 8-bit integers and then the Karatsuba square root algorithm for larger integers. * Includes optimization hints that give the compiler the exact numeric range of results. ### Feature tracking issue `isqrt` is an unstable feature tracked at #116226. <details><summary>Benchmarked improvements</summary> ### Command used to benchmark ./x bench library/core -- int_sqrt ### Before benchmarks: num::int_sqrt::i128::isqrt 439591.65/iter +/- 6652.70 num::int_sqrt::i16::isqrt 5302.97/iter +/- 160.93 num::int_sqrt::i32::isqrt 62999.11/iter +/- 2022.05 num::int_sqrt::i64::isqrt 125248.81/iter +/- 1674.43 num::int_sqrt::i8::isqrt 123.56/iter +/- 1.87 num::int_sqrt::isize::isqrt 125356.56/iter +/- 1017.03 num::int_sqrt::non_zero_u128::isqrt 437443.75/iter +/- 3535.43 num::int_sqrt::non_zero_u16::isqrt 8604.58/iter +/- 94.76 num::int_sqrt::non_zero_u32::isqrt 62933.33/iter +/- 517.30 num::int_sqrt::non_zero_u64::isqrt 125076.38/iter +/- 11340.61 num::int_sqrt::non_zero_u8::isqrt 221.51/iter +/- 1.58 num::int_sqrt::non_zero_usize::isqrt 136005.21/iter +/- 2020.35 num::int_sqrt::u128::isqrt 439014.55/iter +/- 3920.45 num::int_sqrt::u16::isqrt 8575.08/iter +/- 148.06 num::int_sqrt::u32::isqrt 63008.89/iter +/- 803.67 num::int_sqrt::u64::isqrt 125088.09/iter +/- 879.29 num::int_sqrt::u8::isqrt 230.18/iter +/- 2.04 num::int_sqrt::usize::isqrt 125237.51/iter +/- 4747.83 ### After benchmarks: num::int_sqrt::i128::isqrt 105184.89/iter +/- 1171.38 num::int_sqrt::i16::isqrt 1910.26/iter +/- 78.50 num::int_sqrt::i32::isqrt 34260.34/iter +/- 960.84 num::int_sqrt::i64::isqrt 45939.19/iter +/- 2525.65 num::int_sqrt::i8::isqrt 22.87/iter +/- 0.45 num::int_sqrt::isize::isqrt 45884.17/iter +/- 595.49 num::int_sqrt::non_zero_u128::isqrt 106344.27/iter +/- 780.99 num::int_sqrt::non_zero_u16::isqrt 2790.19/iter +/- 53.43 num::int_sqrt::non_zero_u32::isqrt 33613.99/iter +/- 362.96 num::int_sqrt::non_zero_u64::isqrt 46235.42/iter +/- 429.69 num::int_sqrt::non_zero_u8::isqrt 31.78/iter +/- 0.75 num::int_sqrt::non_zero_usize::isqrt 46208.75/iter +/- 375.27 num::int_sqrt::u128::isqrt 106385.94/iter +/- 1649.95 num::int_sqrt::u16::isqrt 2747.69/iter +/- 28.72 num::int_sqrt::u32::isqrt 33627.09/iter +/- 475.68 num::int_sqrt::u64::isqrt 46182.29/iter +/- 311.16 num::int_sqrt::u8::isqrt 33.10/iter +/- 0.30 num::int_sqrt::usize::isqrt 46165.00/iter +/- 388.41 </details> Tracking Issue for {u8,i8,...}::isqrt #116226 try-job: test-various
2024-08-29Use simpler branchy swap logic in tiny merge sortLukas Bergdoll-42/+13
Avoids the code duplication issue and results in smaller binary size, which after all is the purpose of the feature.
2024-08-29f32 docs: define 'arithmetic' operationsRalf Jung-16/+19
2024-08-28Speed up `checked_isqrt` and `isqrt` methodsChai T. Rex-35/+371
* Use a lookup table for 8-bit integers and the Karatsuba square root algorithm for larger integers. * Include optimization hints that give the compiler the exact numeric range of results.
2024-08-28fmt-debug optionKornel-0/+4
Allows disabling `fmt::Debug` derive and debug formatting.
2024-08-28Auto merge of #129691 - matthiaskrgr:rollup-owlcr3m, r=matthiaskrgrbors-76/+82
Rollup of 11 pull requests Successful merges: - #129421 (add repr to the allowlist for naked functions) - #129480 (docs: correct panic conditions for rem_euclid and similar functions) - #129551 (ub_checks intrinsics: fall back to cfg(ub_checks)) - #129608 (const-eval: do not make UbChecks behavior depend on current crate's flags) - #129613 (interpret: do not make const-eval query result depend on tcx.sess) - #129641 (rustdoc: fix missing resource suffix on `crates.js`) - #129657 (Rename `BikeshedIntrinsicFrom` to `TransmuteFrom`) - #129666 (interpret: add missing alignment check in raw_eq) - #129667 (Rustc driver cleanup) - #129668 (Fix Pin::set bounds regression) - #129686 (coverage: Rename `CodeRegion` to `SourceRegion`) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-28Rollup merge of #129668 - coolreader18:fix-pin-set-regr, r=dtolnayMatthias Krüger-9/+12
Fix Pin::set bounds regression Fixes #129601 Fixes the regression from #129449, where changing the bounds of the impl block containing `Pin::set` changed the method resolution behavior. ```rust struct A; impl A { fn set(&self) {} } let a: Pin<&A>; a.set(); // before: // - checks <impl<Ptr: DerefMut> Pin<Ptr>>::set(): `&A` doesn't impl `DerefMut` // - autorefs -> &A: resolves to A::set() // now: // - checks <impl<Ptr: Deref> Pin<Ptr>>::set(): `&A` impls `Deref`! resolves to Pin::set() // - check method bounds: `&A` doesn't impl DerefMut: error ``` r? `@dtolnay`
2024-08-28Rollup merge of #129657 - jswrenn:transmute-name, r=compiler-errorsMatthias Krüger-57/+54
Rename `BikeshedIntrinsicFrom` to `TransmuteFrom` As our implementation of MCP411 nears completion and we begin to solicit testing, it's no longer reasonable to expect testers to type or remember `BikeshedIntrinsicFrom`. The name degrades the ease-of-reading of documentation, and the overall experience of using compiler safe transmute. Tentatively, we'll instead adopt `TransmuteFrom`. This name seems to be the one most likely to be stabilized, after discussion on Zulip [1]. We may want to revisit the ordering of `Src` and `Dst` before stabilization, at which point we'd likely consider `TransmuteInto` or `Transmute`. [1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20should.20.60BikeshedIntrinsicFrom.60.20be.20named.3F Tracking Issue: https://github.com/rust-lang/rust/issues/99571 r​? `@compiler-errors`
2024-08-28Rollup merge of #129551 - RalfJung:ub-checks-fallback, r=saethlinMatthias Krüger-2/+3
ub_checks intrinsics: fall back to cfg(ub_checks) Not sure why the fallback body uses `debug_assertions`, probably a leftover from when `cfg!(ub_checks)` did not exist yet? r? `@saethlin`
2024-08-28Rollup merge of #129480 - lolbinarycat:euclid-docs, r=joboetMatthias Krüger-8/+13
docs: correct panic conditions for rem_euclid and similar functions fixes https://github.com/rust-lang/rust/issues/128857 also fixes the documentation for functions behind the `int_roundings` feature (#88581)
2024-08-28Auto merge of #129589 - saethlin:improve-panic-immediate-abort, r=tgross35bors-3/+5
Tweak some attributes to improve panic_immediate_abort This is similar to https://github.com/rust-lang/rust/pull/117332; I did the same approach as before where I build a really big project with `-Zbuild-std -Zbuild-std-features=panic_immediate_abort` and grep its symbols for things that look panic-related.
2024-08-28addr_of on places derived from raw pointers should preserve permissionsRalf Jung-3/+7
2024-08-27Fix Pin::set bounds regressionNoa-9/+12
2024-08-27Rollup merge of #129652 - RalfJung:ptr-to-ref, r=traviscrossMatthias Krüger-23/+15
fix Pointer to reference conversion docs The aliasing rules documented in https://github.com/rust-lang/rust/pull/128157 are wrong, this fixes them.
2024-08-27Rollup merge of #129645 - beetrees:fix-float-docs, r=tgross35Matthias Krüger-8/+6
Fix typos in floating-point primitive type docs Fixes a few typos. Also reflows the text of a couple of paragraphs in the source code to the standard line width to make the source easier to read (will have no effect on the rendered documentation).
2024-08-27safe transmute: Rename `BikeshedIntrinsicFrom` to `TransmuteFrom`Jack Wrenn-57/+54
As our implementation of MCP411 nears completion and we begin to solicit testing, it's no longer reasonable to expect testers to type or remember `BikeshedIntrinsicFrom`. The name degrades the ease-of-reading of documentation, and the overall experience of using compiler safe transmute. Tentatively, we'll instead adopt `TransmuteFrom`. This name seems to be the one most likely to be stabilized, after discussion on Zulip [1]. We may want to revisit the ordering of `Src` and `Dst` before stabilization, at which point we'd likely consider `TransmuteInto` or `Transmute`. [1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20should.20.60BikeshedIntrinsicFrom.60.20be.20named.3F
2024-08-27fix Pointer to reference conversion docsRalf Jung-23/+15
2024-08-27clarify that addr_of creates read-only pointersRalf Jung-0/+4
2024-08-27Use last swap optimization in bubblesortLukas Bergdoll-9/+18
2024-08-27Rollup merge of #129559 - RalfJung:float-nan-semantics, r=thomccTrevor Gross-36/+130
float types: document NaN bit pattern guarantees Part of https://github.com/rust-lang/rust/issues/128288: document the guarantees we make for NaN bit patterns. Cc ``@tgross35``
2024-08-27Rollup merge of #128731 - RalfJung:simd-shuffle-vector, r=workingjubileeTrevor Gross-1/+1
simd_shuffle intrinsic: allow argument to be passed as vector See https://github.com/rust-lang/rust/issues/128738 for context. I'd like to get rid of [this hack](https://github.com/rust-lang/rust/blob/6c0b89dfac65be9a5be12f938f23098ebc36c635/compiler/rustc_codegen_ssa/src/mir/block.rs#L922-L935). https://github.com/rust-lang/rust/pull/128537 almost lets us do that since constant SIMD vectors will then be passed as immediate arguments. However, simd_shuffle for some reason actually takes an *array* as argument, not a vector, so the hack is still required to ensure that the array becomes an immediate (which then later stages of codegen convert into a vector, as that's what LLVM needs). This PR prepares simd_shuffle to also support a vector as the `idx` argument. Once this lands, stdarch can hopefully be updated to pass `idx` as a vector, and then support for arrays can be removed, which finally lets us get rid of that hack.
2024-08-27Reflow a couple of paragraphs in floating-point primitive docsbeetrees-6/+4
2024-08-27Fix typos in floating-point primitive type docsbeetrees-3/+3
2024-08-27Rollup merge of #129032 - jswrenn:transmute-method, r=compiler-errorsMatthias Krüger-21/+350
Document & implement the transmutation modeled by `BikeshedIntrinsicFrom` Documents that `BikeshedIntrinsicFrom` models transmute-via-union, which is slightly more expressive than the transmute-via-cast implemented by `transmute_copy`. Additionally, we provide an implementation of transmute-via-union as a method on the `BikeshedIntrinsicFrom` trait with additional documentation on the boundary between trait invariants and caller obligations. Whether or not transmute-via-union is the right kind of transmute to model remains up for discussion [1]. Regardless, it seems wise to document the present behavior. [1] https://rust-lang.zulipchat.com/#narrow/stream/216762-project-safe-transmute/topic/What.20'kind'.20of.20transmute.20to.20model.3F/near/426331967 Tracking Issue: https://github.com/rust-lang/rust/issues/99571 r? `@compiler-errors` cc `@scottmcm,` `@Lokathor`
2024-08-27Rollup merge of #128157 - lolbinarycat:unify-ptr-ref-docs, r=cuviperMatthias Krüger-210/+73
deduplicate and clarify rules for converting pointers to references part of #124669
2024-08-26Apply suggestions from code reviewJosh Stone-9/+9
2024-08-26Rollup merge of #129592 - saethlin:core-cfg-test, r=tgross35Matthias Krüger-3/+0
Remove cfg(test) from library/core The diff here is very small with the ignore whitespace option. `core` doesn't/can't have unit tests. All of its tests are just modules under `tests/`, so it has no use for `cfg(test)`, because the entire contents of `library/core/src` are only ever compiled with that cfg off, and the entire contents of `library/core/tests` are only ever compiled with that cfg on. You can tell this is what's happening because we had `#[cfg(test)]` on a module declaration that has no source file. I also deleted the extra `mod tests {` layer of nesting; there's no need to mention again in the module path that this is a module of tests. This exposes a name collision between the `u128` module of tests and `core::u128`. Fixed that by using `<u128>::MAX` like is done in the `check!` macro, which is what avoids this name ambiguity for the other types.
2024-08-26Rollup merge of #129539 - oconnor663:poll_link, r=tgross35Matthias Krüger-0/+2
link to Future::poll from the Poll docs The most important thing about Poll is that Future::poll returns it, but previously the docs didn't emphasize this.
2024-08-26Rollup merge of #129377 - chorman0773:unbounded-shifts-impl, r=scottmcmMatthias Krüger-0/+118
Add implementations for `unbounded_shl`/`unbounded_shr` Tracking Issue: https://github.com/rust-lang/rust/issues/129375 This implements `unbounded_shl` and `unbounded_shr` under the feature gate `unbounded_shifts`
2024-08-26move per-target NaN info into a tableRalf Jung-7/+14
2024-08-26float types: document NaN bit pattern guaranteesRalf Jung-36/+123
2024-08-26Convert cfg blocks to cfg_ifLukas Bergdoll-79/+68
2024-08-26Reduce code duplication by moving partition_lomuto_branchless_simple into ↵Lukas Bergdoll-79/+39
quicksort module
2024-08-26Auto merge of #129595 - matthiaskrgr:rollup-4udn7nn, r=matthiaskrgrbors-15/+21
Rollup of 9 pull requests Successful merges: - #129288 (Use subtyping for `UnsafeFnPointer` coercion, too) - #129405 (Fixing span manipulation and indentation of the suggestion introduced by #126187) - #129518 (gitignore: ignore ICE reports regardless of directory) - #129519 (Remove redundant flags from `lower_ty_common` that can be inferred from the HIR) - #129525 (rustdoc: clean up tuple <-> primitive conversion docs) - #129526 (Use `FxHasher` on new solver unconditionally) - #129544 (Removes dead code from the compiler) - #129553 (add back test for stable-const-can-only-call-stable-const) - #129590 (Avoid taking reference of &TyKind) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-25Remove cfg(test) from library/coreBen Kimock-3/+0
2024-08-26Rollup merge of #129525 - notriddle:notriddle/fake-variadic-tuple-array, ↵Matthias Krüger-15/+21
r=GuillaumeGomez rustdoc: clean up tuple <-> primitive conversion docs This adds a minor missing feature to `fake_variadic`, so that it can render `impl From<(T,)> for [T; 1]` correctly.
2024-08-25Auto merge of #129488 - saethlin:alignment-precondition, r=workingjubileebors-2/+0
Enable Alignment::new_unchecked precondition check Similar to what happened with https://github.com/rust-lang/rust/pull/126556, I think this has become palatable since https://github.com/rust-lang/rust/pull/126793.
2024-08-25Tweak some attributes to improve panic_immediate_abortBen Kimock-3/+5
2024-08-25Add binary-size optimized variants for stable and unstable sort as well as ↵Lukas Bergdoll-33/+284
select_nth_unstable - Stable sort uses a simple merge-sort that re-uses the existing - rather gnarly - merge function. - Unstable sort jumps directly to the branchless heapsort fallback. - select_nth_unstable jumps directly to the median_of_medians fallback, which is augmented with a custom tiny smallsort and partition impl. Some code is duplicated but de-duplication would bring it's own problems. For example `swap_if_less` is critical for performance, if the sorting networks don't inline it perf drops drastically, however `#[inline(always)]` is also a poor fit, if the provided comparison function is huge, it gives the compiler an out to only instantiate `swap_if_less` once and call it. Another aspect that would suffer when making `swap_if_less` pub, is having to cfg out dozens of functions in in smallsort module.
2024-08-25link to Future::poll from the Poll docsJack O'Connor-0/+2
The most important thing about Poll is that Future::poll returns it, but previously the docs didn't emphasize this.