about summary refs log tree commit diff
path: root/library/core/src
AgeCommit message (Collapse)AuthorLines
2023-11-25Address review feedbackGary Guo-5/+11
2023-11-25Convert many `assert_unsafe_precondition` to `debug_assert_nounwind`Gary Guo-132/+98
2023-11-25Add `debug_assert_nounwind`Gary Guo-19/+54
2023-11-25Rollup merge of #117968 - Urgau:stabilize-ptr-addr-eq, r=dtolnayMichael Goulet-4/+5
Stabilize `ptr::addr_eq` This PR stabilize the `ptr_addr_eq` library feature, representing: ```rust // core::ptr pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool; ``` FCP has already started [on the tracking issue](https://github.com/rust-lang/rust/issues/116324#issuecomment-1813008697) and is waiting on the final period comment. Note: stabilizing this feature is somewhat of requirement for a new T-lang lint, cf. https://github.com/rust-lang/rust/pull/117758#issuecomment-1813183686.
2023-11-24Auto merge of #118138 - Nilstrieb:one-previous-error, r=WaffleLapkinbors-1/+1
Fixes error count display is different when there's only one error left Supersedes #114759 ### What did I do? I did the small change in `rustc_errors` by hand. Then I did the other changes in `/compiler` by hand, those were just find replace on `*.rs` in the workspace. The changes in run-make are find replace for `run-make` in the workspace. All other changes are blessed using `x test TEST --bless`. I blessed the tests that were blessed in #114759. ### how to review this nightmare ping bors with an `r+`. You should check that my logic is sound and maybe quickly scroll through the diff, but fully verifying it seems fairly hard to impossible. I did my best to do this correctly. Thank you `@adrianEffe` for bringing this up and your initial implementation. cc `@flip1995,` you said you want to do a subtree sync asap cc `@RalfJung` maybe you want to do a quick subtree sync afterwards as well for Miri r? `@WaffleLapkin`
2023-11-24remove the memcpy-on-equal-ptrs assumptionRalf Jung-3/+2
2023-11-24add `#[track_caller]` to improve panic locationsRyan Mehri-0/+26
2023-11-24implement strict_* operations for unsigned integer typesRyan Mehri-0/+394
2023-11-24implement strict_* operations for signed integer typesRyan Mehri-0/+557
2023-11-24Show number in error message even for one errorNilstrieb-1/+1
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24Rollup merge of #118238 - RalfJung:memcpy, r=Mark-SimulacrumMichael Goulet-1/+1
memcpy assumptions: update GCC link GCC now has this documented on an official website, not just in the bugtracker.
2023-11-24Auto merge of #118228 - Mark-Simulacrum:alloc-opt, r=scottmcmbors-1/+5
Indicate that multiplication in Layout::array cannot overflow Since https://github.com/rust-lang/rust/pull/113113, we have added a check that skips calling into the allocator at all if `capacity == 0`. The global, default allocator will not actually try to allocate though; it returns a dangling pointer explicitly. However, these two checks are not merged/deduplicated by LLVM and so we're comparing to zero twice whenever vectors are allocated/grown. Probably cheap, but also potentially expensive in code size and seems like an unfortunate miss. This removes that extra check by telling LLVM that the multiplication as part of Layout::array can't overflow, turning the original non-zero value into a zero value afterwards. In my checks locally this successfully drops the duplicate comparisons. See https://rust.godbolt.org/z/b6nPP9dcK for a code example. ```rust pub fn foo(elements: usize) -> Vec<u32> { Vec::with_capacity(elements) } ``` r? `@scottmcm` since you touched this in a32305a80fd1409b054e97836321bd0621b142fd - curious if you have thoughts on doing this / can confirm my model of this being correct.
2023-11-24memcpy assumptions: update GCC linkRalf Jung-1/+1
2023-11-24correct grammarKashiwa-1/+1
2023-11-24Auto merge of #118232 - matthiaskrgr:rollup-x8crvm0, r=matthiaskrgrbors-2/+6
Rollup of 6 pull requests Successful merges: - #116807 (Improve rewind documentation) - #117656 (Update windows-bindgen and define `INVALID_HANDLE_VALUE` ourselves) - #117940 (chore: remove unnecessary drop) - #118028 (Document behavior of `<dyn Any as Any>::type_id()`) - #118060 (Use an absolute path to the NUL device) - #118224 (Sort unstable items last in rustdoc, instead of first) r? `@ghost` `@rustbot` modify labels: rollup
2023-11-24Update comment for consistent context logic.Kashiwa-2/+2
2023-11-24also add is_empty to const raw slicesRalf Jung-3/+21
2023-11-24Rollup merge of #118028 - Jules-Bertholet:dyn-any-doc, r=thomccMatthias Krüger-0/+5
Document behavior of `<dyn Any as Any>::type_id()` See also #57893 `@rustbot` label A-docs T-libs
2023-11-24Rollup merge of #117940 - zhiqiangxu:remove_redundant_drop, r=thomccMatthias Krüger-2/+1
chore: remove unnecessary drop No need to manually drop since it's implicit.
2023-11-24Auto merge of #117722 - okaneco:binarysearch, r=thomccbors-9/+8
Refactor `binary_search_by` to use conditional moves Refactor the if/else checking on `cmp::Ordering` variants to a "branchless" reassignment of left and right. This change results in fewer branches and instructions. https://rust.godbolt.org/z/698eYffTx --- I saw consistent benchmark improvements locally. Performance of worst case seems about the same, maybe slightly faster for the L3 test. Current ``` slice::binary_search_l1 43.00ns/iter +/- 3.00ns slice::binary_search_l1_with_dups 25.00ns/iter +/- 0.00ns slice::binary_search_l1_worst_case 10.00ns/iter +/- 0.00ns slice::binary_search_l2 64.00ns/iter +/- 1.00ns slice::binary_search_l2_with_dups 42.00ns/iter +/- 0.00ns slice::binary_search_l2_worst_case 16.00ns/iter +/- 0.00ns slice::binary_search_l3 132.00ns/iter +/- 2.00ns slice::binary_search_l3_with_dups 108.00ns/iter +/- 2.00ns slice::binary_search_l3_worst_case 33.00ns/iter +/- 3.00ns ``` This PR ``` slice::binary_search_l1 21.00ns/iter +/- 0.00ns slice::binary_search_l1_with_dups 14.00ns/iter +/- 0.00ns slice::binary_search_l1_worst_case 9.00ns/iter +/- 0.00ns slice::binary_search_l2 34.00ns/iter +/- 0.00ns slice::binary_search_l2_with_dups 23.00ns/iter +/- 0.00ns slice::binary_search_l2_worst_case 16.00ns/iter +/- 0.00ns slice::binary_search_l3 92.00ns/iter +/- 3.00ns slice::binary_search_l3_with_dups 63.00ns/iter +/- 1.00ns slice::binary_search_l3_worst_case 29.00ns/iter +/- 0.00ns ```
2023-11-23Indicate that multiplication in Layout::array cannot overflowMark Rousskov-1/+5
This allows LLVM to optimize comparisons to zero before & after the multiplication into one, saving on code size and eliminating an (always true) branch from most Vec allocations.
2023-11-24add track_caller for arith opsbohan-0/+14
2023-11-22also make 'core_intrinsics' internalRalf Jung-0/+7
2023-11-22warn against using intrinsics that leave the scope of our memory modelRalf Jung-0/+10
2023-11-21Auto merge of #117619 - elomatreb:add-duration-abs-diff, r=thomccbors-0/+21
Add `Duration::abs_diff` This adds a `Duration::abs_diff` method analogous to the existing one on the primitive integers. ACP: https://github.com/rust-lang/libs-team/issues/291 Tracking Issue: https://github.com/rust-lang/rust/issues/117618
2023-11-18Auto merge of #117525 - GKFX:remove_option_payload_ptr, r=petrochenkovbors-11/+8
Remove option_payload_ptr; redundant to offset_of The `option_payload_ptr` intrinsic is no longer required as `offset_of` supports traversing enums (#114208). This PR removes it in order to dogfood offset_of (as suggested at https://github.com/rust-lang/rust/issues/106655#issuecomment-1790907626). However, it will not build until those changes reach beta (which I think is within the next 8 days?) so I've opened it as a draft.
2023-11-18Update based on petrochenkov's reviewGeorge Bateman-3/+4
2023-11-18Auto merge of #115412 - eswartz:docs/total_cmp-test-result-in-docs, r=scottmcmbors-6/+22
Expose tests for {f32,f64}.total_cmp in docs Expose tests for {f32,f64}.total_cmp in docs Uncomment the helpful `assert_eq!` line, which is stripped out completely in docs, and leaves the reader to mentally play through the algorithm, or go to the playground and add a println!, to see what the result will be. (If these tests are known to fail on some platforms, is there some mechanism to conditionalize this or escape the test so the `assert_eq!` source will be visible on the web? I am a newbie, which is why I was reading docs ;)
2023-11-18guarantee that char and u32 are ABI-compatibleRalf Jung-4/+5
2023-11-18Auto merge of #115249 - clarfonthey:alignment, r=scottmcmbors-1/+44
impl more traits for ptr::Alignment, add mask method Changes: * Adds `rustc_const_unstable` attributes where missing * Makes `log2` method const * Adds `mask` method * Implements `Default`, which is equivalent to `Alignment::MIN` No longer included in PR: * Removes indirection of `AlignmentEnum` type alias (this was intentional) * Implements `Display`, `Binary`, `Octal`, `LowerHex`, and `UpperHex` (should go through libs-api instead) * Controversially implements `LowerExp` and `UpperExp` using `p` instead of `e` to indicate a power of 2 (also should go through libs-api) Tracking issue for `ptr::Alignment`: #102070
2023-11-18impl more traits for ptr::Alignment, add mask methodltdk-1/+44
2023-11-18Auto merge of #117825 - fee1-dead-contrib:corefx, r=petrochenkovbors-0/+1
Reenable effects in libcore With #116670, #117531, and #117171, I think we would be comfortable with re-enabling the effects feature for more testing in libcore. r? `@oli-obk` cc `@fmease` cc #110395
2023-11-17Document behavior of `<dyn Any as Any>::type_id()`Jules Bertholet-0/+5
See also #57893
2023-11-17Rollup merge of #118006 - lcnr:discriminant-docs, r=compiler-errorsMatthias Krüger-4/+6
clarify `fn discriminant` guarantees: only free lifetimes may get erased cc https://github.com/rust-lang/rust/pull/104299/files#r1397082347 don't think this necessitates a backport by itself, but should imo be included if one were to exist. r? types
2023-11-17Rollup merge of #117549 - DaniPopes:more-copied, r=b-naberMatthias Krüger-2/+2
Use `copied` instead of manual `map`
2023-11-17Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naberMatthias Krüger-6/+0
Remove asmjs Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668). `asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-17Auto merge of #111922 - vaporoxx:feat-searcher, r=dtolnaybors-0/+4
feat: implement `DoubleEndedSearcher` for `CharArray[Ref]Searcher` This PR implements `DoubleEndedSearcher` for both `CharArraySearcher` and `CharArrayRefSearcher`. I'm not sure whether this was just overlooked or if there is a reason for it, but since it behaves exactly like `CharSliceSearcher`, I think the implementations should be appropriate.
2023-11-17Improve slice_group_by doc wordingNiklas Fiekas-6/+6
2023-11-17only free lifetimes may get erasedlcnr-4/+6
2023-11-17Rollup merge of #115476 - RalfJung:abi-compat-docs, r=Mark-SimulacrumMatthias Krüger-4/+113
document ABI compatibility I don't think we have any central place where we document our ABI compatibility rules, so let's create one. The `fn()` pointer type seems like a good place since ABI questions can only become relevant when invoking a function through a function pointer. This will likely need T-lang FCP.
2023-11-17linking in general has more pitfalls than just call ABIRalf Jung-2/+3
2023-11-16Remove option_payload_ptr; redundant to offset_ofGeorge Bateman-10/+6
2023-11-16Stabilize ptr_addr_eq library featureUrgau-4/+5
2023-11-15Re-format code with new rustfmtMark Rousskov-15/+12
2023-11-15Bump cfg(bootstrap)sMark Rousskov-26/+17
2023-11-15Substitute version placeholdersMark Rousskov-54/+54
2023-11-16remove unnecessary dropzhiqiangxu-2/+1
2023-11-14Auto merge of #117330 - tmiasko:custom-mir-cleanup-blocks, r=cjgillotbors-15/+73
Custom MIR: Support cleanup blocks Cleanup blocks are declared with `bb (cleanup) = { ... }`. `Call` and `Drop` terminators take an additional argument describing the unwind action, which is one of the following: * `UnwindContinue()` * `UnwindUnreachable()` * `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup` * `UnwindCleanup(block)` Also support unwind resume and unwind terminate terminators: * `UnwindResume()` * `UnwindTerminate(reason)`
2023-11-14Custom MIR: Support cleanup blocksTomasz Miąsko-15/+73
Cleanup blocks are declared with `bb (cleanup) = { ... }`. `Call` and `Drop` terminators take an additional argument describing the unwind action, which is one of the following: * `UnwindContinue()` * `UnwindUnreachable()` * `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup` * `UnwindCleanup(block)` Also support unwind resume and unwind terminate terminators: * `UnwindResume()` * `UnwindTerminate(reason)`
2023-11-14Auto merge of #116301 - mj10021:issue-115737-fix, r=cuviperbors-3/+8
fix rounding issue with exponents in fmt fixes issue #115737 , where the decimal places are rounded incorrectly when formatting scientific notation