about summary refs log tree commit diff
path: root/library/core
AgeCommit message (Collapse)AuthorLines
2023-11-29Auto merge of #118315 - WaffleLapkin:don't-repeat_byte, r=m-ou-sebors-16/+2
Use `usize::repeat_u8` instead of implementing `repeat_byte` in `memchr.rs` It's simpler that way and the tricks don't actually make a difference: https://godbolt.org/z/zrvYY1dGx
2023-11-29Rollup merge of #118231 - RalfJung:const-raw-slice-empty, r=cuviperMatthias Krüger-3/+21
also add is_empty to const raw slices We have this on mutable raw slices but not const raw slices, which makes little sense. Cc https://github.com/rust-lang/rust/issues/71146
2023-11-29Rollup merge of #118265 - RalfJung:memcpy, r=cuviperMatthias Krüger-3/+2
remove the memcpy-on-equal-ptrs assumption One of the libc we support, musl, [defines `memcpy` with `restrict` pointers](https://git.musl-libc.org/cgit/musl/tree/src/string/memcpy.c#n5). This in fact matches the definition in the C standard. Calling that `memcpy` with overlapping pointers is clearly UB, who knows what the compiler did when optimizing this `memcpy` -- it certainly assumed source and destination to be disjoint. Lucky enough, it does not seem like we actually need this assumption that `memcpy(p, p, n)` is always allowed. clang and GCC need it since they use `memcpy` to compile C assignments, but [we use memmove for similar code](https://godbolt.org/z/bcW85WYcM). There are no known cases where LLVM introduces calls to memcpy on equal pointers itself. (And if there were, that would be a soundness bug in rustc due to the musl issue mentioned above.) This does mean we must make sure to never call the LLVM `memcpy` builtin on equal ranges even though the LangRef says that is allowed. Currently that is the case so we just need to make sure it remains the case. :) Cc `@rust-lang/opsem` `@rust-lang/wg-llvm`
2023-11-29Auto merge of #114841 - bvanjoi:fix-114814, r=cuviperbors-0/+14
add track_caller for arith ops Fixes #114814 `#[track_caller]` is works, r? `@scottmcm`
2023-11-28reword panic comments and add spaces to unlikely branchesRyan Mehri-60/+64
2023-11-28Auto merge of #110353 - the8472:in-place-flatten-chunks, r=cuviperbors-40/+316
Expand in-place iteration specialization to Flatten, FlatMap and ArrayChunks This enables the following cases to collect in-place: ```rust let v = vec![[0u8; 4]; 1024] let v: Vec<_> = v.into_iter().flatten().collect(); let v: Vec<Option<NonZeroUsize>> = vec![NonZeroUsize::new(0); 1024]; let v: Vec<_> = v.into_iter().flatten().collect(); let v = vec![u8; 4096]; let v: Vec<_> = v.into_iter().array_chunks::<4>().collect(); ``` Especially the nicheful-option-flattening should be useful in real code.
2023-11-28Rollup merge of #118397 - Zalathar:nonzero, r=WaffleLapkinMatthias Krüger-2/+2
Fix comments for unsigned non-zero `checked_add`, `saturating_add` While looking at #118313, I happened to notice that two of the expanded comments appear to be slightly inaccurate. For these two methods, `other` is an ordinary unsigned integer, so it can be zero. Since the sum of non-zero and zero is always non-zero, the safety argument holds even when `other` is zero.
2023-11-28Rollup merge of #118236 - ksw2000:update_mod_comment, r=cuviperMatthias Krüger-3/+3
Update mod comment The comment of `ASCII_CASE_MASK` on line 477 is `If 6th bit is set ascii is lower case.` but the original comment of `*self ^ ((self.is_ascii_lowercase() as u8) * ASCII_CASE_MASK)` was `Toggle the fifth bit if this is a lowercase letter`
2023-11-28Rollup merge of #115331 - the8472:chars_advance, r=cuviperMatthias Krüger-0/+69
optimize str::iter::Chars::advance_by ``` OLD: str::iter::chars_advance_by_0001 0.00ns/iter +/- 0.00ns str::iter::chars_advance_by_0010 13.00ns/iter +/- 1.00ns str::iter::chars_advance_by_1000 1.20µs/iter +/- 15.00ns NEW: str::iter::chars_advance_by_0001 0.00ns/iter +/- 0.00ns str::iter::chars_advance_by_0010 6.00ns/iter +/- 0.00ns str::iter::chars_advance_by_1000 75.00ns/iter +/- 1.00ns ```
2023-11-28Fix comments for unsigned non-zero `checked_add`, `saturating_add`Zalathar-2/+2
For these two methods, `other` is an ordinary unsigned integer, so it can be zero. Since the sum of non-zero and zero is always non-zero, the safety argument holds even when `other` is zero.
2023-11-27optimize str::iter::Chars::advance_byThe 8472-0/+50
this avoids part of the char decoding work by not looking at utf8 continuation bytes
2023-11-27benchmarks for Chars::advance_byThe 8472-0/+19
2023-11-27use the usual attributes for panic_misaligned_pointer_dereferenceRalf Jung-2/+2
2023-11-27make sure panic_nounwind_fmt can still be fully inlined (e.g. for ↵Ralf Jung-1/+4
panic_immediate_abort)
2023-11-27stabilise bound_mapDylan DPC-3/+1
2023-11-27Auto merge of #118321 - WaffleLapkin:unspace-fn-pointer-fake-variadic, ↵bors-1/+1
r=notriddle rustdoc: Remove space from fake-variadic fn ptr impls before: `for fn (T₁, T₂, …, Tₙ) -> Ret` after: `for fn(T₁, T₂, …, Tₙ) -> Ret` I don't think we usually have spaces there, so it looks weird. cc `@notriddle` since you added the space in https://github.com/rust-lang/rust/pull/98180 (or rather, added the feature with a space included).
2023-11-27Simplify Default for tuplesDaniPopes-9/+6
2023-11-27Auto merge of #118313 - WaffleLapkin:fixup_comments_in_some_nonzero_ops, ↵bors-14/+44
r=thomcc Improve some comments for non-zero ops This makes them a bit more explicit/correct.
2023-11-26Add `is_aligned{,_to}` convenience methods to `NonNull`Maybe Waffle-0/+234
2023-11-26Add `align_offset` convenience method to `NonNull`Maybe Waffle-0/+60
2023-11-26Add `replace` and `swap` convenience methods to `NonNull`Maybe Waffle-0/+35
2023-11-26Add `offset_from`-ish convenience methods to `NonNull`Maybe Waffle-11/+209
2023-11-26Add offset-ish convenience methods to `NonNull`Maybe Waffle-0/+274
2023-11-26Add read/write/copy convenience methods to `NonNull`Maybe Waffle-14/+223
2023-11-26rustdoc: Remove space from fake-variadic fn ptr implsMaybe Waffle-1/+1
before: `for fn (T₁, T₂, …, Tₙ) -> Ret` after: `for fn(T₁, T₂, …, Tₙ) -> Ret`
2023-11-26Update std::simd usage and test outputsCaleb Zulawski-9/+9
2023-11-26Use inner docs to fix linksCaleb Zulawski-1/+2
2023-11-26Fix library testsCaleb Zulawski-5/+3
2023-11-26Use `usize::repeat_u8` instead of implementing `repeat_byte` in `memchr.rs`Maybe Waffle-16/+2
2023-11-26Improve some comments for non-zero opsMaybe Waffle-14/+44
2023-11-26Auto merge of #110303 - nbdd0121:master, r=Mark-Simulacrumbors-147/+154
Add `debug_assert_nounwind` and convert `assert_unsafe_precondition` `assert_unsafe_precondition` checks non-CTFE-evaluable conditions in runtime and performs no-op in compile time, while many of its current usage can be checked during const eval.
2023-11-25Remove an unneeded helper from the tuple library codeScott McMurray-13/+1
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