about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2024-05-22Auto merge of #125423 - fmease:rollup-ne4l9y4, r=fmeasebors-5/+8
Rollup of 7 pull requests Successful merges: - #125043 (reference type safety invariant docs: clarification) - #125306 (Force the inner coroutine of an async closure to `move` if the outer closure is `move` and `FnOnce`) - #125355 (Use Backtrace::force_capture instead of Backtrace::capture in rustc_log) - #125382 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 7)) - #125391 (Minor serialize/span tweaks) - #125395 (Remove unnecessary `.md` from the documentation sidebar) - #125399 (Stop using `to_hir_binop` in codegen) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-22Rollup merge of #125043 - RalfJung:ref-type-safety-invariant, r=scottmcmLeón Orell Valerian Liehr-5/+8
reference type safety invariant docs: clarification The old text could have been read as saying that you can call a function if these requirements are upheld, which is definitely not true as they are an underapproximation of the actual safety invariant. I removed the part about functions relaxing the requirements via their documentation... this seems incoherent with saying that it may actually be unsound to ever temporarily violate the requirement. Furthermore, a function *cannot* just relax this for its return value, that would in general be unsound. And the part about "unsafe code in a safe function may assume these invariants are ensured of arguments passed by the caller" also interacts with relaxing things: clearly, if the invariant has been relaxed, unsafe code cannot rely on it any more. There may be a place to give general guidance on what kinds of function contracts can exist, but the reference type is definitely not the right place to write that down. I also took a clarification from https://github.com/rust-lang/rust/pull/121965 that is orthogonal to the rest of that PR. Cc ```@joshlf``` ```@scottmcm```
2024-05-22Rollup merge of #125296 - tesuji:checkcfg-buildstd, r=Nilstrieb,michaelwoeristerLeón Orell Valerian Liehr-0/+13
Fix `unexpected_cfgs` lint on std closes #125291 r? rust-lang/compiler
2024-05-22Rollup merge of #124896 - RalfJung:miri-intrinsic-fallback, r=oli-obkLeón Orell Valerian Liehr-5/+5
miri: rename intrinsic_fallback_checks_ub to intrinsic_fallback_is_spec Checking UB is not the only concern, we also have to make sure we are not losing out on non-determinism. r? ``@oli-obk`` (not urgent, take your time)
2024-05-22Auto merge of #117329 - RalfJung:offset-by-zero, r=oli-obk,scottmcmbors-33/+34
offset: allow zero-byte offset on arbitrary pointers As per prior `@rust-lang/opsem` [discussion](https://github.com/rust-lang/opsem-team/issues/10) and [FCP](https://github.com/rust-lang/unsafe-code-guidelines/issues/472#issuecomment-1793409130): - Zero-sized reads and writes are allowed on all sufficiently aligned pointers, including the null pointer - Inbounds-offset-by-zero is allowed on all pointers, including the null pointer - `offset_from` on two pointers derived from the same allocation is always allowed when they have the same address This removes surprising UB (in particular, even C++ allows "nullptr + 0", which we currently disallow), and it brings us one step closer to an important theoretical property for our semantics ("provenance monotonicity": if operations are valid on bytes without provenance, then adding provenance can't make them invalid). The minimum LLVM we require (v17) includes https://reviews.llvm.org/D154051, so we can finally implement this. The `offset_from` change is needed to maintain the equivalence with `offset`: if `let ptr2 = ptr1.offset(N)` is well-defined, then `ptr2.offset_from(ptr1)` should be well-defined and return N. Now consider the case where N is 0 and `ptr1` dangles: we want to still allow offset_from here. I think we should change offset_from further, but that's a separate discussion. Fixes https://github.com/rust-lang/rust/issues/65108 [Tracking issue](https://github.com/rust-lang/rust/issues/117945) | [T-lang summary](https://github.com/rust-lang/rust/pull/117329#issuecomment-1951981106) Cc `@nikic`
2024-05-21Wrap Context.ext in AssertUnwindSafeJubilee Young-4/+7
2024-05-21improve comment wordingRalf Jung-14/+14
2024-05-21tidy alphabeticaLzu Tao-1/+1
2024-05-21addresss reviewsLzu Tao-1/+5
2024-05-21Update check-cfg lists for coreLzu Tao-0/+9
2024-05-21core: actually use TAIT instead of emulating itjoboet-117/+44
2024-05-21Auto merge of #125358 - matthiaskrgr:rollup-mx841tg, r=matthiaskrgrbors-0/+9
Rollup of 7 pull requests Successful merges: - #124570 (Miscellaneous cleanups) - #124772 (Refactor documentation for Apple targets) - #125011 (Add opt-for-size core lib feature flag) - #125218 (Migrate `run-make/no-intermediate-extras` to new `rmake.rs`) - #125225 (Use functions from `crt_externs.h` on iOS/tvOS/watchOS/visionOS) - #125266 (compiler: add simd_ctpop intrinsic) - #125348 (Small fixes to `std::path::absolute` docs) Failed merges: - #125296 (Fix `unexpected_cfgs` lint on std) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-21Rollup merge of #125266 - workingjubilee:stream-plastic-love, r=RalfJung,nikicMatthias Krüger-0/+7
compiler: add simd_ctpop intrinsic Fairly straightforward addition. cc `@rust-lang/opsem` new (extremely boring) intrinsic
2024-05-21Rollup merge of #125011 - diondokter:opt-for-size, r=Amanieu,kobzolMatthias Krüger-0/+2
Add opt-for-size core lib feature flag Adds a feature flag to the core library that enables the possibility to have smaller implementations for certain algorithms. So far, the core lib has traded performance for binary size. This is likely what most people want since they have big simd-capable machines. However, people on small machines, like embedded devices, don't enjoy the potential speedup of the bigger algorithms, but do have to pay for them. These microcontrollers often only have 16-1024kB of flash memory. This PR is the result of some talks with project members like `@Amanieu` at RustNL. There are some open questions of how this is eventually stabilized, but it's a similar question as with the existing `panic_immediate_abort` feature. Speaking as someone from the embedded side, we'd rather have this unstable for a while as opposed to not having it at all. In the meantime we can try to use it and also add additional PRs to the core lib that uses the feature flag in areas where we find benefit. Open questions from my side: - Is this a good feature name? - `panic_immediate_abort` is fairly verbose, so I went with something equally verbose - It's easy to refactor later - I've added the feature to `std` and `alloc` as well as they might benefit too. Do we agree? - I expect these to get less usage out of the flag since most size-constraint projects don't use these libraries often.
2024-05-20Implement BOXED_SLICE_INTO_ITERMichael Goulet-2/+3
2024-05-20Add the impls for Box<[T]>: IntoIteratorMichael Goulet-0/+3
Co-authored-by: ltdk <usr@ltdk.xyz>
2024-05-20Fix c_char on AIXTaiki Endo-1/+2
Refs: https://github.com/rust-lang/rust/issues/122985
2024-05-20Switch to primarily using `&str`Arpad Borsos-7/+6
Surprisingly, benchmarks have shown that using `&str` instead of `&[u8]` with some `unsafe` code is actually faster.
2024-05-20Introduce printable-ASCII fast-path for `impl Debug for str`Arpad Borsos-17/+42
Instead of having a single loop that works on utf-8 `char`s, this splits the implementation into a loop that quickly skips over printable ASCII, falling back to per-char iteration for other chunks.
2024-05-20Add a fast-path to `Debug` ASCII `&str`Arpad Borsos-0/+5
Instead of going through the `EscapeDebug` machinery, we can just skip over ASCII chars that don’t need any escaping.
2024-05-20Write `char::DebugEscape` sequences using `write_str`Arpad Borsos-9/+6
Instead of writing each `char` of an escape sequence one by one, this delegates to `Display`, which uses `write_str` internally in order to write the whole escape sequence at once.
2024-05-19Auto merge of #123786 - a1phyr:cursor_unsafe, r=joboetbors-6/+18
Remove bound checks from `BorrowedBuf` and `BorrowedCursor` methods
2024-05-18compiler: add simd_ctpop intrinsicJubilee Young-0/+7
2024-05-18Add `#[inline]` to float `Debug` fallback used by `cfg(no_fp_fmt_parse)`beetrees-0/+1
2024-05-17Inline Duration construction into Duration::from_{millis,micros,nanos}Noa-3/+21
2024-05-17Don't call Duration::new unnecessarily in Duration::from_secsNoa-3/+7
2024-05-17Auto merge of #125188 - tgross35:f16-f128-powi, r=Nilstriebbors-1/+52
Add `powi` fo `f16` and `f128` This will unblock adding support to compiler_builtins (<https://github.com/rust-lang/compiler-builtins/pull/614>), which will then unblock adding tests for these new functions.
2024-05-17Rollup merge of #125186 - Colepng:master, r=lqdMatthias Krüger-1/+1
Remove duplicate word from addr docs This PR simply removes a duplicate word from the addr docs for *mut T.
2024-05-17Rollup merge of #125171 - scottmcm:rename-flatten, r=jhprattMatthias Krüger-10/+10
Rename `flatten(_mut)` → `as_flattened(_mut)` As requested by libs-api in https://github.com/rust-lang/rust/issues/95629#issuecomment-2113081194 (This is just the rename, not the stabilization, so can land without waiting on the FCP in that other issue.)
2024-05-16Add `powi` to `f16` and `f128`Trevor Gross-0/+12
This will unblock adding support to compiler_builtins (<https://github.com/rust-lang/compiler-builtins/pull/614>), which will then unblock adding tests for these new functions.
2024-05-16Add doctests for f16 and f128 library functions where possibleTrevor Gross-1/+40
2024-05-16Remove duplicate word from addr docsCole Kauder-McMurrich-1/+1
2024-05-16Auto merge of #124728 - beetrees:from-f16-for-f64, r=BurntSushibors-2/+3
Re-add `From<f16> for f64` This impl was originally added in #122470 before being removed in #123830 due to #123831. However, the issue only affects `f32` (which currently only has one `From<{float}>` impl, `From<f32>`) as `f64` already has two `From<{float}>` impls (`From<f32>` and `From<f64>`) and is also the float literal fallback type anyway. Therefore it is safe to re-add `From<f16> for f64`. This PR also updates the FIXME link to point to the open issue #123831 rather than the closed issue #123824. Tracking issue: #116909 `@rustbot` label +F-f16_and_f128 +T-libs-api
2024-05-16Fix linkchecker doc errorsLukas Bergdoll-9/+9
Also includes small doc fixes.
2024-05-16Turn bare links into automatic linksLukas Bergdoll-4/+4
2024-05-16Fix tidy errorsLukas Bergdoll-21/+13
2024-05-16Replace sort implementationsLukas Bergdoll-1568/+2504
- `slice::sort` -> driftsort https://github.com/Voultapher/sort-research-rs/blob/main/writeup/driftsort_introduction/text.md - `slice::sort_unstable` -> ipnsort https://github.com/Voultapher/sort-research-rs/blob/main/writeup/ipnsort_introduction/text.md Replaces the sort implementations with tailor made ones that strike a balance of run-time, compile-time and binary-size, yielding run-time and compile-time improvements. Regressing binary-size for `slice::sort` while improving it for `slice::sort_unstable`. All while upholding the existing soft and hard safety guarantees, and even extending the soft guarantees, detecting strict weak ordering violations with a high chance and reporting it to users via a panic. In addition the implementation of `select_nth_unstable` is also adapted as it uses `slice::sort_unstable` internals.
2024-05-16Auto merge of #124959 - prorealize:update-result-documentation, r=joboetbors-4/+8
Refactor examples and enhance documentation in result.rs - Replaced `map` with `map_err` in the error handling example for correctness - Reordered example code to improve readability and logical flow - Added assertions to examples to demonstrate expected outcomes
2024-05-15Rename `flatten(_mut)` → `as_flattened(_mut)`Scott McMurray-10/+10
2024-05-15Allow for_loops_over_fallibles in test that tests &mut Result as IntoIterator.Zachary S-0/+1
2024-05-15Rollup merge of #125038 - ivan-shrimp:checked_sub, r=joboetLeón Orell Valerian Liehr-3/+3
Invert comparison in `uN::checked_sub` After #124114, LLVM no longer combines the comparison and subtraction in `uN::checked_sub` when either operand is a constant (demo: https://rust.godbolt.org/z/MaeoYbsP1). The difference is more pronounced when the expression is slightly more complex (https://rust.godbolt.org/z/4rPavsYdc). This is due to the use of `>=` here: https://github.com/rust-lang/rust/blob/ee97564e3a9f9ac8c65103abb37c6aa48d95bfa2/library/core/src/num/uint_macros.rs#L581-L593 For constant `C`, LLVM eagerly converts `a >= C` into `a > C - 1`, but the backend can only combine `a < C` with `a - C`, not `C - 1 < a` and `a - C`: https://github.com/llvm/llvm-project/blob/e586556e375fc5c4f7e76b5c299cb981f2016108/llvm/lib/CodeGen/CodeGenPrepare.cpp#L1697-L1742 This PR[^1] simply inverts the `>=` into `<` to restore the LLVM magic, and somewhat align this with the implementation of `uN::overflowing_sub` from #103299. When the result is stored as an `Option` (rather than being branched/cmoved on), the discriminant is `self >= rhs`. This PR doesn't affect the codegen (and relevant tests) of that since LLVM will negate `self < rhs` to `self >= rhs` when necessary. [^1]: Note to `self`: My very first contribution to publicly-used code. Hopefully like what I should learn to always be, tiny and humble.
2024-05-15Rollup merge of #124307 - reitermarkus:escape-debug-size-hint-inline, r=joboetLeón Orell Valerian Liehr-79/+126
Optimize character escaping. Allow optimization of panicking branch in `EscapeDebug`, see https://github.com/rust-lang/rust/pull/121805. r? `@joboet`
2024-05-15Update library/core/src/result.rsRenato A-1/+1
Co-authored-by: joboet <jonasboettiger@icloud.com>
2024-05-15Divide float nanoseconds instead of secondsArtyom Pavlov-2/+6
2024-05-13Rollup merge of #116675 - joshlf:patch-10, r=scottmcmJacob Pratt-5/+33
[ptr] Document maximum allocation size Partially addresses https://github.com/rust-lang/unsafe-code-guidelines/issues/465
2024-05-13[ptr] Document maximum allocation sizeJoshua Liebow-Feeser-5/+33
2024-05-13Don't use `T` with both Result and Option, improve explanation.Lokathor-67/+70
2024-05-13Add `size_of`, `size_of_val`, `align_of`, and `align_of_val` to the preludeJosh Triplett-7/+5
Many, many projects use `size_of` to get the size of a type. However, it's also often equally easy to hardcode a size (e.g. `8` instead of `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps ensure that people use it and make code more self-documenting. The name `size_of` is unambiguous: the name alone, without any prefix or path, is self-explanatory and unmistakeable for any other functionality. Adding it to the prelude cannot produce any name conflicts, as any local definition will silently shadow the one from the prelude. Thus, we don't need to wait for a new edition prelude to add it. Add `size_of_val`, `align_of`, and `align_of_val` as well, with similar justification: widely useful, self-explanatory, unmistakeable for anything else, won't produce conflicts.
2024-05-13offset, offset_from: allow zero-byte offset on arbitrary pointersRalf Jung-32/+33
2024-05-12reference type safety invariant docs: clarificationRalf Jung-5/+8