about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-08-28Improve `isqrt` tests and add benchmarksChai T. Rex-32/+313
* Choose test inputs more thoroughly and systematically. * Check that `isqrt` and `checked_isqrt` have equivalent results for signed types, either equivalent numerically or equivalent as a panic and a `None`. * Check that `isqrt` has numerically-equivalent results for unsigned types and their `NonZero` counterparts. * Reuse `ilog10` benchmarks, plus benchmarks that use a uniform distribution.
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-28Enable some ilog2 tests as wellBen Kimock-13/+5
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-659/+649
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-659/+649
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.
2024-08-25Rollup merge of #129487 - ↵Matthias Krüger-0/+6
GrigorenkoPV:repr_transparent_external_private_fields, r=compiler-errors repr_transparent_external_private_fields: special-case some std types Fixes #129470 ```@rustbot``` label +A-lint +L-repr_transparent_external_private_fields
2024-08-25ub_checks intrinsics: fall back to cfg(ub_checks)Ralf Jung-2/+3
2024-08-25Auto merge of #129521 - matthiaskrgr:rollup-uigv77m, r=matthiaskrgrbors-2/+28
Rollup of 9 pull requests Successful merges: - #128596 (stabilize const_fn_floating_point_arithmetic) - #129199 (make writes_through_immutable_pointer a hard error) - #129246 (Retroactively feature gate `ConstArgKind::Path`) - #129290 (Pin `cc` to 1.0.105) - #129323 (Implement `ptr::fn_addr_eq`) - #129500 (remove invalid `TyCompat` relation for effects) - #129501 (panicking: improve hint for Miri's RUST_BACKTRACE behavior) - #129505 (interpret: ImmTy: tighten sanity checks in offset logic) - #129510 (Fix `elided_named_lifetimes` in code) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-24Rollup merge of #129449 - coolreader18:pin-as_deref_mut-signature, r=dtolnayTrevor Gross-70/+73
Put Pin::as_deref_mut in impl Pin<Ptr> / rearrange Pin methods Tracking issue: #86918 Based on the suggestion in https://github.com/rust-lang/rust/issues/86918#issuecomment-2189367582 > Some advantages: > > * Synergy with the existing `as_ref` and `as_mut` signatures (stable since Rust 1.33) > > * Lifetime elision reduces noise in the signature > > * Turbofish less verbose: `Pin::<&mut T>::as_deref_mut` vs `Pin::<&mut Pin<&mut T>>::as_deref_mut` The comment seemed to imply that `Pin::as_ref` and `Pin::as_mut` already share an impl block, which they don't. So, I rearranged it so that they do, and we can see which looks better in the docs. <details><summary><b>Docs screenshots</b></summary> Current nightly: ![image](https://github.com/user-attachments/assets/b432cb82-8f4b-48ae-bafc-2fe49d0ad48c) `Pin::as_deref_mut` moved into the same block as `as_mut`: ![image](https://github.com/user-attachments/assets/f9b35722-6a88-4465-ad1c-28d8e91902ac) `Pin::as_ref`, `as_mut`, and `as_deref_mut` all in the same block: ![image](https://github.com/user-attachments/assets/9a1b2bf0-70a6-4751-b13f-390f1d575244) </details> I think I like the last one the most; obviously I'm biased since I'm the one who rearranged it, but it doesn't make sense to me to have `as_ref` methods split up by an `into_inner` method. r? dtolnay
2024-08-24Rollup merge of #128735 - jieyouxu:pr-120176-revive, r=cjgillotTrevor Gross-0/+1
Add a special case for `CStr`/`CString` in the `improper_ctypes` lint Revives #120176. Just needed to bless a test and fix an argument, but seemed reasonable to me otherwise. Instead of saying to "consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct", we now tell users to "Use `*const ffi::c_char` instead, and pass the value from `CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`. The suggestion is not made for `&mut CString` or `*mut CString`. r? ``````@cjgillot`````` (since you were the reviewer of the original PR #120176, but feel free to reroll)
2024-08-24rustdoc: clean up tuple <-> primitive conversion docsMichael Howell-15/+21
This adds a minor missing feature to `fake_variadic`, so that it can render `impl From<(T,)> for [T; 1]` correctly.
2024-08-24Rollup merge of #129500 - fee1-dead-contrib:fxrel, r=compiler-errorsMatthias Krüger-1/+0
remove invalid `TyCompat` relation for effects if the current impl uses `Maybe` (`impl const`), the parent impl must use `Maybe` (`impl const`) as well. I'd like to rename `TyCompat` to `Sub` which is probably clearer. But it would conflict with my other PR. r? ``@rust-lang/project-const-traits``
2024-08-24Rollup merge of #129323 - Urgau:ptr_fn_addr_eq, r=Mark-SimulacrumMatthias Krüger-0/+27
Implement `ptr::fn_addr_eq` This PR implements https://github.com/rust-lang/libs-team/issues/323: `ptr::fn_addr_eq`. r? libs
2024-08-24Rollup merge of #128596 - RalfJung:const_fn_floating_point_arithmetic, ↵Matthias Krüger-1/+1
r=nnethercote stabilize const_fn_floating_point_arithmetic Part of https://github.com/rust-lang/rust/issues/128288 Fixes https://github.com/rust-lang/rust/issues/57241 The existing test `tests/ui/consts/const_let_eq_float.rs` ([link](https://github.com/RalfJung/rust/blob/const_fn_floating_point_arithmetic/tests/ui/consts/const_let_eq_float.rs)) covers the basics, and also Miri has extensive tests covering the interpreter's float machinery. Also, that machinery can already be used on stable inside `const`/`static` initializers, just not inside `const fn`. This was explicitly called out in https://github.com/rust-lang/rfcs/pull/3514 so in a sense t-lang just recently already FCP'd this, but let's hear from them whether they want another FCP for the stabilization here or whether that was covered by the FCP for the RFC. Cc ``@rust-lang/lang`` ### Open items - [x] Update the Reference: https://github.com/rust-lang/reference/pull/1566
2024-08-24New `#[rustc_pub_transparent]` attributePavel Grigorenko-0/+6
2024-08-24remove invalid `TyCompat` relation for effectsDeadbeef-1/+0
2024-08-24Pass `fmt::Arguments` by reference to `PanicInfo` and `PanicMessage`StackOverflowExcept1on-8/+8